diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f388791 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +* text=auto + +*.am text eol=lf +*.in text eol=lf +*.sh text eol=lf +*.ac text eol=lf +*.txt text eol=crlf +*.vcxproj text eol=crlf +*.sln text eol=crlf + +*.cu diff=cpp diff --git a/.gitignore b/.gitignore index fbdf2c8..7ccbb4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,81 @@ -cpuminer-config.h \ No newline at end of file +cpuminer-config.h +*.m4 +*.in +compat/*.in +compat/jansson/*.in +configure +#ignore thumbnails created by windows +Thumbs.db +#Ignore files build by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +*.sdf +*.opensdf +[Dd]ebug*/ +*.sbr +obj/ +[Rr]elease*/ +*.db +*.opendb +.deps/ccminer-cpu-miner.Po +.deps/ccminer-cryptonight.Po +.deps/ccminer-sha2.Po +.deps/ccminer-util.Po +ccminer-cpu-miner.o +ccminer-sha2.o +ccminer-util.o +compat/jansson/.deps/dump.Po +compat/jansson/.deps/error.Po +compat/jansson/.deps/hashtable.Po +compat/jansson/.deps/load.Po +compat/jansson/.deps/memory.Po +compat/jansson/.deps/pack_unpack.Po +compat/jansson/.deps/strbuffer.Po +compat/jansson/.deps/utf.Po +compat/jansson/.deps/value.Po +compat/jansson/dump.o +compat/jansson/error.o +compat/jansson/hashtable.o +compat/jansson/jansson_private_config.h +compat/jansson/libjansson.a +compat/jansson/load.o +compat/jansson/Makefile +compat/jansson/memory.o +compat/jansson/pack_unpack.o +compat/jansson/strbuffer.o +compat/jansson/utf.o +compat/jansson/value.o +compat/Makefile +compat/Makefile.in +config.status +cpuminer-config.h +crypto/.deps/ccminer-aesb.Po +crypto/.deps/ccminer-c_blake256.Po +crypto/.deps/ccminer-c_groestl.Po +crypto/.deps/ccminer-c_jh.Po +crypto/.deps/ccminer-c_keccak.Po +crypto/.deps/ccminer-c_skein.Po +crypto/.deps/ccminer-oaes_lib.Po +cryptonight/.deps/.dirstamp +cryptonight/.dirstamp +Makefile +missing +stamp-h1 +compat/Makefile.in +cpuminer-config.h +/.vs diff --git a/INSTALL b/INSTALL index 2ee1151..fda1100 100644 --- a/INSTALL +++ b/INSTALL @@ -1,9 +1,21 @@ - -It is advised to run ./autogen.sh before./configure (autoconf and automake +It is advised to run ./autogen.sh before ./configure (autoconf and automake need to be installed on your system for autogen.sh to work) ./configure has an option named --with-cuda that allows you to specify where your CUDA 5.5 toolkit is installed (usually /usr/local/cuda-5.5, -but some distros may have a different default location) +but some distros may have a different default location). + +On Ubuntu Xenial (16 LTS), here's the rough installation process using cuda 9.0: + +# wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb +# sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb +# sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub +# sudo apt-get update +# sudo apt install build-essential automake pkg-config libssl-dev libcurl4-openssl-dev cuda-9-0 nvidia-opencl-dev nvidia-cuda-toolkit + +For cuda-9-1, you also need the cuda-nvcc-9-1 package. -See README.txt +# ./autogen.sh +# ./configure --with-cuda=/usr/local/cuda +# make clean +# make diff --git a/Makefile.am b/Makefile.am index d36dc34..e6d462e 100755 --- a/Makefile.am +++ b/Makefile.am @@ -17,26 +17,24 @@ bin_PROGRAMS = ccminer ccminer_SOURCES = elist.h miner.h compat.h \ compat/inttypes.h compat/stdbool.h compat/unistd.h \ compat/sys/time.h compat/getopt/getopt.h \ - cpu-miner.c util.c sha2.c \ + cpu-miner.cpp util.cpp sha2.cpp \ cryptonight/cryptonight.cu cryptonight/cuda_cryptonight_core.cu cryptonight/cuda_cryptonight_extra.cu \ - cryptonight.c \ - crypto/oaes_lib.c \ - crypto/c_keccak.c \ - crypto/c_groestl.c \ - crypto/c_blake256.c \ - crypto/c_jh.c \ - crypto/c_skein.c \ - crypto/aesb.c + cryptonight-cpu.cpp \ + crypto/oaes_lib.cpp \ + crypto/c_keccak.cpp \ + crypto/c_groestl.cpp \ + crypto/c_blake256.cpp \ + crypto/c_jh.cpp \ + crypto/c_skein.cpp \ + crypto/aesb.cpp ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@ ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ -ccminer_CPPFLAGS = -msse2 @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME +ccminer_CPPFLAGS = $(CUDA_CFLAGS) -msse2 @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME -#NVCC_GENCODE = -gencode=arch=compute_35,code=\"sm_35,compute_35\" -#NVCC_GENCODE = -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" -NVCC_GENCODE = -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" +NVCC_GENCODE = -D_FORCE_INLINES $(CUDA_CFLAGS) -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_37,code=sm_37 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_75,code=sm_75 # we're now targeting all major compute architectures within one binary. .cu.o: - $(NVCC) @CFLAGS@ -I . -Xptxas "-abi=no -v" $(NVCC_GENCODE) --maxrregcount=80 --ptxas-options=-v $(JANSSON_INCLUDES) -o $@ -c $< + $(NVCC) @CFLAGS@ -I . $(NVCC_GENCODE) --maxrregcount=128 $(JANSSON_INCLUDES) -o $@ -c $< diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 9da7878..0000000 --- a/Makefile.in +++ /dev/null @@ -1,1213 +0,0 @@ -# Makefile.in generated by automake 1.11.3 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software -# Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -target_triplet = @target@ -bin_PROGRAMS = ccminer$(EXEEXT) -subdir = . -DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in $(srcdir)/cpuminer-config.h.in \ - $(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \ - compile config.guess config.sub depcomp install-sh missing -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ - configure.lineno config.status.lineno -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = cpuminer-config.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -am__installdirs = "$(DESTDIR)$(bindir)" -PROGRAMS = $(bin_PROGRAMS) -am__dirstamp = $(am__leading_dot)dirstamp -am_ccminer_OBJECTS = ccminer-cpu-miner.$(OBJEXT) \ - ccminer-util.$(OBJEXT) ccminer-bmw.$(OBJEXT) \ - ccminer-blake.$(OBJEXT) ccminer-groestl.$(OBJEXT) \ - ccminer-jh.$(OBJEXT) ccminer-keccak.$(OBJEXT) \ - ccminer-skein.$(OBJEXT) ccminer-hefty1.$(OBJEXT) \ - ccminer-scrypt.$(OBJEXT) ccminer-sha2.$(OBJEXT) \ - heavy/heavy.$(OBJEXT) heavy/cuda_blake512.$(OBJEXT) \ - heavy/cuda_combine.$(OBJEXT) heavy/cuda_groestl512.$(OBJEXT) \ - heavy/cuda_hefty1.$(OBJEXT) heavy/cuda_keccak512.$(OBJEXT) \ - heavy/cuda_sha256.$(OBJEXT) ccminer-fuguecoin.$(OBJEXT) \ - cuda_fugue256.$(OBJEXT) ccminer-fugue.$(OBJEXT) \ - ccminer-groestlcoin.$(OBJEXT) cuda_groestlcoin.$(OBJEXT) \ - JHA/jackpotcoin.$(OBJEXT) JHA/cuda_jha_keccak512.$(OBJEXT) \ - JHA/cuda_jha_compactionTest.$(OBJEXT) \ - quark/cuda_quark_checkhash.$(OBJEXT) \ - quark/cuda_jh512.$(OBJEXT) quark/cuda_quark_blake512.$(OBJEXT) \ - quark/cuda_quark_groestl512.$(OBJEXT) \ - quark/cuda_skein512.$(OBJEXT) quark/cuda_bmw512.$(OBJEXT) \ - quark/cuda_quark_keccak512.$(OBJEXT) quark/quarkcoin.$(OBJEXT) \ - quark/animecoin.$(OBJEXT) \ - quark/cuda_quark_compactionTest.$(OBJEXT) \ - ccminer-myriadgroestl.$(OBJEXT) cuda_myriadgroestl.$(OBJEXT) -ccminer_OBJECTS = $(am_ccminer_OBJECTS) -ccminer_DEPENDENCIES = -ccminer_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(ccminer_LDFLAGS) \ - $(LDFLAGS) -o $@ -DEFAULT_INCLUDES = -I.@am__isrc@ -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ - -o $@ -SOURCES = $(ccminer_SOURCES) -DIST_SOURCES = $(ccminer_SOURCES) -RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ - html-recursive info-recursive install-data-recursive \ - install-dvi-recursive install-exec-recursive \ - install-html-recursive install-info-recursive \ - install-pdf-recursive install-ps-recursive install-recursive \ - installcheck-recursive installdirs-recursive pdf-recursive \ - ps-recursive uninstall-recursive -RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ - distclean-recursive maintainer-clean-recursive -AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ - $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ - distdir dist dist-all distcheck -ETAGS = etags -CTAGS = ctags -DIST_SUBDIRS = $(SUBDIRS) -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) -am__remove_distdir = \ - if test -d "$(distdir)"; then \ - find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ - && rm -rf "$(distdir)" \ - || { sleep 5 && rm -rf "$(distdir)"; }; \ - else :; fi -am__relativize = \ - dir0=`pwd`; \ - sed_first='s,^\([^/]*\)/.*$$,\1,'; \ - sed_rest='s,^[^/]*/*,,'; \ - sed_last='s,^.*/\([^/]*\)$$,\1,'; \ - sed_butlast='s,/*[^/]*$$,,'; \ - while test -n "$$dir1"; do \ - first=`echo "$$dir1" | sed -e "$$sed_first"`; \ - if test "$$first" != "."; then \ - if test "$$first" = ".."; then \ - dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ - dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ - else \ - first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ - if test "$$first2" = "$$first"; then \ - dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ - else \ - dir2="../$$dir2"; \ - fi; \ - dir0="$$dir0"/"$$first"; \ - fi; \ - fi; \ - dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ - done; \ - reldir="$$dir2" -DIST_ARCHIVES = $(distdir).tar.gz -GZIP_ENV = --best -distuninstallcheck_listfiles = find . -type f -print -am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ - | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' -distcleancheck_listfiles = find . -type f -print -ACLOCAL = @ACLOCAL@ -ALLOCA = @ALLOCA@ -AMTAR = @AMTAR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCAS = @CCAS@ -CCASDEPMODE = @CCASDEPMODE@ -CCASFLAGS = @CCASFLAGS@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CUDA_CFLAGS = @CUDA_CFLAGS@ -CUDA_LDFLAGS = @CUDA_LDFLAGS@ -CUDA_LIBS = @CUDA_LIBS@ -CXX = @CXX@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -GREP = @GREP@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -JANSSON_LIBS = @JANSSON_LIBS@ -LDFLAGS = @LDFLAGS@ -LIBCURL = @LIBCURL@ -LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LTLIBOBJS = @LTLIBOBJS@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MKDIR_P = @MKDIR_P@ -NVCC = @NVCC@ -OBJEXT = @OBJEXT@ -OPENMP_CFLAGS = @OPENMP_CFLAGS@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_URL = @PACKAGE_URL@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -PTHREAD_FLAGS = @PTHREAD_FLAGS@ -PTHREAD_LIBS = @PTHREAD_LIBS@ -RANLIB = @RANLIB@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -WS2_LIBS = @WS2_LIBS@ -_libcurl_config = @_libcurl_config@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target = @target@ -target_alias = @target_alias@ -target_cpu = @target_cpu@ -target_os = @target_os@ -target_vendor = @target_vendor@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -@WANT_JANSSON_FALSE@JANSSON_INCLUDES = -@WANT_JANSSON_TRUE@JANSSON_INCLUDES = -I$(top_srcdir)/compat/jansson -EXTRA_DIST = autogen.sh README.txt LICENSE.txt \ - cudaminer.sln cudaminer.vcxproj cudaminer.vcxproj.filters \ - compat/gettimeofday.c compat/getopt/getopt_long.c cpuminer-config.h.in - -SUBDIRS = compat -ccminer_SOURCES = elist.h miner.h compat.h \ - compat/inttypes.h compat/stdbool.h compat/unistd.h \ - compat/sys/time.h compat/getopt/getopt.h \ - cpu-miner.c util.c sph/bmw.c sph/blake.c sph/groestl.c sph/jh.c sph/keccak.c sph/skein.c hefty1.c scrypt.c sha2.c \ - sph/bmw.h sph/sph_blake.h sph/sph_groestl.h sph/sph_jh.h sph/sph_keccak.h sph/sph_skein.h sph/sph_types.h \ - heavy/heavy.cu \ - heavy/cuda_blake512.cu heavy/cuda_blake512.h \ - heavy/cuda_combine.cu heavy/cuda_combine.h \ - heavy/cuda_groestl512.cu heavy/cuda_groestl512.h \ - heavy/cuda_hefty1.cu heavy/cuda_hefty1.h \ - heavy/cuda_keccak512.cu heavy/cuda_keccak512.h \ - heavy/cuda_sha256.cu heavy/cuda_sha256.h \ - fuguecoin.cpp cuda_fugue256.cu sph/fugue.c sph/sph_fugue.h uint256.h \ - groestlcoin.cpp cuda_groestlcoin.cu cuda_groestlcoin.h \ - JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \ - JHA/cuda_jha_compactionTest.cu quark/cuda_quark_checkhash.cu \ - quark/cuda_jh512.cu quark/cuda_quark_blake512.cu quark/cuda_quark_groestl512.cu quark/cuda_skein512.cu \ - quark/cuda_bmw512.cu quark/cuda_quark_keccak512.cu quark/quarkcoin.cu quark/animecoin.cu \ - quark/cuda_quark_compactionTest.cu \ - myriadgroestl.cpp cuda_myriadgroestl.cu - -ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@ -ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ -ccminer_CPPFLAGS = -msse2 @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME -all: cpuminer-config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -.SUFFIXES: -.SUFFIXES: .c .cpp .cu .o .obj -am--refresh: Makefile - @: -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ - $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - echo ' $(SHELL) ./config.status'; \ - $(SHELL) ./config.status;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck - -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - $(am__cd) $(srcdir) && $(AUTOCONF) -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) - $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) -$(am__aclocal_m4_deps): - -cpuminer-config.h: stamp-h1 - @if test ! -f $@; then rm -f stamp-h1; else :; fi - @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi - -stamp-h1: $(srcdir)/cpuminer-config.h.in $(top_builddir)/config.status - @rm -f stamp-h1 - cd $(top_builddir) && $(SHELL) ./config.status cpuminer-config.h -$(srcdir)/cpuminer-config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) - rm -f stamp-h1 - touch $@ - -distclean-hdr: - -rm -f cpuminer-config.h stamp-h1 -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" - @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ - for p in $$list; do echo "$$p $$p"; done | \ - sed 's/$(EXEEXT)$$//' | \ - while read p p1; do if test -f $$p; \ - then echo "$$p"; echo "$$p"; else :; fi; \ - done | \ - sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ - -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ - sed 'N;N;N;s,\n, ,g' | \ - $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ - { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ - if ($$2 == $$4) files[d] = files[d] " " $$1; \ - else { print "f", $$3 "/" $$4, $$1; } } \ - END { for (d in files) print "f", d, files[d] }' | \ - while read type dir files; do \ - if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ - test -z "$$files" || { \ - echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ - $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ - } \ - ; done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ - files=`for p in $$list; do echo "$$p"; done | \ - sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ - -e 's/$$/$(EXEEXT)/' `; \ - test -n "$$list" || exit 0; \ - echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ - cd "$(DESTDIR)$(bindir)" && rm -f $$files - -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -heavy/$(am__dirstamp): - @$(MKDIR_P) heavy - @: > heavy/$(am__dirstamp) -heavy/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) heavy/$(DEPDIR) - @: > heavy/$(DEPDIR)/$(am__dirstamp) -heavy/heavy.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -heavy/cuda_blake512.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -heavy/cuda_combine.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -heavy/cuda_groestl512.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -heavy/cuda_hefty1.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -heavy/cuda_keccak512.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -heavy/cuda_sha256.$(OBJEXT): heavy/$(am__dirstamp) \ - heavy/$(DEPDIR)/$(am__dirstamp) -JHA/$(am__dirstamp): - @$(MKDIR_P) JHA - @: > JHA/$(am__dirstamp) -JHA/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) JHA/$(DEPDIR) - @: > JHA/$(DEPDIR)/$(am__dirstamp) -JHA/jackpotcoin.$(OBJEXT): JHA/$(am__dirstamp) \ - JHA/$(DEPDIR)/$(am__dirstamp) -JHA/cuda_jha_keccak512.$(OBJEXT): JHA/$(am__dirstamp) \ - JHA/$(DEPDIR)/$(am__dirstamp) -JHA/cuda_jha_compactionTest.$(OBJEXT): JHA/$(am__dirstamp) \ - JHA/$(DEPDIR)/$(am__dirstamp) -quark/$(am__dirstamp): - @$(MKDIR_P) quark - @: > quark/$(am__dirstamp) -quark/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) quark/$(DEPDIR) - @: > quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_quark_checkhash.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_jh512.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_quark_blake512.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_quark_groestl512.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_skein512.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_bmw512.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_quark_keccak512.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/quarkcoin.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/animecoin.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -quark/cuda_quark_compactionTest.$(OBJEXT): quark/$(am__dirstamp) \ - quark/$(DEPDIR)/$(am__dirstamp) -ccminer$(EXEEXT): $(ccminer_OBJECTS) $(ccminer_DEPENDENCIES) $(EXTRA_ccminer_DEPENDENCIES) - @rm -f ccminer$(EXEEXT) - $(ccminer_LINK) $(ccminer_OBJECTS) $(ccminer_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -rm -f JHA/cuda_jha_compactionTest.$(OBJEXT) - -rm -f JHA/cuda_jha_keccak512.$(OBJEXT) - -rm -f JHA/jackpotcoin.$(OBJEXT) - -rm -f heavy/cuda_blake512.$(OBJEXT) - -rm -f heavy/cuda_combine.$(OBJEXT) - -rm -f heavy/cuda_groestl512.$(OBJEXT) - -rm -f heavy/cuda_hefty1.$(OBJEXT) - -rm -f heavy/cuda_keccak512.$(OBJEXT) - -rm -f heavy/cuda_sha256.$(OBJEXT) - -rm -f heavy/heavy.$(OBJEXT) - -rm -f quark/animecoin.$(OBJEXT) - -rm -f quark/cuda_bmw512.$(OBJEXT) - -rm -f quark/cuda_jh512.$(OBJEXT) - -rm -f quark/cuda_quark_blake512.$(OBJEXT) - -rm -f quark/cuda_quark_checkhash.$(OBJEXT) - -rm -f quark/cuda_quark_compactionTest.$(OBJEXT) - -rm -f quark/cuda_quark_groestl512.$(OBJEXT) - -rm -f quark/cuda_quark_keccak512.$(OBJEXT) - -rm -f quark/cuda_skein512.$(OBJEXT) - -rm -f quark/quarkcoin.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-blake.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-bmw.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-cpu-miner.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-fugue.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-fuguecoin.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-groestl.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-groestlcoin.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-hefty1.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-jh.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-keccak.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-myriadgroestl.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-scrypt.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-sha2.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-skein.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ccminer-util.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c $< - -.c.obj: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` - -ccminer-cpu-miner.o: cpu-miner.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-cpu-miner.o -MD -MP -MF $(DEPDIR)/ccminer-cpu-miner.Tpo -c -o ccminer-cpu-miner.o `test -f 'cpu-miner.c' || echo '$(srcdir)/'`cpu-miner.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-cpu-miner.Tpo $(DEPDIR)/ccminer-cpu-miner.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cpu-miner.c' object='ccminer-cpu-miner.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-cpu-miner.o `test -f 'cpu-miner.c' || echo '$(srcdir)/'`cpu-miner.c - -ccminer-cpu-miner.obj: cpu-miner.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-cpu-miner.obj -MD -MP -MF $(DEPDIR)/ccminer-cpu-miner.Tpo -c -o ccminer-cpu-miner.obj `if test -f 'cpu-miner.c'; then $(CYGPATH_W) 'cpu-miner.c'; else $(CYGPATH_W) '$(srcdir)/cpu-miner.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-cpu-miner.Tpo $(DEPDIR)/ccminer-cpu-miner.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cpu-miner.c' object='ccminer-cpu-miner.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-cpu-miner.obj `if test -f 'cpu-miner.c'; then $(CYGPATH_W) 'cpu-miner.c'; else $(CYGPATH_W) '$(srcdir)/cpu-miner.c'; fi` - -ccminer-util.o: util.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-util.o -MD -MP -MF $(DEPDIR)/ccminer-util.Tpo -c -o ccminer-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-util.Tpo $(DEPDIR)/ccminer-util.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='util.c' object='ccminer-util.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c - -ccminer-util.obj: util.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-util.obj -MD -MP -MF $(DEPDIR)/ccminer-util.Tpo -c -o ccminer-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-util.Tpo $(DEPDIR)/ccminer-util.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='util.c' object='ccminer-util.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi` - -ccminer-bmw.o: sph/bmw.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-bmw.o -MD -MP -MF $(DEPDIR)/ccminer-bmw.Tpo -c -o ccminer-bmw.o `test -f 'sph/bmw.c' || echo '$(srcdir)/'`sph/bmw.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-bmw.Tpo $(DEPDIR)/ccminer-bmw.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/bmw.c' object='ccminer-bmw.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-bmw.o `test -f 'sph/bmw.c' || echo '$(srcdir)/'`sph/bmw.c - -ccminer-bmw.obj: sph/bmw.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-bmw.obj -MD -MP -MF $(DEPDIR)/ccminer-bmw.Tpo -c -o ccminer-bmw.obj `if test -f 'sph/bmw.c'; then $(CYGPATH_W) 'sph/bmw.c'; else $(CYGPATH_W) '$(srcdir)/sph/bmw.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-bmw.Tpo $(DEPDIR)/ccminer-bmw.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/bmw.c' object='ccminer-bmw.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-bmw.obj `if test -f 'sph/bmw.c'; then $(CYGPATH_W) 'sph/bmw.c'; else $(CYGPATH_W) '$(srcdir)/sph/bmw.c'; fi` - -ccminer-blake.o: sph/blake.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-blake.o -MD -MP -MF $(DEPDIR)/ccminer-blake.Tpo -c -o ccminer-blake.o `test -f 'sph/blake.c' || echo '$(srcdir)/'`sph/blake.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-blake.Tpo $(DEPDIR)/ccminer-blake.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/blake.c' object='ccminer-blake.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-blake.o `test -f 'sph/blake.c' || echo '$(srcdir)/'`sph/blake.c - -ccminer-blake.obj: sph/blake.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-blake.obj -MD -MP -MF $(DEPDIR)/ccminer-blake.Tpo -c -o ccminer-blake.obj `if test -f 'sph/blake.c'; then $(CYGPATH_W) 'sph/blake.c'; else $(CYGPATH_W) '$(srcdir)/sph/blake.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-blake.Tpo $(DEPDIR)/ccminer-blake.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/blake.c' object='ccminer-blake.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-blake.obj `if test -f 'sph/blake.c'; then $(CYGPATH_W) 'sph/blake.c'; else $(CYGPATH_W) '$(srcdir)/sph/blake.c'; fi` - -ccminer-groestl.o: sph/groestl.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-groestl.o -MD -MP -MF $(DEPDIR)/ccminer-groestl.Tpo -c -o ccminer-groestl.o `test -f 'sph/groestl.c' || echo '$(srcdir)/'`sph/groestl.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-groestl.Tpo $(DEPDIR)/ccminer-groestl.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/groestl.c' object='ccminer-groestl.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-groestl.o `test -f 'sph/groestl.c' || echo '$(srcdir)/'`sph/groestl.c - -ccminer-groestl.obj: sph/groestl.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-groestl.obj -MD -MP -MF $(DEPDIR)/ccminer-groestl.Tpo -c -o ccminer-groestl.obj `if test -f 'sph/groestl.c'; then $(CYGPATH_W) 'sph/groestl.c'; else $(CYGPATH_W) '$(srcdir)/sph/groestl.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-groestl.Tpo $(DEPDIR)/ccminer-groestl.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/groestl.c' object='ccminer-groestl.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-groestl.obj `if test -f 'sph/groestl.c'; then $(CYGPATH_W) 'sph/groestl.c'; else $(CYGPATH_W) '$(srcdir)/sph/groestl.c'; fi` - -ccminer-jh.o: sph/jh.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-jh.o -MD -MP -MF $(DEPDIR)/ccminer-jh.Tpo -c -o ccminer-jh.o `test -f 'sph/jh.c' || echo '$(srcdir)/'`sph/jh.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-jh.Tpo $(DEPDIR)/ccminer-jh.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/jh.c' object='ccminer-jh.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-jh.o `test -f 'sph/jh.c' || echo '$(srcdir)/'`sph/jh.c - -ccminer-jh.obj: sph/jh.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-jh.obj -MD -MP -MF $(DEPDIR)/ccminer-jh.Tpo -c -o ccminer-jh.obj `if test -f 'sph/jh.c'; then $(CYGPATH_W) 'sph/jh.c'; else $(CYGPATH_W) '$(srcdir)/sph/jh.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-jh.Tpo $(DEPDIR)/ccminer-jh.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/jh.c' object='ccminer-jh.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-jh.obj `if test -f 'sph/jh.c'; then $(CYGPATH_W) 'sph/jh.c'; else $(CYGPATH_W) '$(srcdir)/sph/jh.c'; fi` - -ccminer-keccak.o: sph/keccak.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-keccak.o -MD -MP -MF $(DEPDIR)/ccminer-keccak.Tpo -c -o ccminer-keccak.o `test -f 'sph/keccak.c' || echo '$(srcdir)/'`sph/keccak.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-keccak.Tpo $(DEPDIR)/ccminer-keccak.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/keccak.c' object='ccminer-keccak.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-keccak.o `test -f 'sph/keccak.c' || echo '$(srcdir)/'`sph/keccak.c - -ccminer-keccak.obj: sph/keccak.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-keccak.obj -MD -MP -MF $(DEPDIR)/ccminer-keccak.Tpo -c -o ccminer-keccak.obj `if test -f 'sph/keccak.c'; then $(CYGPATH_W) 'sph/keccak.c'; else $(CYGPATH_W) '$(srcdir)/sph/keccak.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-keccak.Tpo $(DEPDIR)/ccminer-keccak.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/keccak.c' object='ccminer-keccak.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-keccak.obj `if test -f 'sph/keccak.c'; then $(CYGPATH_W) 'sph/keccak.c'; else $(CYGPATH_W) '$(srcdir)/sph/keccak.c'; fi` - -ccminer-skein.o: sph/skein.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-skein.o -MD -MP -MF $(DEPDIR)/ccminer-skein.Tpo -c -o ccminer-skein.o `test -f 'sph/skein.c' || echo '$(srcdir)/'`sph/skein.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-skein.Tpo $(DEPDIR)/ccminer-skein.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/skein.c' object='ccminer-skein.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-skein.o `test -f 'sph/skein.c' || echo '$(srcdir)/'`sph/skein.c - -ccminer-skein.obj: sph/skein.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-skein.obj -MD -MP -MF $(DEPDIR)/ccminer-skein.Tpo -c -o ccminer-skein.obj `if test -f 'sph/skein.c'; then $(CYGPATH_W) 'sph/skein.c'; else $(CYGPATH_W) '$(srcdir)/sph/skein.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-skein.Tpo $(DEPDIR)/ccminer-skein.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/skein.c' object='ccminer-skein.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-skein.obj `if test -f 'sph/skein.c'; then $(CYGPATH_W) 'sph/skein.c'; else $(CYGPATH_W) '$(srcdir)/sph/skein.c'; fi` - -ccminer-hefty1.o: hefty1.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-hefty1.o -MD -MP -MF $(DEPDIR)/ccminer-hefty1.Tpo -c -o ccminer-hefty1.o `test -f 'hefty1.c' || echo '$(srcdir)/'`hefty1.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-hefty1.Tpo $(DEPDIR)/ccminer-hefty1.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='hefty1.c' object='ccminer-hefty1.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-hefty1.o `test -f 'hefty1.c' || echo '$(srcdir)/'`hefty1.c - -ccminer-hefty1.obj: hefty1.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-hefty1.obj -MD -MP -MF $(DEPDIR)/ccminer-hefty1.Tpo -c -o ccminer-hefty1.obj `if test -f 'hefty1.c'; then $(CYGPATH_W) 'hefty1.c'; else $(CYGPATH_W) '$(srcdir)/hefty1.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-hefty1.Tpo $(DEPDIR)/ccminer-hefty1.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='hefty1.c' object='ccminer-hefty1.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-hefty1.obj `if test -f 'hefty1.c'; then $(CYGPATH_W) 'hefty1.c'; else $(CYGPATH_W) '$(srcdir)/hefty1.c'; fi` - -ccminer-scrypt.o: scrypt.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-scrypt.o -MD -MP -MF $(DEPDIR)/ccminer-scrypt.Tpo -c -o ccminer-scrypt.o `test -f 'scrypt.c' || echo '$(srcdir)/'`scrypt.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-scrypt.Tpo $(DEPDIR)/ccminer-scrypt.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='scrypt.c' object='ccminer-scrypt.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-scrypt.o `test -f 'scrypt.c' || echo '$(srcdir)/'`scrypt.c - -ccminer-scrypt.obj: scrypt.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-scrypt.obj -MD -MP -MF $(DEPDIR)/ccminer-scrypt.Tpo -c -o ccminer-scrypt.obj `if test -f 'scrypt.c'; then $(CYGPATH_W) 'scrypt.c'; else $(CYGPATH_W) '$(srcdir)/scrypt.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-scrypt.Tpo $(DEPDIR)/ccminer-scrypt.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='scrypt.c' object='ccminer-scrypt.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-scrypt.obj `if test -f 'scrypt.c'; then $(CYGPATH_W) 'scrypt.c'; else $(CYGPATH_W) '$(srcdir)/scrypt.c'; fi` - -ccminer-sha2.o: sha2.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-sha2.o -MD -MP -MF $(DEPDIR)/ccminer-sha2.Tpo -c -o ccminer-sha2.o `test -f 'sha2.c' || echo '$(srcdir)/'`sha2.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-sha2.Tpo $(DEPDIR)/ccminer-sha2.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sha2.c' object='ccminer-sha2.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-sha2.o `test -f 'sha2.c' || echo '$(srcdir)/'`sha2.c - -ccminer-sha2.obj: sha2.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-sha2.obj -MD -MP -MF $(DEPDIR)/ccminer-sha2.Tpo -c -o ccminer-sha2.obj `if test -f 'sha2.c'; then $(CYGPATH_W) 'sha2.c'; else $(CYGPATH_W) '$(srcdir)/sha2.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-sha2.Tpo $(DEPDIR)/ccminer-sha2.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sha2.c' object='ccminer-sha2.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-sha2.obj `if test -f 'sha2.c'; then $(CYGPATH_W) 'sha2.c'; else $(CYGPATH_W) '$(srcdir)/sha2.c'; fi` - -ccminer-fugue.o: sph/fugue.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-fugue.o -MD -MP -MF $(DEPDIR)/ccminer-fugue.Tpo -c -o ccminer-fugue.o `test -f 'sph/fugue.c' || echo '$(srcdir)/'`sph/fugue.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-fugue.Tpo $(DEPDIR)/ccminer-fugue.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/fugue.c' object='ccminer-fugue.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-fugue.o `test -f 'sph/fugue.c' || echo '$(srcdir)/'`sph/fugue.c - -ccminer-fugue.obj: sph/fugue.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ccminer-fugue.obj -MD -MP -MF $(DEPDIR)/ccminer-fugue.Tpo -c -o ccminer-fugue.obj `if test -f 'sph/fugue.c'; then $(CYGPATH_W) 'sph/fugue.c'; else $(CYGPATH_W) '$(srcdir)/sph/fugue.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ccminer-fugue.Tpo $(DEPDIR)/ccminer-fugue.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sph/fugue.c' object='ccminer-fugue.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ccminer-fugue.obj `if test -f 'sph/fugue.c'; then $(CYGPATH_W) 'sph/fugue.c'; else $(CYGPATH_W) '$(srcdir)/sph/fugue.c'; fi` - -.cpp.o: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -ccminer-fuguecoin.o: fuguecoin.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ccminer-fuguecoin.o -MD -MP -MF $(DEPDIR)/ccminer-fuguecoin.Tpo -c -o ccminer-fuguecoin.o `test -f 'fuguecoin.cpp' || echo '$(srcdir)/'`fuguecoin.cpp -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/ccminer-fuguecoin.Tpo $(DEPDIR)/ccminer-fuguecoin.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='fuguecoin.cpp' object='ccminer-fuguecoin.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ccminer-fuguecoin.o `test -f 'fuguecoin.cpp' || echo '$(srcdir)/'`fuguecoin.cpp - -ccminer-fuguecoin.obj: fuguecoin.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ccminer-fuguecoin.obj -MD -MP -MF $(DEPDIR)/ccminer-fuguecoin.Tpo -c -o ccminer-fuguecoin.obj `if test -f 'fuguecoin.cpp'; then $(CYGPATH_W) 'fuguecoin.cpp'; else $(CYGPATH_W) '$(srcdir)/fuguecoin.cpp'; fi` -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/ccminer-fuguecoin.Tpo $(DEPDIR)/ccminer-fuguecoin.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='fuguecoin.cpp' object='ccminer-fuguecoin.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ccminer-fuguecoin.obj `if test -f 'fuguecoin.cpp'; then $(CYGPATH_W) 'fuguecoin.cpp'; else $(CYGPATH_W) '$(srcdir)/fuguecoin.cpp'; fi` - -ccminer-groestlcoin.o: groestlcoin.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ccminer-groestlcoin.o -MD -MP -MF $(DEPDIR)/ccminer-groestlcoin.Tpo -c -o ccminer-groestlcoin.o `test -f 'groestlcoin.cpp' || echo '$(srcdir)/'`groestlcoin.cpp -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/ccminer-groestlcoin.Tpo $(DEPDIR)/ccminer-groestlcoin.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='groestlcoin.cpp' object='ccminer-groestlcoin.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ccminer-groestlcoin.o `test -f 'groestlcoin.cpp' || echo '$(srcdir)/'`groestlcoin.cpp - -ccminer-groestlcoin.obj: groestlcoin.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ccminer-groestlcoin.obj -MD -MP -MF $(DEPDIR)/ccminer-groestlcoin.Tpo -c -o ccminer-groestlcoin.obj `if test -f 'groestlcoin.cpp'; then $(CYGPATH_W) 'groestlcoin.cpp'; else $(CYGPATH_W) '$(srcdir)/groestlcoin.cpp'; fi` -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/ccminer-groestlcoin.Tpo $(DEPDIR)/ccminer-groestlcoin.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='groestlcoin.cpp' object='ccminer-groestlcoin.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ccminer-groestlcoin.obj `if test -f 'groestlcoin.cpp'; then $(CYGPATH_W) 'groestlcoin.cpp'; else $(CYGPATH_W) '$(srcdir)/groestlcoin.cpp'; fi` - -ccminer-myriadgroestl.o: myriadgroestl.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ccminer-myriadgroestl.o -MD -MP -MF $(DEPDIR)/ccminer-myriadgroestl.Tpo -c -o ccminer-myriadgroestl.o `test -f 'myriadgroestl.cpp' || echo '$(srcdir)/'`myriadgroestl.cpp -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/ccminer-myriadgroestl.Tpo $(DEPDIR)/ccminer-myriadgroestl.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='myriadgroestl.cpp' object='ccminer-myriadgroestl.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ccminer-myriadgroestl.o `test -f 'myriadgroestl.cpp' || echo '$(srcdir)/'`myriadgroestl.cpp - -ccminer-myriadgroestl.obj: myriadgroestl.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ccminer-myriadgroestl.obj -MD -MP -MF $(DEPDIR)/ccminer-myriadgroestl.Tpo -c -o ccminer-myriadgroestl.obj `if test -f 'myriadgroestl.cpp'; then $(CYGPATH_W) 'myriadgroestl.cpp'; else $(CYGPATH_W) '$(srcdir)/myriadgroestl.cpp'; fi` -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/ccminer-myriadgroestl.Tpo $(DEPDIR)/ccminer-myriadgroestl.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='myriadgroestl.cpp' object='ccminer-myriadgroestl.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ccminer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ccminer-myriadgroestl.obj `if test -f 'myriadgroestl.cpp'; then $(CYGPATH_W) 'myriadgroestl.cpp'; else $(CYGPATH_W) '$(srcdir)/myriadgroestl.cpp'; fi` - -# This directory's subdirectories are mostly independent; you can cd -# into them and run `make' without going through this Makefile. -# To change the values of `make' variables: instead of editing Makefiles, -# (1) if the variable is set in `config.status', edit `config.status' -# (which will cause the Makefiles to be regenerated when you run `make'); -# (2) otherwise, pass the desired values on the `make' command line. -$(RECURSIVE_TARGETS): - @fail= failcom='exit 1'; \ - for f in x $$MAKEFLAGS; do \ - case $$f in \ - *=* | --[!k]*);; \ - *k*) failcom='fail=yes';; \ - esac; \ - done; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || eval $$failcom; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -$(RECURSIVE_CLEAN_TARGETS): - @fail= failcom='exit 1'; \ - for f in x $$MAKEFLAGS; do \ - case $$f in \ - *=* | --[!k]*);; \ - *k*) failcom='fail=yes';; \ - esac; \ - done; \ - dot_seen=no; \ - case "$@" in \ - distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ - *) list='$(SUBDIRS)' ;; \ - esac; \ - rev=''; for subdir in $$list; do \ - if test "$$subdir" = "."; then :; else \ - rev="$$subdir $$rev"; \ - fi; \ - done; \ - rev="$$rev ."; \ - target=`echo $@ | sed s/-recursive//`; \ - for subdir in $$rev; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || eval $$failcom; \ - done && test -z "$$fail" -tags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ - done -ctags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ - done - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: tags-recursive $(HEADERS) $(SOURCES) cpuminer-config.h.in $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - set x; \ - here=`pwd`; \ - if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ - include_option=--etags-include; \ - empty_fix=.; \ - else \ - include_option=--include; \ - empty_fix=; \ - fi; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test ! -f $$subdir/TAGS || \ - set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ - fi; \ - done; \ - list='$(SOURCES) $(HEADERS) cpuminer-config.h.in $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - shift; \ - if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - if test $$# -gt 0; then \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - "$$@" $$unique; \ - else \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$unique; \ - fi; \ - fi -ctags: CTAGS -CTAGS: ctags-recursive $(HEADERS) $(SOURCES) cpuminer-config.h.in $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - list='$(SOURCES) $(HEADERS) cpuminer-config.h.in $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) "$$here" - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - $(am__remove_distdir) - test -d "$(distdir)" || mkdir "$(distdir)" - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done - @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -d "$(distdir)/$$subdir" \ - || $(MKDIR_P) "$(distdir)/$$subdir" \ - || exit 1; \ - fi; \ - done - @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ - $(am__relativize); \ - new_distdir=$$reldir; \ - dir1=$$subdir; dir2="$(top_distdir)"; \ - $(am__relativize); \ - new_top_distdir=$$reldir; \ - echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ - echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ - ($(am__cd) $$subdir && \ - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$$new_top_distdir" \ - distdir="$$new_distdir" \ - am__remove_distdir=: \ - am__skip_length_check=: \ - am__skip_mode_fix=: \ - distdir) \ - || exit 1; \ - fi; \ - done - -test -n "$(am__skip_mode_fix)" \ - || find "$(distdir)" -type d ! -perm -755 \ - -exec chmod u+rwx,go+rx {} \; -o \ - ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ - ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ - ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ - || chmod -R a+r "$(distdir)" -dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__remove_distdir) - -dist-bzip2: distdir - tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 - $(am__remove_distdir) - -dist-lzip: distdir - tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz - $(am__remove_distdir) - -dist-lzma: distdir - tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma - $(am__remove_distdir) - -dist-xz: distdir - tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz - $(am__remove_distdir) - -dist-tarZ: distdir - tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z - $(am__remove_distdir) - -dist-shar: distdir - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz - $(am__remove_distdir) - -dist-zip: distdir - -rm -f $(distdir).zip - zip -rq $(distdir).zip $(distdir) - $(am__remove_distdir) - -dist dist-all: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__remove_distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - case '$(DIST_ARCHIVES)' in \ - *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ - *.tar.bz2*) \ - bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ - *.tar.lzma*) \ - lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ - *.tar.lz*) \ - lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ - *.tar.xz*) \ - xz -dc $(distdir).tar.xz | $(am__untar) ;;\ - *.tar.Z*) \ - uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ - *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ - *.zip*) \ - unzip $(distdir).zip ;;\ - esac - chmod -R a-w $(distdir); chmod a+w $(distdir) - mkdir $(distdir)/_build - mkdir $(distdir)/_inst - chmod a-w $(distdir) - test -d $(distdir)/_build || exit 0; \ - dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ - && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ - && am__cwd=`pwd` \ - && $(am__cd) $(distdir)/_build \ - && ../configure --srcdir=.. --prefix="$$dc_install_base" \ - $(AM_DISTCHECK_CONFIGURE_FLAGS) \ - $(DISTCHECK_CONFIGURE_FLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) uninstall \ - && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ - distuninstallcheck \ - && chmod -R a-w "$$dc_install_base" \ - && ({ \ - (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ - && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ - && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ - && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ - distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ - } || { rm -rf "$$dc_destdir"; exit 1; }) \ - && rm -rf "$$dc_destdir" \ - && $(MAKE) $(AM_MAKEFLAGS) dist \ - && rm -rf $(DIST_ARCHIVES) \ - && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ - && cd "$$am__cwd" \ - || exit 1 - $(am__remove_distdir) - @(echo "$(distdir) archives ready for distribution: "; \ - list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ - sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' -distuninstallcheck: - @test -n '$(distuninstallcheck_dir)' || { \ - echo 'ERROR: trying to run $@ with an empty' \ - '$$(distuninstallcheck_dir)' >&2; \ - exit 1; \ - }; \ - $(am__cd) '$(distuninstallcheck_dir)' || { \ - echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ - exit 1; \ - }; \ - test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ - || { echo "ERROR: files left after uninstall:" ; \ - if test -n "$(DESTDIR)"; then \ - echo " (check DESTDIR support)"; \ - fi ; \ - $(distuninstallcheck_listfiles) ; \ - exit 1; } >&2 -distcleancheck: distclean - @if test '$(srcdir)' = . ; then \ - echo "ERROR: distcleancheck can only run from a VPATH build" ; \ - exit 1 ; \ - fi - @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ - || { echo "ERROR: files left in build directory after distclean:" ; \ - $(distcleancheck_listfiles) ; \ - exit 1; } >&2 -check-am: all-am -check: check-recursive -all-am: Makefile $(PROGRAMS) cpuminer-config.h -installdirs: installdirs-recursive -installdirs-am: - for dir in "$(DESTDIR)$(bindir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: install-recursive -install-exec: install-exec-recursive -install-data: install-data-recursive -uninstall: uninstall-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-recursive -install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -rm -f JHA/$(DEPDIR)/$(am__dirstamp) - -rm -f JHA/$(am__dirstamp) - -rm -f heavy/$(DEPDIR)/$(am__dirstamp) - -rm -f heavy/$(am__dirstamp) - -rm -f quark/$(DEPDIR)/$(am__dirstamp) - -rm -f quark/$(am__dirstamp) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-recursive - -clean-am: clean-binPROGRAMS clean-generic mostlyclean-am - -distclean: distclean-recursive - -rm -f $(am__CONFIG_DISTCLEAN_FILES) - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-hdr distclean-tags - -dvi: dvi-recursive - -dvi-am: - -html: html-recursive - -html-am: - -info: info-recursive - -info-am: - -install-data-am: - -install-dvi: install-dvi-recursive - -install-dvi-am: - -install-exec-am: install-binPROGRAMS - -install-html: install-html-recursive - -install-html-am: - -install-info: install-info-recursive - -install-info-am: - -install-man: - -install-pdf: install-pdf-recursive - -install-pdf-am: - -install-ps: install-ps-recursive - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-recursive - -rm -f $(am__CONFIG_DISTCLEAN_FILES) - -rm -rf $(top_srcdir)/autom4te.cache - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-recursive - -mostlyclean-am: mostlyclean-compile mostlyclean-generic - -pdf: pdf-recursive - -pdf-am: - -ps: ps-recursive - -ps-am: - -uninstall-am: uninstall-binPROGRAMS - -.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \ - ctags-recursive install-am install-strip tags-recursive - -.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ - all all-am am--refresh check check-am clean clean-binPROGRAMS \ - clean-generic ctags ctags-recursive dist dist-all dist-bzip2 \ - dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ dist-xz \ - dist-zip distcheck distclean distclean-compile \ - distclean-generic distclean-hdr distclean-tags distcleancheck \ - distdir distuninstallcheck dvi dvi-am html html-am info \ - info-am install install-am install-binPROGRAMS install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs installdirs-am maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic pdf pdf-am ps ps-am tags tags-recursive \ - uninstall uninstall-am uninstall-binPROGRAMS - - -# we're now targeting all major compute architectures within one binary. -.cu.o: - $(NVCC) @CFLAGS@ -I . -Xptxas "-abi=no -v" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --maxrregcount=80 --ptxas-options=-v $(JANSSON_INCLUDES) -o $@ -c $< - -# ABI requiring code modules -# this module doesn't compile with Compute 2.0 unfortunately -quark/cuda_quark_compactionTest.o: quark/cuda_quark_compactionTest.cu - $(NVCC) -I . -I cudpp-2.1/include @CFLAGS@ -Xptxas "-abi=yes -v" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --maxrregcount=80 --ptxas-options=-v $(JANSSON_INCLUDES) -o $@ -c $< - -JHA/cuda_jha_compactionTest.o: JHA/cuda_jha_compactionTest.cu - $(NVCC) -I . -I cudpp-2.1/include @CFLAGS@ -Xptxas "-abi=yes -v" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --maxrregcount=80 --ptxas-options=-v $(JANSSON_INCLUDES) -o $@ -c $< - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/README.md b/README.md index cf2d787..00a756e 100755 --- a/README.md +++ b/README.md @@ -1,78 +1,106 @@ -ccminer-cryptonight +# ccminer-cryptonight, a ccminer mod by tsiv and KlausT -A modification of Christian Buchner's & Christian H.'s -ccminer project by tsiv for Cryptonight mining. +If you find this tool useful and like to support its continued development, +then consider a donation. -July 5th 2014 -------------- +## KlausT's donation address: +* BTC: 1QHH2dibyYL5iyMDk3UN4PVvFVtrWD8QKp +* BCH: 1AH1u7B4KtDTUBgmT6NrXyahNEgTac3fL7 -Massive improvement to interactivity on Windows, should also further help with TDR issues. -Introducing the --bfactor and --bsleep command line parameters allows for control over -execution of the biggest resource hog of the algorithm. Use bfactor to determine how -many parts the kernel is split into and bsleep to insert a short delay between the kernel -launches. The defaults are no splitting / no sleep for Linux and split into 64 (bfactor 6) -parts / sleep 100 microseconds between launches for Windows. These defaults seem to work -wonders on my 750 Ti on Windows 7, once again you may want to tweak according to your -environment. +## tsiv's donation adresses: +* BTC: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs +* XMR: 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohDQLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX -June 30th 2014 --------------- +Don't forget to support the original ccminer authors +Christian Buchner and Christian H. This mod would not be +here without their work on ccminer: -I've keep getting asked for donation addresses, here are some -for wallets that I currently have up. Will set up other wallets -on request, in case you feel like donating but don't hold any -of the currencies I currently have addresses for. +* BTC donation address: 16hJF5mceSojnTD3ZTUDqdRhDyPJzoRakM -* BTC: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs -* DRK: XrHp267JNTVdw5P3dsBpqYfgTpWnzoESPQ -* JPC: Jb9hFeBgakCXvM5u27rTZoYR9j13JGmuc2 -* VTC: VwYsZFPb6KMeWuP4voiS9H1kqxcU9kGbsw -* XMR: 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohDQLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX +## Introduction + +This is a CUDA accelerated mining application for use with +Monero and other coins based on the Cryptonight algorithm. + +THIS PROGRAM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK! + +## Command Line Options +` + -a --algo choose between the supported algos: + cryptonight (the old version) + monero (v7) + graft (v8) + stellite (v3) + intense (v4) + electroneum (v6) + -d, --devices gives a comma separated list of CUDA device IDs + to operate on. Device IDs start counting from 0! + Alternatively give string names of your card like + gtx780ti or gt640#2 (matching 2nd gt640 in the PC). + -l, --launch=CONFIG launch config for the Cryptonight kernel. + a comma separated list of values in form of + AxB where A is the number of threads to run in + each thread block and B is the number of thread + blocks to launch. If less values than devices in use + are provided, the last value will be used for + the remaining devices. If you don't need to vary the + value between devices, you can just enter a single + value and it will be used for all devices. + --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ + The kernel will be run in 2^X parts according to bfactor,\n\ + with a small pause between parts, specified by --bsleep.\n\ + This is a per-device setting like the launch config.\n\ + (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ + --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ + Use in combination with --bfactor to mitigate the lag\n\ + when running on your primary GPU.\n\ + This is a per-device setting like the launch config.\n\ + -f, --diff Divide difficulty by this factor (std is 1) + -o, --url=URL URL of mining server (default: " DEF_RPC_URL ") + -O, --userpass=U:P username:password pair for mining server + -u, --user=USERNAME username for mining server + -p, --pass=PASSWORD password for mining server + --cert=FILE certificate for mining server using SSL + -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy + -t, --threads=N number of miner threads + (default: number of nVidia GPUs in your system) + -r, --retries=N number of times to retry if a network call fails + (default: retry indefinitely) + -R, --retry-pause=N time to pause between retries, in seconds (default: 15) + -T, --timeout=N network timeout, in seconds (default: 270) + -k, --keepalive send keepalive requests to avoid a stratum timeout + -s, --scantime=N upper bound on time spent scanning current work when + long polling is unavailable, in seconds (default: 5) + --no-longpoll disable X-Long-Polling support + --no-stratum disable X-Stratum support + -q, --quiet disable per-thread hashmeter output + -D, --debug enable debug output + --color enable color output + -P, --protocol-dump verbose dump of protocol-level activities + -B, --background run the miner in the background (Linux only) + --benchmark run in offline benchmark mode + -c, --config=FILE load a JSON-format configuration file + -V, --version display version information and exit + -h, --help display this help text and exit +``` + +## AUTHORS + +Notable contributors to this application are: +KlausT: +- various fixes and optimizations + +tsiv: +- CUDA implementation for the Cryptonight algorithm. + +Christian Buchner, Christian H. (Germany): +- modifying the original pooler-cpuminer for use with CUDA. + +Jeff Garzik, pooler + contributors: +- The original pooler-cpuminer project + +LucasJones: + - JSON-RPC 2.0 handling and the Cryptonight C-code comes + from his cpuminer fork, cpuminer-multi -In other news, I just yanked out the code for other alrogithms. -This is now a cryptonight-only miner. - - -June 24th 2014 --------------- - -Initial release, compiles and runs on Linux and Windows. -Documentation is scarce and probably will be, see README.txt -and ccminer --help for the basics. - -Before you read further (and you should), I highly recommend -running Linux. There are some issues with running on Windows -that are - -Do note that the cryptonight kernel on this release is FAT -and SLOW, and pretty much makes your Windows computer -unusable while running. If you plan on running it on your -primary desktop with only a single GPU... Well, just don't -think you'll be using the computer for anything. I haven't -tested it, but I'd expect it'll be fine if you have multiple -GPUs on the system and you run the miner only on the cards -that don't have a display attached. You'll still have the -TDR issue to deal with though: - -The kernel also tends to turn just long enough for Windows -to think the GPU crashed and trigger the driver timeout -detection and recovery. This is where the kernel launch -option (-l) hopefully comes in. - -The default launch is 40 tread blocks of 8 threads each. Don't -know why, but at least my 750 Ti seems to like 8 thread blocks -best. 40 blocks of 8 is something that, once again on my 750 ti, -manages to run fast enough to finish before the Windows default -2 second timeout. Basically enables you to run the damn thing -without the driver crashing instantly, which is why I made -it the default. Since I only have that one single 750 Ti -to test on Windows, I haven't got the slightest clue how -it works on other GPUs. Your mileage may vary. - -I peaked out my hashrate with 60 blocks of 8 threads, you'll -just have to experiment with it until (if) you find the sweet -spot for your cards. Do keep in mind that cryptonight needs -2 MB of memory for each hash, that would mean about 960 MB -of GPU memory for the 8x60 config. Keep that and the amount -of memory on your card in mind while playing around with -the numbers. +Source code is included to satisfy GNU GPL V3 requirements. diff --git a/README.txt b/README.txt index 0197c42..9a32e07 100755 --- a/README.txt +++ b/README.txt @@ -1,117 +1,113 @@ - -ccminer-cryptonight, a ccminer mod by tsiv -------------------------------------------------------------- - -*************************************************************** -If you find this tool useful and like to support its continued - development, then consider a donation. - - BTC donation address: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs - DRK donation address: XrHp267JNTVdw5P3dsBpqYfgTpWnzoESPQ - JPC donation address: Jb9hFeBgakCXvM5u27rTZoYR9j13JGmuc2 - VTC donation address: VwYsZFPb6KMeWuP4voiS9H1kqxcU9kGbsw - XMR donation address: - (man these are long... single address, split on two lines) - 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohD - QLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX - -Don't forget to support the original ccminer authors -Christian Buchner and Christian H. This mod would not be -here without their work on ccminer: - - LTC donation address: LKS1WDKGED647msBQfLBHV3Ls8sveGncnm - BTC donation address: 16hJF5mceSojnTD3ZTUDqdRhDyPJzoRakM - YAC donation address: Y87sptDEcpLkLeAuex6qZioDbvy1qXZEj4 - VTC donation address: VrjeFzMgvteCGarLw85KivBzmsiH9fqp4a - MAX donation address: mHrhQP9EFArechWxTFJ97s9D3jvcCvEEnt - DOGE donation address: DT9ghsGmez6ojVdEZgvaZbT2Z3TruXG6yP - HVC donation address: HNN3PyyTMkDo4RkEjkWSGMwqia1yD8mwJN - GRS donation address: FmJKJAhvyHWPeEVeLQHefr2naqgWc9ABTM - MYR donation address: MNHM7Q7HVfGpKDJgVJrY8ofwvmeugNewyf - JPC donation address: JYFBypVDkk583yKWY4M46TG5vXG8hfgD2U - SFR donation address: SR4b87aEnPfTs77bo9NnnaV21fiF6jQpAp - MNC donation address: MShgNUSYwybEbXLvJUtdNg1a7rUeiNgooK - BTQ donation address: 13GFwLiZL2DaA9XeE733PNrQX5QYLFsonS -*************************************************************** - ->>> Introduction <<< - -This is a CUDA accelerated mining application for use with -Monero and other coins based on the Cryptonight algorithm. - -THIS PROGRAM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK! - ->>> Command Line Interface <<< - -This code is based on the main ccminer branch, that in turn -is based on the pooler cpuminer 2.3.2 release and inherits -most of their command line interface and options. - - -d, --devices gives a comma separated list of CUDA device IDs - to operate on. Device IDs start counting from 0! - Alternatively give string names of your card like - gtx780ti or gt640#2 (matching 2nd gt640 in the PC). - -l, --launch=CONFIG launch config for the Cryptonight kernel. - a comma separated list of values in form of - AxB where A is the number of threads to run in - each thread block and B is the number of thread - blocks to launch. If less values than devices in use - are provided, the last value will be used for - the remaining devices. If you don't need to vary the - value between devices, you can just enter a single - value and it will be used for all devices. - (default: 8x40) - --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ - The kernel will be run in 2^X parts according to bfactor,\n\ - with a small pause between parts, specified by --bsleep.\n\ - This is a per-device setting like the launch config.\n\ - (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ - --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ - Use in combination with --bfactor to mitigate the lag\n\ - when running on your primary GPU.\n\ - This is a per-device setting like the launch config.\n\ - -f, --diff Divide difficulty by this factor (std is 1) - -o, --url=URL URL of mining server (default: " DEF_RPC_URL ") - -O, --userpass=U:P username:password pair for mining server - -u, --user=USERNAME username for mining server - -p, --pass=PASSWORD password for mining server - --cert=FILE certificate for mining server using SSL - -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy - -t, --threads=N number of miner threads - (default: number of nVidia GPUs in your system) - -r, --retries=N number of times to retry if a network call fails - (default: retry indefinitely) - -R, --retry-pause=N time to pause between retries, in seconds (default: 15) - -T, --timeout=N network timeout, in seconds (default: 270) - -s, --scantime=N upper bound on time spent scanning current work when - long polling is unavailable, in seconds (default: 5) - --no-longpoll disable X-Long-Polling support - --no-stratum disable X-Stratum support - -q, --quiet disable per-thread hashmeter output - -D, --debug enable debug output - -P, --protocol-dump verbose dump of protocol-level activities - -B, --background run the miner in the background - --benchmark run in offline benchmark mode - -c, --config=FILE load a JSON-format configuration file - -V, --version display version information and exit - -h, --help display this help text and exit - - ->>> AUTHORS <<< - -Notable contributors to this application are: - -tsiv: -- CUDA implementation for the Cryptonight algorithm. - -Christian Buchner, Christian H. (Germany): -- modifying the original pooler-cpuminer for use with CUDA. - -Jeff Garzik, pooler + contributors: -- The original pooler-cpuminer project - -LucasJones: - - JSON-RPC 2.0 handling and the Cryptonight C-code comes - from his cpuminer fork, cpuminer-multi - -Source code is included to satisfy GNU GPL V3 requirements. +ccminer-cryptonight, a ccminer mod by tsiv and KlausT +------------------------------------------------------------- + +*************************************************************** +If you find this tool useful and like to support its continued + development, then consider a donation. + +KlausT's BTC donation addresses: 1QDwdLPrPYSoPqS7pB2kGG84YX6hEcQ4JN + bc1qpt7qnvjaqu8t24xqajgyfqan2v00hrdgrut0zq +KlausT's BCH donation addresses: 1AH1u7B4KtDTUBgmT6NrXyahNEgTac3fL7 + qpjupzv3nevqzlkyxx5d736xt78jvet7usm479kl73 + +tsiv's BTC donation address: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs +tsiv's XMR donation address: 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohDQLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX + +Don't forget to support the original ccminer authors +Christian Buchner and Christian H. This mod would not be +here without their work on ccminer: + + BTC donation address: 16hJF5mceSojnTD3ZTUDqdRhDyPJzoRakM +*************************************************************** + +>>> Introduction <<< + +This is a CUDA accelerated mining application for use with +Monero and other coins based on the Cryptonight algorithm. + +THIS PROGRAM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK! + +>>> Command Line Interface <<< + +This code is based on the main ccminer branch, that in turn +is based on the pooler cpuminer 2.3.2 release and inherits +most of their command line interface and options. + + -a --algo choose between the supported algos: + cryptonight (the old version) + monero (v7) + graft (v8) + stellite (v3) + intense (v4) + electroneum (v6) + -d, --devices gives a comma separated list of CUDA device IDs + to operate on. Device IDs start counting from 0! + Alternatively give string names of your card like + gtx780ti or gt640#2 (matching 2nd gt640 in the PC). + -l, --launch=CONFIG launch config for the Cryptonight kernel. + a comma separated list of values in form of + AxB where A is the number of threads to run in + each thread block and B is the number of thread + blocks to launch. If less values than devices in use + are provided, the last value will be used for + the remaining devices. If you don't need to vary the + value between devices, you can just enter a single + value and it will be used for all devices. + --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ + The kernel will be run in 2^X parts according to bfactor,\n\ + with a small pause between parts, specified by --bsleep.\n\ + This is a per-device setting like the launch config.\n\ + (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ + --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ + Use in combination with --bfactor to mitigate the lag\n\ + when running on your primary GPU.\n\ + This is a per-device setting like the launch config.\n\ + -f, --diff Divide difficulty by this factor (std is 1) + -o, --url=URL URL of mining server (default: " DEF_RPC_URL ") + -O, --userpass=U:P username:password pair for mining server + -u, --user=USERNAME username for mining server + -p, --pass=PASSWORD password for mining server + --cert=FILE certificate for mining server using SSL + -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy + -t, --threads=N number of miner threads + (default: number of nVidia GPUs in your system) + -r, --retries=N number of times to retry if a network call fails + (default: retry indefinitely) + -R, --retry-pause=N time to pause between retries, in seconds (default: 15) + -T, --timeout=N network timeout, in seconds (default: 270) + -k, --keepalive send keepalive requests to avoid a stratum timeout + -s, --scantime=N upper bound on time spent scanning current work when + long polling is unavailable, in seconds (default: 5) + --no-longpoll disable X-Long-Polling support + --no-stratum disable X-Stratum support + -q, --quiet disable per-thread hashmeter output + -D, --debug enable debug output + --color enable color output + -P, --protocol-dump verbose dump of protocol-level activities + -B, --background run the miner in the background (Linux only) + --benchmark run in offline benchmark mode + -c, --config=FILE load a JSON-format configuration file + -V, --version display version information and exit + -h, --help display this help text and exit + + +>>> AUTHORS <<< + +Notable contributors to this application are: +KlausT: +- various fixes and optimizations + +tsiv: +- CUDA implementation for the Cryptonight algorithm. + +Christian Buchner, Christian H. (Germany): +- modifying the original pooler-cpuminer for use with CUDA. + +Jeff Garzik, pooler + contributors: +- The original pooler-cpuminer project + +LucasJones: + - JSON-RPC 2.0 handling and the Cryptonight C-code comes + from his cpuminer fork, cpuminer-multi + +Source code is included to satisfy GNU GPL V3 requirements. diff --git a/aclocal.m4 b/aclocal.m4 deleted file mode 100644 index 911786c..0000000 --- a/aclocal.m4 +++ /dev/null @@ -1,1319 +0,0 @@ -# generated automatically by aclocal 1.11.3 -*- Autoconf -*- - -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, -# Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -m4_ifndef([AC_AUTOCONF_VERSION], - [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],, -[m4_warning([this file was generated for autoconf 2.68. -You have another version of autoconf. It may work, but is not guaranteed to. -If you have problems, you may need to regenerate the build system entirely. -To do so, use the procedure documented by the package, typically `autoreconf'.])]) - -# LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION], -# [ACTION-IF-YES], [ACTION-IF-NO]) -# ---------------------------------------------------------- -# David Shaw May-09-2006 -# -# Checks for libcurl. DEFAULT-ACTION is the string yes or no to -# specify whether to default to --with-libcurl or --without-libcurl. -# If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the -# minimum version of libcurl to accept. Pass the version as a regular -# version number like 7.10.1. If not supplied, any version is -# accepted. ACTION-IF-YES is a list of shell commands to run if -# libcurl was successfully found and passed the various tests. -# ACTION-IF-NO is a list of shell commands that are run otherwise. -# Note that using --without-libcurl does run ACTION-IF-NO. -# -# This macro #defines HAVE_LIBCURL if a working libcurl setup is -# found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary -# values. Other useful defines are LIBCURL_FEATURE_xxx where xxx are -# the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy -# where yyy are the various protocols supported by libcurl. Both xxx -# and yyy are capitalized. See the list of AH_TEMPLATEs at the top of -# the macro for the complete list of possible defines. Shell -# variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also -# defined to 'yes' for those features and protocols that were found. -# Note that xxx and yyy keep the same capitalization as in the -# curl-config list (e.g. it's "HTTP" and not "http"). -# -# Users may override the detected values by doing something like: -# LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure -# -# For the sake of sanity, this macro assumes that any libcurl that is -# found is after version 7.7.2, the first version that included the -# curl-config script. Note that it is very important for people -# packaging binary versions of libcurl to include this script! -# Without curl-config, we can only guess what protocols are available, -# or use curl_version_info to figure it out at runtime. - -AC_DEFUN([LIBCURL_CHECK_CONFIG], -[ - AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL]) - AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4]) - AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6]) - AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz]) - AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS]) - AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN]) - AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI]) - AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM]) - - AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP]) - AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS]) - AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP]) - AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS]) - AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE]) - AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET]) - AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP]) - AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT]) - AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP]) - AH_TEMPLATE([LIBCURL_PROTOCOL_RTSP],[Defined if libcurl supports RTSP]) - AH_TEMPLATE([LIBCURL_PROTOCOL_POP3],[Defined if libcurl supports POP3]) - AH_TEMPLATE([LIBCURL_PROTOCOL_IMAP],[Defined if libcurl supports IMAP]) - AH_TEMPLATE([LIBCURL_PROTOCOL_SMTP],[Defined if libcurl supports SMTP]) - - AC_ARG_WITH(libcurl, - AC_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]), - [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])]) - - if test "$_libcurl_with" != "no" ; then - - AC_PROG_AWK - - _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'" - - _libcurl_try_link=yes - - if test -d "$_libcurl_with" ; then - LIBCURL_CPPFLAGS="-I$withval/include" - _libcurl_ldflags="-L$withval/lib" - AC_PATH_PROG([_libcurl_config],[curl-config],[], - ["$withval/bin"]) - else - AC_PATH_PROG([_libcurl_config],[curl-config],[],[$PATH]) - fi - - if test x$_libcurl_config != "x" ; then - AC_CACHE_CHECK([for the version of libcurl], - [libcurl_cv_lib_curl_version], - [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`]) - - _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse` - _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse` - - if test $_libcurl_wanted -gt 0 ; then - AC_CACHE_CHECK([for libcurl >= version $2], - [libcurl_cv_lib_version_ok], - [ - if test $_libcurl_version -ge $_libcurl_wanted ; then - libcurl_cv_lib_version_ok=yes - else - libcurl_cv_lib_version_ok=no - fi - ]) - fi - - if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then - if test x"$LIBCURL_CPPFLAGS" = "x" ; then - LIBCURL_CPPFLAGS=`$_libcurl_config --cflags` - fi - if test x"$LIBCURL" = "x" ; then - LIBCURL=`$_libcurl_config --libs` - - # This is so silly, but Apple actually has a bug in their - # curl-config script. Fixed in Tiger, but there are still - # lots of Panther installs around. - case "${host}" in - powerpc-apple-darwin7*) - LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'` - ;; - esac - fi - - # All curl-config scripts support --feature - _libcurl_features=`$_libcurl_config --feature` - - # Is it modern enough to have --protocols? (7.12.4) - if test $_libcurl_version -ge 461828 ; then - _libcurl_protocols=`$_libcurl_config --protocols` - fi - else - _libcurl_try_link=no - fi - - unset _libcurl_wanted - fi - - if test $_libcurl_try_link = yes ; then - - # we didn't find curl-config, so let's see if the user-supplied - # link line (or failing that, "-lcurl") is enough. - LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"} - - AC_CACHE_CHECK([whether libcurl is usable], - [libcurl_cv_lib_curl_usable], - [ - _libcurl_save_cppflags=$CPPFLAGS - CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS" - _libcurl_save_libs=$LIBS - LIBS="$LIBCURL $LIBS" - - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ],[ -/* Try and use a few common options to force a failure if we are - missing symbols or can't link. */ -int x; -curl_easy_setopt(NULL,CURLOPT_URL,NULL); -x=CURL_ERROR_SIZE; -x=CURLOPT_WRITEFUNCTION; -x=CURLOPT_FILE; -x=CURLOPT_ERRORBUFFER; -x=CURLOPT_STDERR; -x=CURLOPT_VERBOSE; -])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no) - - CPPFLAGS=$_libcurl_save_cppflags - LIBS=$_libcurl_save_libs - unset _libcurl_save_cppflags - unset _libcurl_save_libs - ]) - - if test $libcurl_cv_lib_curl_usable = yes ; then - - # Does curl_free() exist in this version of libcurl? - # If not, fake it with free() - - _libcurl_save_cppflags=$CPPFLAGS - CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS" - _libcurl_save_libs=$LIBS - LIBS="$LIBS $LIBCURL" - - AC_CHECK_FUNC(curl_free,, - AC_DEFINE(curl_free,free, - [Define curl_free() as free() if our version of curl lacks curl_free.])) - - CPPFLAGS=$_libcurl_save_cppflags - LIBS=$_libcurl_save_libs - unset _libcurl_save_cppflags - unset _libcurl_save_libs - - AC_DEFINE(HAVE_LIBCURL,1, - [Define to 1 if you have a functional curl library.]) - AC_SUBST(LIBCURL_CPPFLAGS) - AC_SUBST(LIBCURL) - - for _libcurl_feature in $_libcurl_features ; do - AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1]) - eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes - done - - if test "x$_libcurl_protocols" = "x" ; then - - # We don't have --protocols, so just assume that all - # protocols are available - _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP" - - if test x$libcurl_feature_SSL = xyes ; then - _libcurl_protocols="$_libcurl_protocols HTTPS" - - # FTPS wasn't standards-compliant until version - # 7.11.0 (0x070b00 == 461568) - if test $_libcurl_version -ge 461568; then - _libcurl_protocols="$_libcurl_protocols FTPS" - fi - fi - - # RTSP, IMAP, POP3 and SMTP were added in - # 7.20.0 (0x071400 == 463872) - if test $_libcurl_version -ge 463872; then - _libcurl_protocols="$_libcurl_protocols RTSP IMAP POP3 SMTP" - fi - fi - - for _libcurl_protocol in $_libcurl_protocols ; do - AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1]) - eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes - done - else - unset LIBCURL - unset LIBCURL_CPPFLAGS - fi - fi - - unset _libcurl_try_link - unset _libcurl_version_parse - unset _libcurl_config - unset _libcurl_feature - unset _libcurl_features - unset _libcurl_protocol - unset _libcurl_protocols - unset _libcurl_version - unset _libcurl_ldflags - fi - - if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then - # This is the IF-NO path - ifelse([$4],,:,[$4]) - else - # This is the IF-YES path - ifelse([$3],,:,[$3]) - fi - - unset _libcurl_with -])dnl - -# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 Free Software -# Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 1 - -# AM_AUTOMAKE_VERSION(VERSION) -# ---------------------------- -# Automake X.Y traces this macro to ensure aclocal.m4 has been -# generated from the m4 files accompanying Automake X.Y. -# (This private macro should not be called outside this file.) -AC_DEFUN([AM_AUTOMAKE_VERSION], -[am__api_version='1.11' -dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to -dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.11.3], [], - [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl -]) - -# _AM_AUTOCONF_VERSION(VERSION) -# ----------------------------- -# aclocal traces this macro to find the Autoconf version. -# This is a private macro too. Using m4_define simplifies -# the logic in aclocal, which can simply ignore this definition. -m4_define([_AM_AUTOCONF_VERSION], []) - -# AM_SET_CURRENT_AUTOMAKE_VERSION -# ------------------------------- -# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. -# This function is AC_REQUIREd by AM_INIT_AUTOMAKE. -AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.11.3])dnl -m4_ifndef([AC_AUTOCONF_VERSION], - [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) - -# Figure out how to run the assembler. -*- Autoconf -*- - -# Copyright (C) 2001, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 5 - -# AM_PROG_AS -# ---------- -AC_DEFUN([AM_PROG_AS], -[# By default we simply use the C compiler to build assembly code. -AC_REQUIRE([AC_PROG_CC]) -test "${CCAS+set}" = set || CCAS=$CC -test "${CCASFLAGS+set}" = set || CCASFLAGS=$CFLAGS -AC_ARG_VAR([CCAS], [assembler compiler command (defaults to CC)]) -AC_ARG_VAR([CCASFLAGS], [assembler compiler flags (defaults to CFLAGS)]) -_AM_IF_OPTION([no-dependencies],, [_AM_DEPENDENCIES([CCAS])])dnl -]) - -# AM_AUX_DIR_EXPAND -*- Autoconf -*- - -# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 1 - -# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets -# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to -# `$srcdir', `$srcdir/..', or `$srcdir/../..'. -# -# Of course, Automake must honor this variable whenever it calls a -# tool from the auxiliary directory. The problem is that $srcdir (and -# therefore $ac_aux_dir as well) can be either absolute or relative, -# depending on how configure is run. This is pretty annoying, since -# it makes $ac_aux_dir quite unusable in subdirectories: in the top -# source directory, any form will work fine, but in subdirectories a -# relative path needs to be adjusted first. -# -# $ac_aux_dir/missing -# fails when called from a subdirectory if $ac_aux_dir is relative -# $top_srcdir/$ac_aux_dir/missing -# fails if $ac_aux_dir is absolute, -# fails when called from a subdirectory in a VPATH build with -# a relative $ac_aux_dir -# -# The reason of the latter failure is that $top_srcdir and $ac_aux_dir -# are both prefixed by $srcdir. In an in-source build this is usually -# harmless because $srcdir is `.', but things will broke when you -# start a VPATH build or use an absolute $srcdir. -# -# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, -# iff we strip the leading $srcdir from $ac_aux_dir. That would be: -# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` -# and then we would define $MISSING as -# MISSING="\${SHELL} $am_aux_dir/missing" -# This will work as long as MISSING is not called from configure, because -# unfortunately $(top_srcdir) has no meaning in configure. -# However there are other variables, like CC, which are often used in -# configure, and could therefore not use this "fixed" $ac_aux_dir. -# -# Another solution, used here, is to always expand $ac_aux_dir to an -# absolute PATH. The drawback is that using absolute paths prevent a -# configured tree to be moved without reconfiguration. - -AC_DEFUN([AM_AUX_DIR_EXPAND], -[dnl Rely on autoconf to set up CDPATH properly. -AC_PREREQ([2.50])dnl -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` -]) - -# AM_CONDITIONAL -*- Autoconf -*- - -# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 -# Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 9 - -# AM_CONDITIONAL(NAME, SHELL-CONDITION) -# ------------------------------------- -# Define a conditional. -AC_DEFUN([AM_CONDITIONAL], -[AC_PREREQ(2.52)dnl - ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], - [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl -AC_SUBST([$1_TRUE])dnl -AC_SUBST([$1_FALSE])dnl -_AM_SUBST_NOTMAKE([$1_TRUE])dnl -_AM_SUBST_NOTMAKE([$1_FALSE])dnl -m4_define([_AM_COND_VALUE_$1], [$2])dnl -if $2; then - $1_TRUE= - $1_FALSE='#' -else - $1_TRUE='#' - $1_FALSE= -fi -AC_CONFIG_COMMANDS_PRE( -[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then - AC_MSG_ERROR([[conditional "$1" was never defined. -Usually this means the macro was only invoked conditionally.]]) -fi])]) - -# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, -# 2010, 2011 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 12 - -# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be -# written in clear, in which case automake, when reading aclocal.m4, -# will think it sees a *use*, and therefore will trigger all it's -# C support machinery. Also note that it means that autoscan, seeing -# CC etc. in the Makefile, will ask for an AC_PROG_CC use... - - -# _AM_DEPENDENCIES(NAME) -# ---------------------- -# See how the compiler implements dependency checking. -# NAME is "CC", "CXX", "GCJ", or "OBJC". -# We try a few techniques and use that to set a single cache variable. -# -# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was -# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular -# dependency, and given that the user is not expected to run this macro, -# just rely on AC_PROG_CC. -AC_DEFUN([_AM_DEPENDENCIES], -[AC_REQUIRE([AM_SET_DEPDIR])dnl -AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl -AC_REQUIRE([AM_MAKE_INCLUDE])dnl -AC_REQUIRE([AM_DEP_TRACK])dnl - -ifelse([$1], CC, [depcc="$CC" am_compiler_list=], - [$1], CXX, [depcc="$CXX" am_compiler_list=], - [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], - [$1], UPC, [depcc="$UPC" am_compiler_list=], - [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], - [depcc="$$1" am_compiler_list=]) - -AC_CACHE_CHECK([dependency style of $depcc], - [am_cv_$1_dependencies_compiler_type], -[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then - # We make a subdir and do the tests there. Otherwise we can end up - # making bogus files that we don't know about and never remove. For - # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. - rm -rf conftest.dir - mkdir conftest.dir - # Copy depcomp to subdir because otherwise we won't find it if we're - # using a relative directory. - cp "$am_depcomp" conftest.dir - cd conftest.dir - # We will build objects and dependencies in a subdirectory because - # it helps to detect inapplicable dependency modes. For instance - # both Tru64's cc and ICC support -MD to output dependencies as a - # side effect of compilation, but ICC will put the dependencies in - # the current directory while Tru64 will put them in the object - # directory. - mkdir sub - - am_cv_$1_dependencies_compiler_type=none - if test "$am_compiler_list" = ""; then - am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` - fi - am__universal=false - m4_case([$1], [CC], - [case " $depcc " in #( - *\ -arch\ *\ -arch\ *) am__universal=true ;; - esac], - [CXX], - [case " $depcc " in #( - *\ -arch\ *\ -arch\ *) am__universal=true ;; - esac]) - - for depmode in $am_compiler_list; do - # Setup a source with many dependencies, because some compilers - # like to wrap large dependency lists on column 80 (with \), and - # we should not choose a depcomp mode which is confused by this. - # - # We need to recreate these files for each test, as the compiler may - # overwrite some of them when testing with obscure command lines. - # This happens at least with the AIX C compiler. - : > sub/conftest.c - for i in 1 2 3 4 5 6; do - echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with - # Solaris 8's {/usr,}/bin/sh. - touch sub/conftst$i.h - done - echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - - # We check with `-c' and `-o' for the sake of the "dashmstdout" - # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs - am__obj=sub/conftest.${OBJEXT-o} - am__minus_obj="-o $am__obj" - case $depmode in - gcc) - # This depmode causes a compiler race in universal mode. - test "$am__universal" = false || continue - ;; - nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested - if test "x$enable_dependency_tracking" = xyes; then - continue - else - break - fi - ;; - msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok `-c -o', but also, the minuso test has - # not run yet. These depmodes are late enough in the game, and - # so weak that their functioning should not be impacted. - am__obj=conftest.${OBJEXT-o} - am__minus_obj= - ;; - none) break ;; - esac - if depmode=$depmode \ - source=sub/conftest.c object=$am__obj \ - depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ - $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ - >/dev/null 2>conftest.err && - grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && - grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && - grep $am__obj sub/conftest.Po > /dev/null 2>&1 && - ${MAKE-make} -s -f confmf > /dev/null 2>&1; then - # icc doesn't choke on unknown options, it will just issue warnings - # or remarks (even with -Werror). So we grep stderr for any message - # that says an option was ignored or not supported. - # When given -MP, icc 7.0 and 7.1 complain thusly: - # icc: Command line warning: ignoring option '-M'; no argument required - # The diagnosis changed in icc 8.0: - # icc: Command line remark: option '-MP' not supported - if (grep 'ignoring option' conftest.err || - grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else - am_cv_$1_dependencies_compiler_type=$depmode - break - fi - fi - done - - cd .. - rm -rf conftest.dir -else - am_cv_$1_dependencies_compiler_type=none -fi -]) -AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) -AM_CONDITIONAL([am__fastdep$1], [ - test "x$enable_dependency_tracking" != xno \ - && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) -]) - - -# AM_SET_DEPDIR -# ------------- -# Choose a directory name for dependency files. -# This macro is AC_REQUIREd in _AM_DEPENDENCIES -AC_DEFUN([AM_SET_DEPDIR], -[AC_REQUIRE([AM_SET_LEADING_DOT])dnl -AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl -]) - - -# AM_DEP_TRACK -# ------------ -AC_DEFUN([AM_DEP_TRACK], -[AC_ARG_ENABLE(dependency-tracking, -[ --disable-dependency-tracking speeds up one-time build - --enable-dependency-tracking do not reject slow dependency extractors]) -if test "x$enable_dependency_tracking" != xno; then - am_depcomp="$ac_aux_dir/depcomp" - AMDEPBACKSLASH='\' - am__nodep='_no' -fi -AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) -AC_SUBST([AMDEPBACKSLASH])dnl -_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl -AC_SUBST([am__nodep])dnl -_AM_SUBST_NOTMAKE([am__nodep])dnl -]) - -# Generate code to set up dependency tracking. -*- Autoconf -*- - -# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 -# Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -#serial 5 - -# _AM_OUTPUT_DEPENDENCY_COMMANDS -# ------------------------------ -AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], -[{ - # Autoconf 2.62 quotes --file arguments for eval, but not when files - # are listed without --file. Let's play safe and only enable the eval - # if we detect the quoting. - case $CONFIG_FILES in - *\'*) eval set x "$CONFIG_FILES" ;; - *) set x $CONFIG_FILES ;; - esac - shift - for mf - do - # Strip MF so we end up with the name of the file. - mf=`echo "$mf" | sed -e 's/:.*$//'` - # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named `Makefile.in', but - # some people rename them; so instead we look at the file content. - # Grep'ing the first line is not enough: some people post-process - # each Makefile.in and add a new line on top of each file to say so. - # Grep'ing the whole file is not good either: AIX grep has a line - # limit of 2048, but all sed's we know have understand at least 4000. - if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then - dirpart=`AS_DIRNAME("$mf")` - else - continue - fi - # Extract the definition of DEPDIR, am__include, and am__quote - # from the Makefile without running `make'. - DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` - test -z "$DEPDIR" && continue - am__include=`sed -n 's/^am__include = //p' < "$mf"` - test -z "am__include" && continue - am__quote=`sed -n 's/^am__quote = //p' < "$mf"` - # When using ansi2knr, U may be empty or an underscore; expand it - U=`sed -n 's/^U = //p' < "$mf"` - # Find all dependency output files, they are included files with - # $(DEPDIR) in their names. We invoke sed twice because it is the - # simplest approach to changing $(DEPDIR) to its actual value in the - # expansion. - for file in `sed -n " - s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do - # Make sure the directory exists. - test -f "$dirpart/$file" && continue - fdir=`AS_DIRNAME(["$file"])` - AS_MKDIR_P([$dirpart/$fdir]) - # echo "creating $dirpart/$file" - echo '# dummy' > "$dirpart/$file" - done - done -} -])# _AM_OUTPUT_DEPENDENCY_COMMANDS - - -# AM_OUTPUT_DEPENDENCY_COMMANDS -# ----------------------------- -# This macro should only be invoked once -- use via AC_REQUIRE. -# -# This code is only required when automatic dependency tracking -# is enabled. FIXME. This creates each `.P' file that we will -# need in order to bootstrap the dependency handling code. -AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], -[AC_CONFIG_COMMANDS([depfiles], - [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], - [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) -]) - -# Do all the work for Automake. -*- Autoconf -*- - -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2006, 2008, 2009 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 16 - -# This macro actually does too much. Some checks are only needed if -# your package does certain things. But this isn't really a big deal. - -# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) -# AM_INIT_AUTOMAKE([OPTIONS]) -# ----------------------------------------------- -# The call with PACKAGE and VERSION arguments is the old style -# call (pre autoconf-2.50), which is being phased out. PACKAGE -# and VERSION should now be passed to AC_INIT and removed from -# the call to AM_INIT_AUTOMAKE. -# We support both call styles for the transition. After -# the next Automake release, Autoconf can make the AC_INIT -# arguments mandatory, and then we can depend on a new Autoconf -# release and drop the old call support. -AC_DEFUN([AM_INIT_AUTOMAKE], -[AC_PREREQ([2.62])dnl -dnl Autoconf wants to disallow AM_ names. We explicitly allow -dnl the ones we care about. -m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl -AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl -AC_REQUIRE([AC_PROG_INSTALL])dnl -if test "`cd $srcdir && pwd`" != "`pwd`"; then - # Use -I$(srcdir) only when $(srcdir) != ., so that make's output - # is not polluted with repeated "-I." - AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl - # test to see if srcdir already configured - if test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) - fi -fi - -# test whether we have cygpath -if test -z "$CYGPATH_W"; then - if (cygpath --version) >/dev/null 2>/dev/null; then - CYGPATH_W='cygpath -w' - else - CYGPATH_W=echo - fi -fi -AC_SUBST([CYGPATH_W]) - -# Define the identity of the package. -dnl Distinguish between old-style and new-style calls. -m4_ifval([$2], -[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl - AC_SUBST([PACKAGE], [$1])dnl - AC_SUBST([VERSION], [$2])], -[_AM_SET_OPTIONS([$1])dnl -dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. -m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, - [m4_fatal([AC_INIT should be called with package and version arguments])])dnl - AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl - AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl - -_AM_IF_OPTION([no-define],, -[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) - AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl - -# Some tools Automake needs. -AC_REQUIRE([AM_SANITY_CHECK])dnl -AC_REQUIRE([AC_ARG_PROGRAM])dnl -AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) -AM_MISSING_PROG(AUTOCONF, autoconf) -AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) -AM_MISSING_PROG(AUTOHEADER, autoheader) -AM_MISSING_PROG(MAKEINFO, makeinfo) -AC_REQUIRE([AM_PROG_INSTALL_SH])dnl -AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl -AC_REQUIRE([AM_PROG_MKDIR_P])dnl -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. -AC_REQUIRE([AC_PROG_AWK])dnl -AC_REQUIRE([AC_PROG_MAKE_SET])dnl -AC_REQUIRE([AM_SET_LEADING_DOT])dnl -_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], - [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], - [_AM_PROG_TAR([v7])])]) -_AM_IF_OPTION([no-dependencies],, -[AC_PROVIDE_IFELSE([AC_PROG_CC], - [_AM_DEPENDENCIES(CC)], - [define([AC_PROG_CC], - defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl -AC_PROVIDE_IFELSE([AC_PROG_CXX], - [_AM_DEPENDENCIES(CXX)], - [define([AC_PROG_CXX], - defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl -AC_PROVIDE_IFELSE([AC_PROG_OBJC], - [_AM_DEPENDENCIES(OBJC)], - [define([AC_PROG_OBJC], - defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl -]) -_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl -dnl The `parallel-tests' driver may need to know about EXEEXT, so add the -dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro -dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. -AC_CONFIG_COMMANDS_PRE(dnl -[m4_provide_if([_AM_COMPILER_EXEEXT], - [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl -]) - -dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not -dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further -dnl mangled by Autoconf and run in a shell conditional statement. -m4_define([_AC_COMPILER_EXEEXT], -m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) - - -# When config.status generates a header, we must update the stamp-h file. -# This file resides in the same directory as the config header -# that is generated. The stamp files are numbered to have different names. - -# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the -# loop where config.status creates the headers, so we can generate -# our stamp files there. -AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], -[# Compute $1's index in $config_headers. -_am_arg=$1 -_am_stamp_count=1 -for _am_header in $config_headers :; do - case $_am_header in - $_am_arg | $_am_arg:* ) - break ;; - * ) - _am_stamp_count=`expr $_am_stamp_count + 1` ;; - esac -done -echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) - -# Copyright (C) 2001, 2003, 2005, 2008, 2011 Free Software Foundation, -# Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 1 - -# AM_PROG_INSTALL_SH -# ------------------ -# Define $install_sh. -AC_DEFUN([AM_PROG_INSTALL_SH], -[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -if test x"${install_sh}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; - *) - install_sh="\${SHELL} $am_aux_dir/install-sh" - esac -fi -AC_SUBST(install_sh)]) - -# Copyright (C) 2003, 2005 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 2 - -# Check whether the underlying file-system supports filenames -# with a leading dot. For instance MS-DOS doesn't. -AC_DEFUN([AM_SET_LEADING_DOT], -[rm -rf .tst 2>/dev/null -mkdir .tst 2>/dev/null -if test -d .tst; then - am__leading_dot=. -else - am__leading_dot=_ -fi -rmdir .tst 2>/dev/null -AC_SUBST([am__leading_dot])]) - -# Add --enable-maintainer-mode option to configure. -*- Autoconf -*- -# From Jim Meyering - -# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008, -# 2011 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 5 - -# AM_MAINTAINER_MODE([DEFAULT-MODE]) -# ---------------------------------- -# Control maintainer-specific portions of Makefiles. -# Default is to disable them, unless `enable' is passed literally. -# For symmetry, `disable' may be passed as well. Anyway, the user -# can override the default with the --enable/--disable switch. -AC_DEFUN([AM_MAINTAINER_MODE], -[m4_case(m4_default([$1], [disable]), - [enable], [m4_define([am_maintainer_other], [disable])], - [disable], [m4_define([am_maintainer_other], [enable])], - [m4_define([am_maintainer_other], [enable]) - m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) -AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) - dnl maintainer-mode's default is 'disable' unless 'enable' is passed - AC_ARG_ENABLE([maintainer-mode], -[ --][am_maintainer_other][-maintainer-mode am_maintainer_other make rules and dependencies not useful - (and sometimes confusing) to the casual installer], - [USE_MAINTAINER_MODE=$enableval], - [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) - AC_MSG_RESULT([$USE_MAINTAINER_MODE]) - AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) - MAINT=$MAINTAINER_MODE_TRUE - AC_SUBST([MAINT])dnl -] -) - -AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE]) - -# Check to see how 'make' treats includes. -*- Autoconf -*- - -# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 4 - -# AM_MAKE_INCLUDE() -# ----------------- -# Check to see how make treats includes. -AC_DEFUN([AM_MAKE_INCLUDE], -[am_make=${MAKE-make} -cat > confinc << 'END' -am__doit: - @echo this is the am__doit target -.PHONY: am__doit -END -# If we don't find an include directive, just comment out the code. -AC_MSG_CHECKING([for style of include used by $am_make]) -am__include="#" -am__quote= -_am_result=none -# First try GNU make style include. -echo "include confinc" > confmf -# Ignore all kinds of additional output from `make'. -case `$am_make -s -f confmf 2> /dev/null` in #( -*the\ am__doit\ target*) - am__include=include - am__quote= - _am_result=GNU - ;; -esac -# Now try BSD make style include. -if test "$am__include" = "#"; then - echo '.include "confinc"' > confmf - case `$am_make -s -f confmf 2> /dev/null` in #( - *the\ am__doit\ target*) - am__include=.include - am__quote="\"" - _am_result=BSD - ;; - esac -fi -AC_SUBST([am__include]) -AC_SUBST([am__quote]) -AC_MSG_RESULT([$_am_result]) -rm -f confinc confmf -]) - -# Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2008 -# Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 6 - -# AM_PROG_CC_C_O -# -------------- -# Like AC_PROG_CC_C_O, but changed for automake. -AC_DEFUN([AM_PROG_CC_C_O], -[AC_REQUIRE([AC_PROG_CC_C_O])dnl -AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -AC_REQUIRE_AUX_FILE([compile])dnl -# FIXME: we rely on the cache variable name because -# there is no other way. -set dummy $CC -am_cc=`echo $[2] | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']` -eval am_t=\$ac_cv_prog_cc_${am_cc}_c_o -if test "$am_t" != yes; then - # Losing compiler, so override with the script. - # FIXME: It is wrong to rewrite CC. - # But if we don't then we get into trouble of one sort or another. - # A longer-term fix would be to have automake use am__CC in this case, - # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" - CC="$am_aux_dir/compile $CC" -fi -dnl Make sure AC_PROG_CC is never called again, or it will override our -dnl setting of CC. -m4_define([AC_PROG_CC], - [m4_fatal([AC_PROG_CC cannot be called after AM_PROG_CC_C_O])]) -]) - -# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- - -# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 -# Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 6 - -# AM_MISSING_PROG(NAME, PROGRAM) -# ------------------------------ -AC_DEFUN([AM_MISSING_PROG], -[AC_REQUIRE([AM_MISSING_HAS_RUN]) -$1=${$1-"${am_missing_run}$2"} -AC_SUBST($1)]) - - -# AM_MISSING_HAS_RUN -# ------------------ -# Define MISSING if not defined so far and test if it supports --run. -# If it does, set am_missing_run to use it, otherwise, to nothing. -AC_DEFUN([AM_MISSING_HAS_RUN], -[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -AC_REQUIRE_AUX_FILE([missing])dnl -if test x"${MISSING+set}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; - *) - MISSING="\${SHELL} $am_aux_dir/missing" ;; - esac -fi -# Use eval to expand $SHELL -if eval "$MISSING --run true"; then - am_missing_run="$MISSING --run " -else - am_missing_run= - AC_MSG_WARN([`missing' script is too old or missing]) -fi -]) - -# Copyright (C) 2003, 2004, 2005, 2006, 2011 Free Software Foundation, -# Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 1 - -# AM_PROG_MKDIR_P -# --------------- -# Check for `mkdir -p'. -AC_DEFUN([AM_PROG_MKDIR_P], -[AC_PREREQ([2.60])dnl -AC_REQUIRE([AC_PROG_MKDIR_P])dnl -dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, -dnl while keeping a definition of mkdir_p for backward compatibility. -dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. -dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of -dnl Makefile.ins that do not define MKDIR_P, so we do our own -dnl adjustment using top_builddir (which is defined more often than -dnl MKDIR_P). -AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl -case $mkdir_p in - [[\\/$]]* | ?:[[\\/]]*) ;; - */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; -esac -]) - -# Helper functions for option handling. -*- Autoconf -*- - -# Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 Free Software -# Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 5 - -# _AM_MANGLE_OPTION(NAME) -# ----------------------- -AC_DEFUN([_AM_MANGLE_OPTION], -[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) - -# _AM_SET_OPTION(NAME) -# -------------------- -# Set option NAME. Presently that only means defining a flag for this option. -AC_DEFUN([_AM_SET_OPTION], -[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) - -# _AM_SET_OPTIONS(OPTIONS) -# ------------------------ -# OPTIONS is a space-separated list of Automake options. -AC_DEFUN([_AM_SET_OPTIONS], -[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) - -# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) -# ------------------------------------------- -# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. -AC_DEFUN([_AM_IF_OPTION], -[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) - -# Check to make sure that the build environment is sane. -*- Autoconf -*- - -# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 -# Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 5 - -# AM_SANITY_CHECK -# --------------- -AC_DEFUN([AM_SANITY_CHECK], -[AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftest.file -# Reject unsafe characters in $srcdir or the absolute working directory -# name. Accept space and tab only in the latter. -am_lf=' -' -case `pwd` in - *[[\\\"\#\$\&\'\`$am_lf]]*) - AC_MSG_ERROR([unsafe absolute working directory name]);; -esac -case $srcdir in - *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) - AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; -esac - -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$[*]" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - rm -f conftest.file - if test "$[*]" != "X $srcdir/configure conftest.file" \ - && test "$[*]" != "X conftest.file $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi - - test "$[2]" = conftest.file - ) -then - # Ok. - : -else - AC_MSG_ERROR([newly created file is older than distributed files! -Check your system clock]) -fi -AC_MSG_RESULT(yes)]) - -# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 1 - -# AM_PROG_INSTALL_STRIP -# --------------------- -# One issue with vendor `install' (even GNU) is that you can't -# specify the program used to strip binaries. This is especially -# annoying in cross-compiling environments, where the build's strip -# is unlikely to handle the host's binaries. -# Fortunately install-sh will honor a STRIPPROG variable, so we -# always use install-sh in `make install-strip', and initialize -# STRIPPROG with the value of the STRIP variable (set by the user). -AC_DEFUN([AM_PROG_INSTALL_STRIP], -[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl -# Installed binaries are usually stripped using `strip' when the user -# run `make install-strip'. However `strip' might not be the right -# tool to use in cross-compilation environments, therefore Automake -# will honor the `STRIP' environment variable to overrule this program. -dnl Don't test for $cross_compiling = yes, because it might be `maybe'. -if test "$cross_compiling" != no; then - AC_CHECK_TOOL([STRIP], [strip], :) -fi -INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" -AC_SUBST([INSTALL_STRIP_PROGRAM])]) - -# Copyright (C) 2006, 2008, 2010 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 3 - -# _AM_SUBST_NOTMAKE(VARIABLE) -# --------------------------- -# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. -# This macro is traced by Automake. -AC_DEFUN([_AM_SUBST_NOTMAKE]) - -# AM_SUBST_NOTMAKE(VARIABLE) -# -------------------------- -# Public sister of _AM_SUBST_NOTMAKE. -AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) - -# Check how to create a tarball. -*- Autoconf -*- - -# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 2 - -# _AM_PROG_TAR(FORMAT) -# -------------------- -# Check how to create a tarball in format FORMAT. -# FORMAT should be one of `v7', `ustar', or `pax'. -# -# Substitute a variable $(am__tar) that is a command -# writing to stdout a FORMAT-tarball containing the directory -# $tardir. -# tardir=directory && $(am__tar) > result.tar -# -# Substitute a variable $(am__untar) that extract such -# a tarball read from stdin. -# $(am__untar) < result.tar -AC_DEFUN([_AM_PROG_TAR], -[# Always define AMTAR for backward compatibility. Yes, it's still used -# in the wild :-( We should find a proper way to deprecate it ... -AC_SUBST([AMTAR], ['$${TAR-tar}']) -m4_if([$1], [v7], - [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], - [m4_case([$1], [ustar],, [pax],, - [m4_fatal([Unknown tar format])]) -AC_MSG_CHECKING([how to create a $1 tar archive]) -# Loop over all known methods to create a tar archive until one works. -_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' -_am_tools=${am_cv_prog_tar_$1-$_am_tools} -# Do not fold the above two line into one, because Tru64 sh and -# Solaris sh will not grok spaces in the rhs of `-'. -for _am_tool in $_am_tools -do - case $_am_tool in - gnutar) - for _am_tar in tar gnutar gtar; - do - AM_RUN_LOG([$_am_tar --version]) && break - done - am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' - am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' - am__untar="$_am_tar -xf -" - ;; - plaintar) - # Must skip GNU tar: if it does not support --format= it doesn't create - # ustar tarball either. - (tar --version) >/dev/null 2>&1 && continue - am__tar='tar chf - "$$tardir"' - am__tar_='tar chf - "$tardir"' - am__untar='tar xf -' - ;; - pax) - am__tar='pax -L -x $1 -w "$$tardir"' - am__tar_='pax -L -x $1 -w "$tardir"' - am__untar='pax -r' - ;; - cpio) - am__tar='find "$$tardir" -print | cpio -o -H $1 -L' - am__tar_='find "$tardir" -print | cpio -o -H $1 -L' - am__untar='cpio -i -H $1 -d' - ;; - none) - am__tar=false - am__tar_=false - am__untar=false - ;; - esac - - # If the value was cached, stop now. We just wanted to have am__tar - # and am__untar set. - test -n "${am_cv_prog_tar_$1}" && break - - # tar/untar a dummy directory, and stop if the command works - rm -rf conftest.dir - mkdir conftest.dir - echo GrepMe > conftest.dir/file - AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) - rm -rf conftest.dir - if test -s conftest.tar; then - AM_RUN_LOG([$am__untar /dev/null 2>&1 && break - fi -done -rm -rf conftest.dir - -AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) -AC_MSG_RESULT([$am_cv_prog_tar_$1])]) -AC_SUBST([am__tar]) -AC_SUBST([am__untar]) -]) # _AM_PROG_TAR - diff --git a/autogen.sh b/autogen.sh index 8261a2c..a4768b5 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1 +1 @@ -aclocal && autoheader && automake --add-missing --gnu --copy && autoconf +aclocal && autoheader && automake --add-missing --gnu --copy && autoconf diff --git a/ccminer.vcxproj b/ccminer.vcxproj index d78f830..26b64d8 100755 --- a/ccminer.vcxproj +++ b/ccminer.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -21,33 +21,38 @@ {36DC07F9-A4A6-4877-A146-1B960083CF6F} ccminer + ccminer-cryptonight Application true MultiByte + v140 Application true MultiByte + v140 Application false true MultiByte + v140 Application false true MultiByte + v140 - + @@ -70,9 +75,13 @@ false + $(SolutionDir)$(Configuration)\$(PlatformTarget)\ + $(SolutionDir)$(Configuration)\$(PlatformTarget)\temp\ false + $(SolutionDir)$(Configuration)\$(PlatformTarget)\ + $(SolutionDir)$(Configuration)\$(PlatformTarget)\temp\ @@ -138,104 +147,137 @@ copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" - Level3 - MaxSpeed + Full true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions) - .;compat;compat\jansson;compat\getopt;..\pthreads\Pre-built.2\include;..\curl-7.29.0\include;..\OpenSSL-Win32\include;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir) + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;HAVE_STRUCT_TIMESPEC;%(PreprocessorDefinitions) + .;compat;compat\jansson;compat\getopt;compat\includes;compat\includes\pthreads;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir) + Speed + false + Level3 + false + true + false - true + false true true Console - cudart.lib;cuda.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;pthreadVC2.lib;libcurl.lib;ws2_32.lib;Wldap32.lib;libeay32MT.lib;ssleay32MT.lib;%(AdditionalDependencies) - ..\pthreads\Pre-built.2\lib\x86;..\curl-7.29.0\build\lib\Release;..\OpenSSL-Win32\lib\VC\static;%(AdditionalLibraryDirectories);$(CudaToolkitLibDir) + cudart.lib;cuda.lib;Normaliz.lib;crypt32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;pthreadVC2.lib;libcurl.lib;ws2_32.lib;Wldap32.lib;libcrypto.lib;%(AdditionalDependencies) + compat\libs\x86;%(AdditionalLibraryDirectories);$(CudaToolkitLibDir) + true - echo copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" -copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" + + - true - - - 80 + false + true true - compute_20,sm_20;compute_30,sm_30;compute_35,sm_35 + compute_30,sm_30;compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61 + O3 + $(CudaIntDir)\temp\$(PlatformTarget) + 128 + Shared + + false + + + O2 + - Level3 - MaxSpeed + Full true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions) - .;compat;compat\jansson;compat\getopt;..\pthreads\Pre-built.2\include;..\curl-7.29.0_x64\include;..\OpenSSL-Win64\include;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir) + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;HAVE_STRUCT_TIMESPEC;%(PreprocessorDefinitions) + .;compat;compat\jansson;compat\getopt;compat\includes;compat\includes\pthreads;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir) + Speed + false + Level3 + false + true + false - true + false true true Console - cudart.lib;cuda.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;pthreadVC2.lib;libcurl.lib;ws2_32.lib;Wldap32.lib;libeay32MT.lib;ssleay32MT.lib;%(AdditionalDependencies) - ..\pthreads\Pre-built.2\lib\x64;..\curl-7.29.0_x64\build\lib\Release;..\OpenSSL-Win64\lib\VC\static;%(AdditionalLibraryDirectories);$(CudaToolkitLibDir) + cudart.lib;cuda.lib;Normaliz.lib;crypt32.lib;pthreadVC2.lib;libcurl.lib;ws2_32.lib;Wldap32.lib;libcrypto.lib;Winmm.lib;%(AdditionalDependencies) + compat\libs\x64;%(AdditionalLibraryDirectories);$(CudaToolkitLibDir) + true - echo copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" -copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" + + - true + false + - 80 - - - true + false true - compute_20,sm_20;compute_30,sm_30;compute_35,sm_35 + compute_30,sm_30;compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75 + 64 + O3 + $(CudaIntDir)\temp\$(PlatformTarget) + 128 + Shared + + false + + + O3 + + + + + - + /TP %(AdditionalOptions) /TP %(AdditionalOptions) /TP %(AdditionalOptions) /TP %(AdditionalOptions) - + /TP %(AdditionalOptions) /TP %(AdditionalOptions) /TP %(AdditionalOptions) /TP %(AdditionalOptions) - - - - - - - - - + + + + + + + + + /TP %(AdditionalOptions) /TP %(AdditionalOptions) /TP %(AdditionalOptions) @@ -246,11 +288,20 @@ copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" + + + + + + + + + - - + + @@ -263,30 +314,53 @@ copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" - + + true + true + + + true + true + - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) - -Xptxas "-abi=no -v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + -Xptxas "-v" %(AdditionalOptions) + + + true + true + + + true + true + + + true + true + + + true + true - + \ No newline at end of file diff --git a/ccminer.vcxproj.filters b/ccminer.vcxproj.filters index 2c6400f..b3d9aba 100755 --- a/ccminer.vcxproj.filters +++ b/ccminer.vcxproj.filters @@ -1,173 +1,230 @@ - - - - - {2450a9c7-a97a-49e1-ba19-c8dbc5a4e3e7} - - - {c53ce808-c5c5-4c6c-99a2-3947090c62f1} - - - {5a45c1bf-81d2-4bc6-97b5-714e34f51a82} - - - {431cec61-9376-4de9-aae9-04c4250652e7} - - - {cc8bb259-5332-4a45-ba81-f4840a55b604} - - - {89362bd8-4690-4f0c-a4f7-6b2fa67a1f34} - - - {6c3cd392-b6b8-424c-87d2-10e33dbd4b41} - - - {5a31b6f4-4943-4b22-b69a-230f3cc96269} - - - {a0f072d0-a831-4c23-8d64-7a026521df9c} - - - {fe39ded0-754b-415f-a284-038a15a0aa55} - - - {17b56151-79ec-4a32-bac3-9d94ae7f68fe} - - - - - Source Files\jansson - - - Source Files\jansson - - - Source Files\jansson - - - Source Files\jansson - - - Source Files\jansson - - - Source Files\jansson - - - Source Files\getopt - - - Source Files\gettimeofday - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Source Files\code - - - Header Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files\compat\sys - - - Header Files\compat - - - Header Files\compat - - - Header Files\compat\getopt - - - Header Files\compat - - - Header Files - - - Header Files - - - Header Files\CUDA - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files\CUDA - - - Source Files\CUDA - - - Source Files\CUDA - - + + + + + {2450a9c7-a97a-49e1-ba19-c8dbc5a4e3e7} + + + {c53ce808-c5c5-4c6c-99a2-3947090c62f1} + + + {5a45c1bf-81d2-4bc6-97b5-714e34f51a82} + + + {431cec61-9376-4de9-aae9-04c4250652e7} + + + {cc8bb259-5332-4a45-ba81-f4840a55b604} + + + {89362bd8-4690-4f0c-a4f7-6b2fa67a1f34} + + + {6c3cd392-b6b8-424c-87d2-10e33dbd4b41} + + + {5a31b6f4-4943-4b22-b69a-230f3cc96269} + + + {a0f072d0-a831-4c23-8d64-7a026521df9c} + + + {fe39ded0-754b-415f-a284-038a15a0aa55} + + + {17b56151-79ec-4a32-bac3-9d94ae7f68fe} + + + {8f1195ec-0869-4fa7-a24a-e56f06cd45fe} + + + + + Source Files\getopt + + + Source Files\gettimeofday + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files\jansson + + + Source Files + + + Source Files + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + Source Files\code + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files\compat\sys + + + Header Files\compat + + + Header Files\compat + + + Header Files\compat\getopt + + + Header Files\compat + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files\compat\jansson + + + Header Files + + + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + + Source Files\CUDA + + \ No newline at end of file diff --git a/compat/includes/curl/curl.h b/compat/includes/curl/curl.h new file mode 100644 index 0000000..1030712 --- /dev/null +++ b/compat/includes/curl/curl.h @@ -0,0 +1,2552 @@ +#ifndef __CURL_CURL_H +#define __CURL_CURL_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * If you have libcurl problems, all docs and details are found here: + * https://curl.haxx.se/libcurl/ + * + * curl-library mailing list subscription and unsubscription web interface: + * https://cool.haxx.se/mailman/listinfo/curl-library/ + */ + +#ifdef CURL_NO_OLDIES +#define CURL_STRICTER +#endif + +#include "curlver.h" /* libcurl version defines */ +#include "system.h" /* determine things run-time */ +#include "curlbuild.h" /* libcurl build definitions */ +#include "curlrules.h" /* libcurl rules enforcement */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && \ + !defined(WIN32) && !defined(__SYMBIAN32__) +#define WIN32 +#endif + +#include +#include + +#if defined(__FreeBSD__) && (__FreeBSD__ >= 2) +/* Needed for __FreeBSD_version symbol definition */ +#include +#endif + +/* The include stuff here below is mainly for time_t! */ +#include +#include + +#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) +#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \ + defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)) +/* The check above prevents the winsock2 inclusion if winsock.h already was + included, since they can't co-exist without problems */ +#include +#include +#endif +#endif + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on systems that are known to + require it! */ +#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ + defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ + defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \ + (defined(__FreeBSD_version) && (__FreeBSD_version < 800000)) +#include +#endif + +#if !defined(WIN32) && !defined(_WIN32_WCE) +#include +#endif + +#if !defined(WIN32) && !defined(__WATCOMC__) && !defined(__VXWORKS__) +#include +#endif + +#ifdef __BEOS__ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) +typedef struct Curl_easy CURL; +typedef struct Curl_share CURLSH; +#else +typedef void CURL; +typedef void CURLSH; +#endif + +/* + * libcurl external API function linkage decorations. + */ + +#ifdef CURL_STATICLIB +# define CURL_EXTERN +#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__) +# if defined(BUILDING_LIBCURL) +# define CURL_EXTERN __declspec(dllexport) +# else +# define CURL_EXTERN __declspec(dllimport) +# endif +#elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS) +# define CURL_EXTERN CURL_EXTERN_SYMBOL +#else +# define CURL_EXTERN +#endif + +#ifndef curl_socket_typedef +/* socket typedef */ +#if defined(WIN32) && !defined(__LWIP_OPT_H__) && !defined(LWIP_HDR_OPT_H) +typedef SOCKET curl_socket_t; +#define CURL_SOCKET_BAD INVALID_SOCKET +#else +typedef int curl_socket_t; +#define CURL_SOCKET_BAD -1 +#endif +#define curl_socket_typedef +#endif /* curl_socket_typedef */ + +struct curl_httppost { + struct curl_httppost *next; /* next entry in the list */ + char *name; /* pointer to allocated name */ + long namelength; /* length of name length */ + char *contents; /* pointer to allocated data contents */ + long contentslength; /* length of contents field, see also + CURL_HTTPPOST_LARGE */ + char *buffer; /* pointer to allocated buffer contents */ + long bufferlength; /* length of buffer field */ + char *contenttype; /* Content-Type */ + struct curl_slist *contentheader; /* list of extra headers for this form */ + struct curl_httppost *more; /* if one field name has more than one + file, this link should link to following + files */ + long flags; /* as defined below */ + +/* specified content is a file name */ +#define CURL_HTTPPOST_FILENAME (1<<0) +/* specified content is a file name */ +#define CURL_HTTPPOST_READFILE (1<<1) +/* name is only stored pointer do not free in formfree */ +#define CURL_HTTPPOST_PTRNAME (1<<2) +/* contents is only stored pointer do not free in formfree */ +#define CURL_HTTPPOST_PTRCONTENTS (1<<3) +/* upload file from buffer */ +#define CURL_HTTPPOST_BUFFER (1<<4) +/* upload file from pointer contents */ +#define CURL_HTTPPOST_PTRBUFFER (1<<5) +/* upload file contents by using the regular read callback to get the data and + pass the given pointer as custom pointer */ +#define CURL_HTTPPOST_CALLBACK (1<<6) +/* use size in 'contentlen', added in 7.46.0 */ +#define CURL_HTTPPOST_LARGE (1<<7) + + char *showfilename; /* The file name to show. If not set, the + actual file name will be used (if this + is a file part) */ + void *userp; /* custom pointer used for + HTTPPOST_CALLBACK posts */ + curl_off_t contentlen; /* alternative length of contents + field. Used if CURL_HTTPPOST_LARGE is + set. Added in 7.46.0 */ +}; + +/* This is the CURLOPT_PROGRESSFUNCTION callback proto. It is now considered + deprecated but was the only choice up until 7.31.0 */ +typedef int (*curl_progress_callback)(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); + +/* This is the CURLOPT_XFERINFOFUNCTION callback proto. It was introduced in + 7.32.0, it avoids floating point and provides more detailed information. */ +typedef int (*curl_xferinfo_callback)(void *clientp, + curl_off_t dltotal, + curl_off_t dlnow, + curl_off_t ultotal, + curl_off_t ulnow); + +#ifndef CURL_MAX_READ_SIZE + /* The maximum receive buffer size configurable via CURLOPT_BUFFERSIZE. */ +#define CURL_MAX_READ_SIZE 524288 +#endif + +#ifndef CURL_MAX_WRITE_SIZE + /* Tests have proven that 20K is a very bad buffer size for uploads on + Windows, while 16K for some odd reason performed a lot better. + We do the ifndef check to allow this value to easier be changed at build + time for those who feel adventurous. The practical minimum is about + 400 bytes since libcurl uses a buffer of this size as a scratch area + (unrelated to network send operations). */ +#define CURL_MAX_WRITE_SIZE 16384 +#endif + +#ifndef CURL_MAX_HTTP_HEADER +/* The only reason to have a max limit for this is to avoid the risk of a bad + server feeding libcurl with a never-ending header that will cause reallocs + infinitely */ +#define CURL_MAX_HTTP_HEADER (100*1024) +#endif + +/* This is a magic return code for the write callback that, when returned, + will signal libcurl to pause receiving on the current transfer. */ +#define CURL_WRITEFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_write_callback)(char *buffer, + size_t size, + size_t nitems, + void *outstream); + + + +/* enumeration of file types */ +typedef enum { + CURLFILETYPE_FILE = 0, + CURLFILETYPE_DIRECTORY, + CURLFILETYPE_SYMLINK, + CURLFILETYPE_DEVICE_BLOCK, + CURLFILETYPE_DEVICE_CHAR, + CURLFILETYPE_NAMEDPIPE, + CURLFILETYPE_SOCKET, + CURLFILETYPE_DOOR, /* is possible only on Sun Solaris now */ + + CURLFILETYPE_UNKNOWN /* should never occur */ +} curlfiletype; + +#define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) +#define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) +#define CURLFINFOFLAG_KNOWN_TIME (1<<2) +#define CURLFINFOFLAG_KNOWN_PERM (1<<3) +#define CURLFINFOFLAG_KNOWN_UID (1<<4) +#define CURLFINFOFLAG_KNOWN_GID (1<<5) +#define CURLFINFOFLAG_KNOWN_SIZE (1<<6) +#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) + +/* Content of this structure depends on information which is known and is + achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man + page for callbacks returning this structure -- some fields are mandatory, + some others are optional. The FLAG field has special meaning. */ +struct curl_fileinfo { + char *filename; + curlfiletype filetype; + time_t time; + unsigned int perm; + int uid; + int gid; + curl_off_t size; + long int hardlinks; + + struct { + /* If some of these fields is not NULL, it is a pointer to b_data. */ + char *time; + char *perm; + char *user; + char *group; + char *target; /* pointer to the target filename of a symlink */ + } strings; + + unsigned int flags; + + /* used internally */ + char *b_data; + size_t b_size; + size_t b_used; +}; + +/* return codes for CURLOPT_CHUNK_BGN_FUNCTION */ +#define CURL_CHUNK_BGN_FUNC_OK 0 +#define CURL_CHUNK_BGN_FUNC_FAIL 1 /* tell the lib to end the task */ +#define CURL_CHUNK_BGN_FUNC_SKIP 2 /* skip this chunk over */ + +/* if splitting of data transfer is enabled, this callback is called before + download of an individual chunk started. Note that parameter "remains" works + only for FTP wildcard downloading (for now), otherwise is not used */ +typedef long (*curl_chunk_bgn_callback)(const void *transfer_info, + void *ptr, + int remains); + +/* return codes for CURLOPT_CHUNK_END_FUNCTION */ +#define CURL_CHUNK_END_FUNC_OK 0 +#define CURL_CHUNK_END_FUNC_FAIL 1 /* tell the lib to end the task */ + +/* If splitting of data transfer is enabled this callback is called after + download of an individual chunk finished. + Note! After this callback was set then it have to be called FOR ALL chunks. + Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. + This is the reason why we don't need "transfer_info" parameter in this + callback and we are not interested in "remains" parameter too. */ +typedef long (*curl_chunk_end_callback)(void *ptr); + +/* return codes for FNMATCHFUNCTION */ +#define CURL_FNMATCHFUNC_MATCH 0 /* string corresponds to the pattern */ +#define CURL_FNMATCHFUNC_NOMATCH 1 /* pattern doesn't match the string */ +#define CURL_FNMATCHFUNC_FAIL 2 /* an error occurred */ + +/* callback type for wildcard downloading pattern matching. If the + string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ +typedef int (*curl_fnmatch_callback)(void *ptr, + const char *pattern, + const char *string); + +/* These are the return codes for the seek callbacks */ +#define CURL_SEEKFUNC_OK 0 +#define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */ +#define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so + libcurl might try other means instead */ +typedef int (*curl_seek_callback)(void *instream, + curl_off_t offset, + int origin); /* 'whence' */ + +/* This is a return code for the read callback that, when returned, will + signal libcurl to immediately abort the current transfer. */ +#define CURL_READFUNC_ABORT 0x10000000 +/* This is a return code for the read callback that, when returned, will + signal libcurl to pause sending data on the current transfer. */ +#define CURL_READFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_read_callback)(char *buffer, + size_t size, + size_t nitems, + void *instream); + +typedef enum { + CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */ + CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */ + CURLSOCKTYPE_LAST /* never use */ +} curlsocktype; + +/* The return code from the sockopt_callback can signal information back + to libcurl: */ +#define CURL_SOCKOPT_OK 0 +#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return + CURLE_ABORTED_BY_CALLBACK */ +#define CURL_SOCKOPT_ALREADY_CONNECTED 2 + +typedef int (*curl_sockopt_callback)(void *clientp, + curl_socket_t curlfd, + curlsocktype purpose); + +struct curl_sockaddr { + int family; + int socktype; + int protocol; + unsigned int addrlen; /* addrlen was a socklen_t type before 7.18.0 but it + turned really ugly and painful on the systems that + lack this type */ + struct sockaddr addr; +}; + +typedef curl_socket_t +(*curl_opensocket_callback)(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address); + +typedef int +(*curl_closesocket_callback)(void *clientp, curl_socket_t item); + +typedef enum { + CURLIOE_OK, /* I/O operation successful */ + CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ + CURLIOE_FAILRESTART, /* failed to restart the read */ + CURLIOE_LAST /* never use */ +} curlioerr; + +typedef enum { + CURLIOCMD_NOP, /* no operation */ + CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ + CURLIOCMD_LAST /* never use */ +} curliocmd; + +typedef curlioerr (*curl_ioctl_callback)(CURL *handle, + int cmd, + void *clientp); + +#ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS +/* + * The following typedef's are signatures of malloc, free, realloc, strdup and + * calloc respectively. Function pointers of these types can be passed to the + * curl_global_init_mem() function to set user defined memory management + * callback routines. + */ +typedef void *(*curl_malloc_callback)(size_t size); +typedef void (*curl_free_callback)(void *ptr); +typedef void *(*curl_realloc_callback)(void *ptr, size_t size); +typedef char *(*curl_strdup_callback)(const char *str); +typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); + +#define CURL_DID_MEMORY_FUNC_TYPEDEFS +#endif + +/* the kind of data that is passed to information_callback*/ +typedef enum { + CURLINFO_TEXT = 0, + CURLINFO_HEADER_IN, /* 1 */ + CURLINFO_HEADER_OUT, /* 2 */ + CURLINFO_DATA_IN, /* 3 */ + CURLINFO_DATA_OUT, /* 4 */ + CURLINFO_SSL_DATA_IN, /* 5 */ + CURLINFO_SSL_DATA_OUT, /* 6 */ + CURLINFO_END +} curl_infotype; + +typedef int (*curl_debug_callback) + (CURL *handle, /* the handle/transfer this concerns */ + curl_infotype type, /* what kind of data */ + char *data, /* points to the data */ + size_t size, /* size of the data pointed to */ + void *userptr); /* whatever the user please */ + +/* All possible error codes from all sorts of curl functions. Future versions + may return other values, stay prepared. + + Always add new return codes last. Never *EVER* remove any. The return + codes must remain the same! + */ + +typedef enum { + CURLE_OK = 0, + CURLE_UNSUPPORTED_PROTOCOL, /* 1 */ + CURLE_FAILED_INIT, /* 2 */ + CURLE_URL_MALFORMAT, /* 3 */ + CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for + 7.17.0, reused in April 2011 for 7.21.5] */ + CURLE_COULDNT_RESOLVE_PROXY, /* 5 */ + CURLE_COULDNT_RESOLVE_HOST, /* 6 */ + CURLE_COULDNT_CONNECT, /* 7 */ + CURLE_WEIRD_SERVER_REPLY, /* 8 */ + CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server + due to lack of access - when login fails + this is not returned. */ + CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for + 7.15.4, reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */ + CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server + [was obsoleted in August 2007 for 7.17.0, + reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */ + CURLE_FTP_WEIRD_227_FORMAT, /* 14 */ + CURLE_FTP_CANT_GET_HOST, /* 15 */ + CURLE_HTTP2, /* 16 - A problem in the http2 framing layer. + [was obsoleted in August 2007 for 7.17.0, + reused in July 2014 for 7.38.0] */ + CURLE_FTP_COULDNT_SET_TYPE, /* 17 */ + CURLE_PARTIAL_FILE, /* 18 */ + CURLE_FTP_COULDNT_RETR_FILE, /* 19 */ + CURLE_OBSOLETE20, /* 20 - NOT USED */ + CURLE_QUOTE_ERROR, /* 21 - quote command failure */ + CURLE_HTTP_RETURNED_ERROR, /* 22 */ + CURLE_WRITE_ERROR, /* 23 */ + CURLE_OBSOLETE24, /* 24 - NOT USED */ + CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */ + CURLE_READ_ERROR, /* 26 - couldn't open/read from file */ + CURLE_OUT_OF_MEMORY, /* 27 */ + /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error + instead of a memory allocation error if CURL_DOES_CONVERSIONS + is defined + */ + CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */ + CURLE_OBSOLETE29, /* 29 - NOT USED */ + CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */ + CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */ + CURLE_OBSOLETE32, /* 32 - NOT USED */ + CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */ + CURLE_HTTP_POST_ERROR, /* 34 */ + CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */ + CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */ + CURLE_FILE_COULDNT_READ_FILE, /* 37 */ + CURLE_LDAP_CANNOT_BIND, /* 38 */ + CURLE_LDAP_SEARCH_FAILED, /* 39 */ + CURLE_OBSOLETE40, /* 40 - NOT USED */ + CURLE_FUNCTION_NOT_FOUND, /* 41 - NOT USED starting with 7.53.0 */ + CURLE_ABORTED_BY_CALLBACK, /* 42 */ + CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */ + CURLE_OBSOLETE44, /* 44 - NOT USED */ + CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */ + CURLE_OBSOLETE46, /* 46 - NOT USED */ + CURLE_TOO_MANY_REDIRECTS, /* 47 - catch endless re-direct loops */ + CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */ + CURLE_TELNET_OPTION_SYNTAX, /* 49 - Malformed telnet option */ + CURLE_OBSOLETE50, /* 50 - NOT USED */ + CURLE_PEER_FAILED_VERIFICATION, /* 51 - peer's certificate or fingerprint + wasn't verified fine */ + CURLE_GOT_NOTHING, /* 52 - when this is a specific error */ + CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */ + CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as + default */ + CURLE_SEND_ERROR, /* 55 - failed sending network data */ + CURLE_RECV_ERROR, /* 56 - failure in receiving network data */ + CURLE_OBSOLETE57, /* 57 - NOT IN USE */ + CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */ + CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */ + CURLE_SSL_CACERT, /* 60 - problem with the CA cert (path?) */ + CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */ + CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */ + CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */ + CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */ + CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind + that failed */ + CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */ + CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not + accepted and we failed to login */ + CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */ + CURLE_TFTP_PERM, /* 69 - permission problem on server */ + CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */ + CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */ + CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */ + CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */ + CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */ + CURLE_CONV_FAILED, /* 75 - conversion failed */ + CURLE_CONV_REQD, /* 76 - caller must register conversion + callbacks using curl_easy_setopt options + CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOPT_CONV_TO_NETWORK_FUNCTION, and + CURLOPT_CONV_FROM_UTF8_FUNCTION */ + CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing + or wrong format */ + CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */ + CURLE_SSH, /* 79 - error from the SSH layer, somewhat + generic so the error message will be of + interest when this has happened */ + + CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL + connection */ + CURLE_AGAIN, /* 81 - socket is not ready for send/recv, + wait till it's ready and try again (Added + in 7.18.2) */ + CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or + wrong format (Added in 7.19.0) */ + CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in + 7.19.0) */ + CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */ + CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */ + CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */ + CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */ + CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */ + CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the + session will be queued */ + CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not + match */ + CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */ + CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer + */ + CURL_LAST /* never use! */ +} CURLcode; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Previously obsolete error code re-used in 7.38.0 */ +#define CURLE_OBSOLETE16 CURLE_HTTP2 + +/* Previously obsolete error codes re-used in 7.24.0 */ +#define CURLE_OBSOLETE10 CURLE_FTP_ACCEPT_FAILED +#define CURLE_OBSOLETE12 CURLE_FTP_ACCEPT_TIMEOUT + +/* compatibility with older names */ +#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING +#define CURLE_FTP_WEIRD_SERVER_REPLY CURLE_WEIRD_SERVER_REPLY + +/* The following were added in 7.21.5, April 2011 */ +#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION + +/* The following were added in 7.17.1 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_SSL_PEER_CERTIFICATE CURLE_PEER_FAILED_VERIFICATION + +/* The following were added in 7.17.0 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_OBSOLETE CURLE_OBSOLETE50 /* no one should be using this! */ +#define CURLE_BAD_PASSWORD_ENTERED CURLE_OBSOLETE46 +#define CURLE_BAD_CALLING_ORDER CURLE_OBSOLETE44 +#define CURLE_FTP_USER_PASSWORD_INCORRECT CURLE_OBSOLETE10 +#define CURLE_FTP_CANT_RECONNECT CURLE_OBSOLETE16 +#define CURLE_FTP_COULDNT_GET_SIZE CURLE_OBSOLETE32 +#define CURLE_FTP_COULDNT_SET_ASCII CURLE_OBSOLETE29 +#define CURLE_FTP_WEIRD_USER_REPLY CURLE_OBSOLETE12 +#define CURLE_FTP_WRITE_ERROR CURLE_OBSOLETE20 +#define CURLE_LIBRARY_NOT_FOUND CURLE_OBSOLETE40 +#define CURLE_MALFORMAT_USER CURLE_OBSOLETE24 +#define CURLE_SHARE_IN_USE CURLE_OBSOLETE57 +#define CURLE_URL_MALFORMAT_USER CURLE_NOT_BUILT_IN + +#define CURLE_FTP_ACCESS_DENIED CURLE_REMOTE_ACCESS_DENIED +#define CURLE_FTP_COULDNT_SET_BINARY CURLE_FTP_COULDNT_SET_TYPE +#define CURLE_FTP_QUOTE_ERROR CURLE_QUOTE_ERROR +#define CURLE_TFTP_DISKFULL CURLE_REMOTE_DISK_FULL +#define CURLE_TFTP_EXISTS CURLE_REMOTE_FILE_EXISTS +#define CURLE_HTTP_RANGE_ERROR CURLE_RANGE_ERROR +#define CURLE_FTP_SSL_FAILED CURLE_USE_SSL_FAILED + +/* The following were added earlier */ + +#define CURLE_OPERATION_TIMEOUTED CURLE_OPERATION_TIMEDOUT + +#define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR +#define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED +#define CURLE_FTP_COULDNT_STOR_FILE CURLE_UPLOAD_FAILED + +#define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE +#define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME + +/* This was the error code 50 in 7.7.3 and a few earlier versions, this + is no longer used by libcurl but is instead #defined here only to not + make programs break */ +#define CURLE_ALREADY_COMPLETE 99999 + +/* Provide defines for really old option names */ +#define CURLOPT_FILE CURLOPT_WRITEDATA /* name changed in 7.9.7 */ +#define CURLOPT_INFILE CURLOPT_READDATA /* name changed in 7.9.7 */ +#define CURLOPT_WRITEHEADER CURLOPT_HEADERDATA + +/* Since long deprecated options with no code in the lib that does anything + with them. */ +#define CURLOPT_WRITEINFO CURLOPT_OBSOLETE40 +#define CURLOPT_CLOSEPOLICY CURLOPT_OBSOLETE72 + +#endif /*!CURL_NO_OLDIES*/ + +/* This prototype applies to all conversion callbacks */ +typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length); + +typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */ + void *ssl_ctx, /* actually an + OpenSSL SSL_CTX */ + void *userptr); + +typedef enum { + CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use + CONNECT HTTP/1.1 */ + CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT + HTTP/1.0 */ + CURLPROXY_HTTPS = 2, /* added in 7.52.0 */ + CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already + in 7.10 */ + CURLPROXY_SOCKS5 = 5, /* added in 7.10 */ + CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */ + CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the + host name rather than the IP address. added + in 7.18.0 */ +} curl_proxytype; /* this enum was added in 7.10 */ + +/* + * Bitmasks for CURLOPT_HTTPAUTH and CURLOPT_PROXYAUTH options: + * + * CURLAUTH_NONE - No HTTP authentication + * CURLAUTH_BASIC - HTTP Basic authentication (default) + * CURLAUTH_DIGEST - HTTP Digest authentication + * CURLAUTH_NEGOTIATE - HTTP Negotiate (SPNEGO) authentication + * CURLAUTH_GSSNEGOTIATE - Alias for CURLAUTH_NEGOTIATE (deprecated) + * CURLAUTH_NTLM - HTTP NTLM authentication + * CURLAUTH_DIGEST_IE - HTTP Digest authentication with IE flavour + * CURLAUTH_NTLM_WB - HTTP NTLM authentication delegated to winbind helper + * CURLAUTH_ONLY - Use together with a single other type to force no + * authentication or just that single type + * CURLAUTH_ANY - All fine types set + * CURLAUTH_ANYSAFE - All fine types except Basic + */ + +#define CURLAUTH_NONE ((unsigned long)0) +#define CURLAUTH_BASIC (((unsigned long)1)<<0) +#define CURLAUTH_DIGEST (((unsigned long)1)<<1) +#define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2) +/* Deprecated since the advent of CURLAUTH_NEGOTIATE */ +#define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE +#define CURLAUTH_NTLM (((unsigned long)1)<<3) +#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) +#define CURLAUTH_NTLM_WB (((unsigned long)1)<<5) +#define CURLAUTH_ONLY (((unsigned long)1)<<31) +#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) +#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) + +#define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */ +#define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */ +#define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */ +#define CURLSSH_AUTH_PASSWORD (1<<1) /* password */ +#define CURLSSH_AUTH_HOST (1<<2) /* host key files */ +#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ +#define CURLSSH_AUTH_AGENT (1<<4) /* agent (ssh-agent, pageant...) */ +#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY + +#define CURLGSSAPI_DELEGATION_NONE 0 /* no delegation (default) */ +#define CURLGSSAPI_DELEGATION_POLICY_FLAG (1<<0) /* if permitted by policy */ +#define CURLGSSAPI_DELEGATION_FLAG (1<<1) /* delegate always */ + +#define CURL_ERROR_SIZE 256 + +enum curl_khtype { + CURLKHTYPE_UNKNOWN, + CURLKHTYPE_RSA1, + CURLKHTYPE_RSA, + CURLKHTYPE_DSS +}; + +struct curl_khkey { + const char *key; /* points to a zero-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ + size_t len; + enum curl_khtype keytype; +}; + +/* this is the set of return values expected from the curl_sshkeycallback + callback */ +enum curl_khstat { + CURLKHSTAT_FINE_ADD_TO_FILE, + CURLKHSTAT_FINE, + CURLKHSTAT_REJECT, /* reject the connection, return an error */ + CURLKHSTAT_DEFER, /* do not accept it, but we can't answer right now so + this causes a CURLE_DEFER error but otherwise the + connection will be left intact etc */ + CURLKHSTAT_LAST /* not for use, only a marker for last-in-list */ +}; + +/* this is the set of status codes pass in to the callback */ +enum curl_khmatch { + CURLKHMATCH_OK, /* match */ + CURLKHMATCH_MISMATCH, /* host found, key mismatch! */ + CURLKHMATCH_MISSING, /* no matching host/key found */ + CURLKHMATCH_LAST /* not for use, only a marker for last-in-list */ +}; + +typedef int + (*curl_sshkeycallback) (CURL *easy, /* easy handle */ + const struct curl_khkey *knownkey, /* known */ + const struct curl_khkey *foundkey, /* found */ + enum curl_khmatch, /* libcurl's view on the keys */ + void *clientp); /* custom pointer passed from app */ + +/* parameter for the CURLOPT_USE_SSL option */ +typedef enum { + CURLUSESSL_NONE, /* do not attempt to use SSL */ + CURLUSESSL_TRY, /* try using SSL, proceed anyway otherwise */ + CURLUSESSL_CONTROL, /* SSL for the control connection or fail */ + CURLUSESSL_ALL, /* SSL for all communication or fail */ + CURLUSESSL_LAST /* not an option, never use */ +} curl_usessl; + +/* Definition of bits for the CURLOPT_SSL_OPTIONS argument: */ + +/* - ALLOW_BEAST tells libcurl to allow the BEAST SSL vulnerability in the + name of improving interoperability with older servers. Some SSL libraries + have introduced work-arounds for this flaw but those work-arounds sometimes + make the SSL communication fail. To regain functionality with those broken + servers, a user can this way allow the vulnerability back. */ +#define CURLSSLOPT_ALLOW_BEAST (1<<0) + +/* - NO_REVOKE tells libcurl to disable certificate revocation checks for those + SSL backends where such behavior is present. */ +#define CURLSSLOPT_NO_REVOKE (1<<1) + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2009 */ + +#define CURLFTPSSL_NONE CURLUSESSL_NONE +#define CURLFTPSSL_TRY CURLUSESSL_TRY +#define CURLFTPSSL_CONTROL CURLUSESSL_CONTROL +#define CURLFTPSSL_ALL CURLUSESSL_ALL +#define CURLFTPSSL_LAST CURLUSESSL_LAST +#define curl_ftpssl curl_usessl +#endif /*!CURL_NO_OLDIES*/ + +/* parameter for the CURLOPT_FTP_SSL_CCC option */ +typedef enum { + CURLFTPSSL_CCC_NONE, /* do not send CCC */ + CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */ + CURLFTPSSL_CCC_ACTIVE, /* Initiate the shutdown */ + CURLFTPSSL_CCC_LAST /* not an option, never use */ +} curl_ftpccc; + +/* parameter for the CURLOPT_FTPSSLAUTH option */ +typedef enum { + CURLFTPAUTH_DEFAULT, /* let libcurl decide */ + CURLFTPAUTH_SSL, /* use "AUTH SSL" */ + CURLFTPAUTH_TLS, /* use "AUTH TLS" */ + CURLFTPAUTH_LAST /* not an option, never use */ +} curl_ftpauth; + +/* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ +typedef enum { + CURLFTP_CREATE_DIR_NONE, /* do NOT create missing dirs! */ + CURLFTP_CREATE_DIR, /* (FTP/SFTP) if CWD fails, try MKD and then CWD + again if MKD succeeded, for SFTP this does + similar magic */ + CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD + again even if MKD failed! */ + CURLFTP_CREATE_DIR_LAST /* not an option, never use */ +} curl_ftpcreatedir; + +/* parameter for the CURLOPT_FTP_FILEMETHOD option */ +typedef enum { + CURLFTPMETHOD_DEFAULT, /* let libcurl pick */ + CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */ + CURLFTPMETHOD_NOCWD, /* no CWD at all */ + CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */ + CURLFTPMETHOD_LAST /* not an option, never use */ +} curl_ftpmethod; + +/* bitmask defines for CURLOPT_HEADEROPT */ +#define CURLHEADER_UNIFIED 0 +#define CURLHEADER_SEPARATE (1<<0) + +/* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ +#define CURLPROTO_HTTP (1<<0) +#define CURLPROTO_HTTPS (1<<1) +#define CURLPROTO_FTP (1<<2) +#define CURLPROTO_FTPS (1<<3) +#define CURLPROTO_SCP (1<<4) +#define CURLPROTO_SFTP (1<<5) +#define CURLPROTO_TELNET (1<<6) +#define CURLPROTO_LDAP (1<<7) +#define CURLPROTO_LDAPS (1<<8) +#define CURLPROTO_DICT (1<<9) +#define CURLPROTO_FILE (1<<10) +#define CURLPROTO_TFTP (1<<11) +#define CURLPROTO_IMAP (1<<12) +#define CURLPROTO_IMAPS (1<<13) +#define CURLPROTO_POP3 (1<<14) +#define CURLPROTO_POP3S (1<<15) +#define CURLPROTO_SMTP (1<<16) +#define CURLPROTO_SMTPS (1<<17) +#define CURLPROTO_RTSP (1<<18) +#define CURLPROTO_RTMP (1<<19) +#define CURLPROTO_RTMPT (1<<20) +#define CURLPROTO_RTMPE (1<<21) +#define CURLPROTO_RTMPTE (1<<22) +#define CURLPROTO_RTMPS (1<<23) +#define CURLPROTO_RTMPTS (1<<24) +#define CURLPROTO_GOPHER (1<<25) +#define CURLPROTO_SMB (1<<26) +#define CURLPROTO_SMBS (1<<27) +#define CURLPROTO_ALL (~0) /* enable everything */ + +/* long may be 32 or 64 bits, but we should never depend on anything else + but 32 */ +#define CURLOPTTYPE_LONG 0 +#define CURLOPTTYPE_OBJECTPOINT 10000 +#define CURLOPTTYPE_STRINGPOINT 10000 +#define CURLOPTTYPE_FUNCTIONPOINT 20000 +#define CURLOPTTYPE_OFF_T 30000 + +/* *STRINGPOINT is an alias for OBJECTPOINT to allow tools to extract the + string options from the header file */ + +/* name is uppercase CURLOPT_, + type is one of the defined CURLOPTTYPE_ + number is unique identifier */ +#ifdef CINIT +#undef CINIT +#endif + +#ifdef CURL_ISOCPP +#define CINIT(na,t,nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define STRINGPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLOPT_/**/name = type + number +#endif + +/* + * This macro-mania below setups the CURLOPT_[what] enum, to be used with + * curl_easy_setopt(). The first argument in the CINIT() macro is the [what] + * word. + */ + +typedef enum { + /* This is the FILE * or void * the regular output should be written to. */ + CINIT(WRITEDATA, OBJECTPOINT, 1), + + /* The full URL to get/put */ + CINIT(URL, STRINGPOINT, 2), + + /* Port number to connect to, if other than default. */ + CINIT(PORT, LONG, 3), + + /* Name of proxy to use. */ + CINIT(PROXY, STRINGPOINT, 4), + + /* "user:password;options" to use when fetching. */ + CINIT(USERPWD, STRINGPOINT, 5), + + /* "user:password" to use with proxy. */ + CINIT(PROXYUSERPWD, STRINGPOINT, 6), + + /* Range to get, specified as an ASCII string. */ + CINIT(RANGE, STRINGPOINT, 7), + + /* not used */ + + /* Specified file stream to upload from (use as input): */ + CINIT(READDATA, OBJECTPOINT, 9), + + /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE + * bytes big. If this is not used, error messages go to stderr instead: */ + CINIT(ERRORBUFFER, OBJECTPOINT, 10), + + /* Function that will be called to store the output (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11), + + /* Function that will be called to read the input (instead of fread). The + * parameters will use fread() syntax, make sure to follow them. */ + CINIT(READFUNCTION, FUNCTIONPOINT, 12), + + /* Time-out the read operation after this amount of seconds */ + CINIT(TIMEOUT, LONG, 13), + + /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about + * how large the file being sent really is. That allows better error + * checking and better verifies that the upload was successful. -1 means + * unknown size. + * + * For large file support, there is also a _LARGE version of the key + * which takes an off_t type, allowing platforms with larger off_t + * sizes to handle larger files. See below for INFILESIZE_LARGE. + */ + CINIT(INFILESIZE, LONG, 14), + + /* POST static input fields. */ + CINIT(POSTFIELDS, OBJECTPOINT, 15), + + /* Set the referrer page (needed by some CGIs) */ + CINIT(REFERER, STRINGPOINT, 16), + + /* Set the FTP PORT string (interface name, named or numerical IP address) + Use i.e '-' to use default address. */ + CINIT(FTPPORT, STRINGPOINT, 17), + + /* Set the User-Agent string (examined by some CGIs) */ + CINIT(USERAGENT, STRINGPOINT, 18), + + /* If the download receives less than "low speed limit" bytes/second + * during "low speed time" seconds, the operations is aborted. + * You could i.e if you have a pretty high speed connection, abort if + * it is less than 2000 bytes/sec during 20 seconds. + */ + + /* Set the "low speed limit" */ + CINIT(LOW_SPEED_LIMIT, LONG, 19), + + /* Set the "low speed time" */ + CINIT(LOW_SPEED_TIME, LONG, 20), + + /* Set the continuation offset. + * + * Note there is also a _LARGE version of this key which uses + * off_t types, allowing for large file offsets on platforms which + * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. + */ + CINIT(RESUME_FROM, LONG, 21), + + /* Set cookie in request: */ + CINIT(COOKIE, STRINGPOINT, 22), + + /* This points to a linked list of headers, struct curl_slist kind. This + list is also used for RTSP (in spite of its name) */ + CINIT(HTTPHEADER, OBJECTPOINT, 23), + + /* This points to a linked list of post entries, struct curl_httppost */ + CINIT(HTTPPOST, OBJECTPOINT, 24), + + /* name of the file keeping your private SSL-certificate */ + CINIT(SSLCERT, STRINGPOINT, 25), + + /* password for the SSL or SSH private key */ + CINIT(KEYPASSWD, STRINGPOINT, 26), + + /* send TYPE parameter? */ + CINIT(CRLF, LONG, 27), + + /* send linked-list of QUOTE commands */ + CINIT(QUOTE, OBJECTPOINT, 28), + + /* send FILE * or void * to store headers to, if you use a callback it + is simply passed to the callback unmodified */ + CINIT(HEADERDATA, OBJECTPOINT, 29), + + /* point to a file to read the initial cookies from, also enables + "cookie awareness" */ + CINIT(COOKIEFILE, STRINGPOINT, 31), + + /* What version to specifically try to use. + See CURL_SSLVERSION defines below. */ + CINIT(SSLVERSION, LONG, 32), + + /* What kind of HTTP time condition to use, see defines */ + CINIT(TIMECONDITION, LONG, 33), + + /* Time to use with the above condition. Specified in number of seconds + since 1 Jan 1970 */ + CINIT(TIMEVALUE, LONG, 34), + + /* 35 = OBSOLETE */ + + /* Custom request, for customizing the get command like + HTTP: DELETE, TRACE and others + FTP: to use a different list command + */ + CINIT(CUSTOMREQUEST, STRINGPOINT, 36), + + /* FILE handle to use instead of stderr */ + CINIT(STDERR, OBJECTPOINT, 37), + + /* 38 is not used */ + + /* send linked-list of post-transfer QUOTE commands */ + CINIT(POSTQUOTE, OBJECTPOINT, 39), + + CINIT(OBSOLETE40, OBJECTPOINT, 40), /* OBSOLETE, do not use! */ + + CINIT(VERBOSE, LONG, 41), /* talk a lot */ + CINIT(HEADER, LONG, 42), /* throw the header out too */ + CINIT(NOPROGRESS, LONG, 43), /* shut off the progress meter */ + CINIT(NOBODY, LONG, 44), /* use HEAD to get http document */ + CINIT(FAILONERROR, LONG, 45), /* no output on http error codes >= 400 */ + CINIT(UPLOAD, LONG, 46), /* this is an upload */ + CINIT(POST, LONG, 47), /* HTTP POST method */ + CINIT(DIRLISTONLY, LONG, 48), /* bare names when listing directories */ + + CINIT(APPEND, LONG, 50), /* Append instead of overwrite on upload! */ + + /* Specify whether to read the user+password from the .netrc or the URL. + * This must be one of the CURL_NETRC_* enums below. */ + CINIT(NETRC, LONG, 51), + + CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */ + + CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */ + CINIT(PUT, LONG, 54), /* HTTP PUT */ + + /* 55 = OBSOLETE */ + + /* DEPRECATED + * Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_progress_callback + * prototype defines. */ + CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56), + + /* Data passed to the CURLOPT_PROGRESSFUNCTION and CURLOPT_XFERINFOFUNCTION + callbacks */ + CINIT(PROGRESSDATA, OBJECTPOINT, 57), +#define CURLOPT_XFERINFODATA CURLOPT_PROGRESSDATA + + /* We want the referrer field set automatically when following locations */ + CINIT(AUTOREFERER, LONG, 58), + + /* Port of the proxy, can be set in the proxy string as well with: + "[host]:[port]" */ + CINIT(PROXYPORT, LONG, 59), + + /* size of the POST input data, if strlen() is not good to use */ + CINIT(POSTFIELDSIZE, LONG, 60), + + /* tunnel non-http operations through a HTTP proxy */ + CINIT(HTTPPROXYTUNNEL, LONG, 61), + + /* Set the interface string to use as outgoing network interface */ + CINIT(INTERFACE, STRINGPOINT, 62), + + /* Set the krb4/5 security level, this also enables krb4/5 awareness. This + * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string + * is set but doesn't match one of these, 'private' will be used. */ + CINIT(KRBLEVEL, STRINGPOINT, 63), + + /* Set if we should verify the peer in ssl handshake, set 1 to verify. */ + CINIT(SSL_VERIFYPEER, LONG, 64), + + /* The CApath or CAfile used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAINFO, STRINGPOINT, 65), + + /* 66 = OBSOLETE */ + /* 67 = OBSOLETE */ + + /* Maximum number of http redirects to follow */ + CINIT(MAXREDIRS, LONG, 68), + + /* Pass a long set to 1 to get the date of the requested document (if + possible)! Pass a zero to shut it off. */ + CINIT(FILETIME, LONG, 69), + + /* This points to a linked list of telnet options */ + CINIT(TELNETOPTIONS, OBJECTPOINT, 70), + + /* Max amount of cached alive connections */ + CINIT(MAXCONNECTS, LONG, 71), + + CINIT(OBSOLETE72, LONG, 72), /* OBSOLETE, do not use! */ + + /* 73 = OBSOLETE */ + + /* Set to explicitly use a new connection for the upcoming transfer. + Do not use this unless you're absolutely sure of this, as it makes the + operation slower and is less friendly for the network. */ + CINIT(FRESH_CONNECT, LONG, 74), + + /* Set to explicitly forbid the upcoming transfer's connection to be re-used + when done. Do not use this unless you're absolutely sure of this, as it + makes the operation slower and is less friendly for the network. */ + CINIT(FORBID_REUSE, LONG, 75), + + /* Set to a file name that contains random data for libcurl to use to + seed the random engine when doing SSL connects. */ + CINIT(RANDOM_FILE, STRINGPOINT, 76), + + /* Set to the Entropy Gathering Daemon socket pathname */ + CINIT(EGDSOCKET, STRINGPOINT, 77), + + /* Time-out connect operations after this amount of seconds, if connects are + OK within this time, then fine... This only aborts the connect phase. */ + CINIT(CONNECTTIMEOUT, LONG, 78), + + /* Function that will be called to store headers (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79), + + /* Set this to force the HTTP request to get back to GET. Only really usable + if POST, PUT or a custom request have been used first. + */ + CINIT(HTTPGET, LONG, 80), + + /* Set if we should verify the Common name from the peer certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches the + * provided hostname. */ + CINIT(SSL_VERIFYHOST, LONG, 81), + + /* Specify which file name to write all known cookies in after completed + operation. Set file name to "-" (dash) to make it go to stdout. */ + CINIT(COOKIEJAR, STRINGPOINT, 82), + + /* Specify which SSL ciphers to use */ + CINIT(SSL_CIPHER_LIST, STRINGPOINT, 83), + + /* Specify which HTTP version to use! This must be set to one of the + CURL_HTTP_VERSION* enums set below. */ + CINIT(HTTP_VERSION, LONG, 84), + + /* Specifically switch on or off the FTP engine's use of the EPSV command. By + default, that one will always be attempted before the more traditional + PASV command. */ + CINIT(FTP_USE_EPSV, LONG, 85), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ + CINIT(SSLCERTTYPE, STRINGPOINT, 86), + + /* name of the file keeping your private SSL-key */ + CINIT(SSLKEY, STRINGPOINT, 87), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ + CINIT(SSLKEYTYPE, STRINGPOINT, 88), + + /* crypto engine for the SSL-sub system */ + CINIT(SSLENGINE, STRINGPOINT, 89), + + /* set the crypto engine for the SSL-sub system as default + the param has no meaning... + */ + CINIT(SSLENGINE_DEFAULT, LONG, 90), + + /* Non-zero value means to use the global dns cache */ + CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* DEPRECATED, do not use! */ + + /* DNS cache timeout */ + CINIT(DNS_CACHE_TIMEOUT, LONG, 92), + + /* send linked-list of pre-transfer QUOTE commands */ + CINIT(PREQUOTE, OBJECTPOINT, 93), + + /* set the debug function */ + CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94), + + /* set the data for the debug function */ + CINIT(DEBUGDATA, OBJECTPOINT, 95), + + /* mark this as start of a cookie session */ + CINIT(COOKIESESSION, LONG, 96), + + /* The CApath directory used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAPATH, STRINGPOINT, 97), + + /* Instruct libcurl to use a smaller receive buffer */ + CINIT(BUFFERSIZE, LONG, 98), + + /* Instruct libcurl to not use any signal/alarm handlers, even when using + timeouts. This option is useful for multi-threaded applications. + See libcurl-the-guide for more background information. */ + CINIT(NOSIGNAL, LONG, 99), + + /* Provide a CURLShare for mutexing non-ts data */ + CINIT(SHARE, OBJECTPOINT, 100), + + /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default), + CURLPROXY_HTTPS, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and + CURLPROXY_SOCKS5. */ + CINIT(PROXYTYPE, LONG, 101), + + /* Set the Accept-Encoding string. Use this to tell a server you would like + the response to be compressed. Before 7.21.6, this was known as + CURLOPT_ENCODING */ + CINIT(ACCEPT_ENCODING, STRINGPOINT, 102), + + /* Set pointer to private data */ + CINIT(PRIVATE, OBJECTPOINT, 103), + + /* Set aliases for HTTP 200 in the HTTP Response header */ + CINIT(HTTP200ALIASES, OBJECTPOINT, 104), + + /* Continue to send authentication (user+password) when following locations, + even when hostname changed. This can potentially send off the name + and password to whatever host the server decides. */ + CINIT(UNRESTRICTED_AUTH, LONG, 105), + + /* Specifically switch on or off the FTP engine's use of the EPRT command ( + it also disables the LPRT attempt). By default, those ones will always be + attempted before the good old traditional PORT command. */ + CINIT(FTP_USE_EPRT, LONG, 106), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_USERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(HTTPAUTH, LONG, 107), + + /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx + in second argument. The function must be matching the + curl_ssl_ctx_callback proto. */ + CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108), + + /* Set the userdata for the ssl context callback function's third + argument */ + CINIT(SSL_CTX_DATA, OBJECTPOINT, 109), + + /* FTP Option that causes missing dirs to be created on the remote server. + In 7.19.4 we introduced the convenience enums for this option using the + CURLFTP_CREATE_DIR prefix. + */ + CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(PROXYAUTH, LONG, 111), + + /* FTP option that changes the timeout, in seconds, associated with + getting a response. This is different from transfer timeout time and + essentially places a demand on the FTP server to acknowledge commands + in a timely manner. */ + CINIT(FTP_RESPONSE_TIMEOUT, LONG, 112), +#define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT + + /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to + tell libcurl to resolve names to those IP versions only. This only has + affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */ + CINIT(IPRESOLVE, LONG, 113), + + /* Set this option to limit the size of a file that will be downloaded from + an HTTP or FTP server. + + Note there is also _LARGE version which adds large file support for + platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ + CINIT(MAXFILESIZE, LONG, 114), + + /* See the comment for INFILESIZE above, but in short, specifies + * the size of the file being uploaded. -1 means unknown. + */ + CINIT(INFILESIZE_LARGE, OFF_T, 115), + + /* Sets the continuation offset. There is also a LONG version of this; + * look above for RESUME_FROM. + */ + CINIT(RESUME_FROM_LARGE, OFF_T, 116), + + /* Sets the maximum size of data that will be downloaded from + * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. + */ + CINIT(MAXFILESIZE_LARGE, OFF_T, 117), + + /* Set this option to the file name of your .netrc file you want libcurl + to parse (using the CURLOPT_NETRC option). If not set, libcurl will do + a poor attempt to find the user's home directory and check for a .netrc + file in there. */ + CINIT(NETRC_FILE, STRINGPOINT, 118), + + /* Enable SSL/TLS for FTP, pick one of: + CURLUSESSL_TRY - try using SSL, proceed anyway otherwise + CURLUSESSL_CONTROL - SSL for the control connection or fail + CURLUSESSL_ALL - SSL for all communication or fail + */ + CINIT(USE_SSL, LONG, 119), + + /* The _LARGE version of the standard POSTFIELDSIZE option */ + CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120), + + /* Enable/disable the TCP Nagle algorithm */ + CINIT(TCP_NODELAY, LONG, 121), + + /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 123 OBSOLETE. Gone in 7.16.0 */ + /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 127 OBSOLETE. Gone in 7.16.0 */ + /* 128 OBSOLETE. Gone in 7.16.0 */ + + /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option + can be used to change libcurl's default action which is to first try + "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK + response has been received. + + Available parameters are: + CURLFTPAUTH_DEFAULT - let libcurl decide + CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS + CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL + */ + CINIT(FTPSSLAUTH, LONG, 129), + + CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130), + CINIT(IOCTLDATA, OBJECTPOINT, 131), + + /* 132 OBSOLETE. Gone in 7.16.0 */ + /* 133 OBSOLETE. Gone in 7.16.0 */ + + /* zero terminated string for pass on to the FTP server when asked for + "account" info */ + CINIT(FTP_ACCOUNT, STRINGPOINT, 134), + + /* feed cookie into cookie engine */ + CINIT(COOKIELIST, STRINGPOINT, 135), + + /* ignore Content-Length */ + CINIT(IGNORE_CONTENT_LENGTH, LONG, 136), + + /* Set to non-zero to skip the IP address received in a 227 PASV FTP server + response. Typically used for FTP-SSL purposes but is not restricted to + that. libcurl will then instead use the same IP address it used for the + control connection. */ + CINIT(FTP_SKIP_PASV_IP, LONG, 137), + + /* Select "file method" to use when doing FTP, see the curl_ftpmethod + above. */ + CINIT(FTP_FILEMETHOD, LONG, 138), + + /* Local port number to bind the socket to */ + CINIT(LOCALPORT, LONG, 139), + + /* Number of ports to try, including the first one set with LOCALPORT. + Thus, setting it to 1 will make no additional attempts but the first. + */ + CINIT(LOCALPORTRANGE, LONG, 140), + + /* no transfer, set up connection and let application use the socket by + extracting it with CURLINFO_LASTSOCKET */ + CINIT(CONNECT_ONLY, LONG, 141), + + /* Function that will be called to convert from the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142), + + /* Function that will be called to convert to the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143), + + /* Function that will be called to convert from UTF8 + (instead of using the iconv calls in libcurl) + Note that this is used only for SSL certificate processing */ + CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144), + + /* if the connection proceeds too quickly then need to slow it down */ + /* limit-rate: maximum number of bytes per second to send or receive */ + CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145), + CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146), + + /* Pointer to command string to send if USER/PASS fails. */ + CINIT(FTP_ALTERNATIVE_TO_USER, STRINGPOINT, 147), + + /* callback function for setting socket options */ + CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148), + CINIT(SOCKOPTDATA, OBJECTPOINT, 149), + + /* set to 0 to disable session ID re-use for this transfer, default is + enabled (== 1) */ + CINIT(SSL_SESSIONID_CACHE, LONG, 150), + + /* allowed SSH authentication methods */ + CINIT(SSH_AUTH_TYPES, LONG, 151), + + /* Used by scp/sftp to do public/private key authentication */ + CINIT(SSH_PUBLIC_KEYFILE, STRINGPOINT, 152), + CINIT(SSH_PRIVATE_KEYFILE, STRINGPOINT, 153), + + /* Send CCC (Clear Command Channel) after authentication */ + CINIT(FTP_SSL_CCC, LONG, 154), + + /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ + CINIT(TIMEOUT_MS, LONG, 155), + CINIT(CONNECTTIMEOUT_MS, LONG, 156), + + /* set to zero to disable the libcurl's decoding and thus pass the raw body + data to the application even when it is encoded/compressed */ + CINIT(HTTP_TRANSFER_DECODING, LONG, 157), + CINIT(HTTP_CONTENT_DECODING, LONG, 158), + + /* Permission used when creating new files and directories on the remote + server for protocols that support it, SFTP/SCP/FILE */ + CINIT(NEW_FILE_PERMS, LONG, 159), + CINIT(NEW_DIRECTORY_PERMS, LONG, 160), + + /* Set the behaviour of POST when redirecting. Values must be set to one + of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ + CINIT(POSTREDIR, LONG, 161), + + /* used by scp/sftp to verify the host's public key */ + CINIT(SSH_HOST_PUBLIC_KEY_MD5, STRINGPOINT, 162), + + /* Callback function for opening socket (instead of socket(2)). Optionally, + callback is able change the address or refuse to connect returning + CURL_SOCKET_BAD. The callback should have type + curl_opensocket_callback */ + CINIT(OPENSOCKETFUNCTION, FUNCTIONPOINT, 163), + CINIT(OPENSOCKETDATA, OBJECTPOINT, 164), + + /* POST volatile input fields. */ + CINIT(COPYPOSTFIELDS, OBJECTPOINT, 165), + + /* set transfer mode (;type=) when doing FTP via an HTTP proxy */ + CINIT(PROXY_TRANSFER_MODE, LONG, 166), + + /* Callback function for seeking in the input stream */ + CINIT(SEEKFUNCTION, FUNCTIONPOINT, 167), + CINIT(SEEKDATA, OBJECTPOINT, 168), + + /* CRL file */ + CINIT(CRLFILE, STRINGPOINT, 169), + + /* Issuer certificate */ + CINIT(ISSUERCERT, STRINGPOINT, 170), + + /* (IPv6) Address scope */ + CINIT(ADDRESS_SCOPE, LONG, 171), + + /* Collect certificate chain info and allow it to get retrievable with + CURLINFO_CERTINFO after the transfer is complete. */ + CINIT(CERTINFO, LONG, 172), + + /* "name" and "pwd" to use when fetching. */ + CINIT(USERNAME, STRINGPOINT, 173), + CINIT(PASSWORD, STRINGPOINT, 174), + + /* "name" and "pwd" to use with Proxy when fetching. */ + CINIT(PROXYUSERNAME, STRINGPOINT, 175), + CINIT(PROXYPASSWORD, STRINGPOINT, 176), + + /* Comma separated list of hostnames defining no-proxy zones. These should + match both hostnames directly, and hostnames within a domain. For + example, local.com will match local.com and www.local.com, but NOT + notlocal.com or www.notlocal.com. For compatibility with other + implementations of this, .local.com will be considered to be the same as + local.com. A single * is the only valid wildcard, and effectively + disables the use of proxy. */ + CINIT(NOPROXY, STRINGPOINT, 177), + + /* block size for TFTP transfers */ + CINIT(TFTP_BLKSIZE, LONG, 178), + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_SERVICE, STRINGPOINT, 179), /* DEPRECATED, do not use! */ + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_NEC, LONG, 180), + + /* set the bitmask for the protocols that are allowed to be used for the + transfer, which thus helps the app which takes URLs from users or other + external inputs and want to restrict what protocol(s) to deal + with. Defaults to CURLPROTO_ALL. */ + CINIT(PROTOCOLS, LONG, 181), + + /* set the bitmask for the protocols that libcurl is allowed to follow to, + as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs + to be set in both bitmasks to be allowed to get redirected to. Defaults + to all protocols except FILE and SCP. */ + CINIT(REDIR_PROTOCOLS, LONG, 182), + + /* set the SSH knownhost file name to use */ + CINIT(SSH_KNOWNHOSTS, STRINGPOINT, 183), + + /* set the SSH host key callback, must point to a curl_sshkeycallback + function */ + CINIT(SSH_KEYFUNCTION, FUNCTIONPOINT, 184), + + /* set the SSH host key callback custom pointer */ + CINIT(SSH_KEYDATA, OBJECTPOINT, 185), + + /* set the SMTP mail originator */ + CINIT(MAIL_FROM, STRINGPOINT, 186), + + /* set the list of SMTP mail receiver(s) */ + CINIT(MAIL_RCPT, OBJECTPOINT, 187), + + /* FTP: send PRET before PASV */ + CINIT(FTP_USE_PRET, LONG, 188), + + /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ + CINIT(RTSP_REQUEST, LONG, 189), + + /* The RTSP session identifier */ + CINIT(RTSP_SESSION_ID, STRINGPOINT, 190), + + /* The RTSP stream URI */ + CINIT(RTSP_STREAM_URI, STRINGPOINT, 191), + + /* The Transport: header to use in RTSP requests */ + CINIT(RTSP_TRANSPORT, STRINGPOINT, 192), + + /* Manually initialize the client RTSP CSeq for this handle */ + CINIT(RTSP_CLIENT_CSEQ, LONG, 193), + + /* Manually initialize the server RTSP CSeq for this handle */ + CINIT(RTSP_SERVER_CSEQ, LONG, 194), + + /* The stream to pass to INTERLEAVEFUNCTION. */ + CINIT(INTERLEAVEDATA, OBJECTPOINT, 195), + + /* Let the application define a custom write method for RTP data */ + CINIT(INTERLEAVEFUNCTION, FUNCTIONPOINT, 196), + + /* Turn on wildcard matching */ + CINIT(WILDCARDMATCH, LONG, 197), + + /* Directory matching callback called before downloading of an + individual file (chunk) started */ + CINIT(CHUNK_BGN_FUNCTION, FUNCTIONPOINT, 198), + + /* Directory matching callback called after the file (chunk) + was downloaded, or skipped */ + CINIT(CHUNK_END_FUNCTION, FUNCTIONPOINT, 199), + + /* Change match (fnmatch-like) callback for wildcard matching */ + CINIT(FNMATCH_FUNCTION, FUNCTIONPOINT, 200), + + /* Let the application define custom chunk data pointer */ + CINIT(CHUNK_DATA, OBJECTPOINT, 201), + + /* FNMATCH_FUNCTION user pointer */ + CINIT(FNMATCH_DATA, OBJECTPOINT, 202), + + /* send linked-list of name:port:address sets */ + CINIT(RESOLVE, OBJECTPOINT, 203), + + /* Set a username for authenticated TLS */ + CINIT(TLSAUTH_USERNAME, STRINGPOINT, 204), + + /* Set a password for authenticated TLS */ + CINIT(TLSAUTH_PASSWORD, STRINGPOINT, 205), + + /* Set authentication type for authenticated TLS */ + CINIT(TLSAUTH_TYPE, STRINGPOINT, 206), + + /* Set to 1 to enable the "TE:" header in HTTP requests to ask for + compressed transfer-encoded responses. Set to 0 to disable the use of TE: + in outgoing requests. The current default is 0, but it might change in a + future libcurl release. + + libcurl will ask for the compressed methods it knows of, and if that + isn't any, it will not ask for transfer-encoding at all even if this + option is set to 1. + + */ + CINIT(TRANSFER_ENCODING, LONG, 207), + + /* Callback function for closing socket (instead of close(2)). The callback + should have type curl_closesocket_callback */ + CINIT(CLOSESOCKETFUNCTION, FUNCTIONPOINT, 208), + CINIT(CLOSESOCKETDATA, OBJECTPOINT, 209), + + /* allow GSSAPI credential delegation */ + CINIT(GSSAPI_DELEGATION, LONG, 210), + + /* Set the name servers to use for DNS resolution */ + CINIT(DNS_SERVERS, STRINGPOINT, 211), + + /* Time-out accept operations (currently for FTP only) after this amount + of milliseconds. */ + CINIT(ACCEPTTIMEOUT_MS, LONG, 212), + + /* Set TCP keepalive */ + CINIT(TCP_KEEPALIVE, LONG, 213), + + /* non-universal keepalive knobs (Linux, AIX, HP-UX, more) */ + CINIT(TCP_KEEPIDLE, LONG, 214), + CINIT(TCP_KEEPINTVL, LONG, 215), + + /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */ + CINIT(SSL_OPTIONS, LONG, 216), + + /* Set the SMTP auth originator */ + CINIT(MAIL_AUTH, STRINGPOINT, 217), + + /* Enable/disable SASL initial response */ + CINIT(SASL_IR, LONG, 218), + + /* Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_xferinfo_callback + * prototype defines. (Deprecates CURLOPT_PROGRESSFUNCTION) */ + CINIT(XFERINFOFUNCTION, FUNCTIONPOINT, 219), + + /* The XOAUTH2 bearer token */ + CINIT(XOAUTH2_BEARER, STRINGPOINT, 220), + + /* Set the interface string to use as outgoing network + * interface for DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_INTERFACE, STRINGPOINT, 221), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_LOCAL_IP4, STRINGPOINT, 222), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_LOCAL_IP6, STRINGPOINT, 223), + + /* Set authentication options directly */ + CINIT(LOGIN_OPTIONS, STRINGPOINT, 224), + + /* Enable/disable TLS NPN extension (http2 over ssl might fail without) */ + CINIT(SSL_ENABLE_NPN, LONG, 225), + + /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */ + CINIT(SSL_ENABLE_ALPN, LONG, 226), + + /* Time to wait for a response to a HTTP request containing an + * Expect: 100-continue header before sending the data anyway. */ + CINIT(EXPECT_100_TIMEOUT_MS, LONG, 227), + + /* This points to a linked list of headers used for proxy requests only, + struct curl_slist kind */ + CINIT(PROXYHEADER, OBJECTPOINT, 228), + + /* Pass in a bitmask of "header options" */ + CINIT(HEADEROPT, LONG, 229), + + /* The public key in DER form used to validate the peer public key + this option is used only if SSL_VERIFYPEER is true */ + CINIT(PINNEDPUBLICKEY, STRINGPOINT, 230), + + /* Path to Unix domain socket */ + CINIT(UNIX_SOCKET_PATH, STRINGPOINT, 231), + + /* Set if we should verify the certificate status. */ + CINIT(SSL_VERIFYSTATUS, LONG, 232), + + /* Set if we should enable TLS false start. */ + CINIT(SSL_FALSESTART, LONG, 233), + + /* Do not squash dot-dot sequences */ + CINIT(PATH_AS_IS, LONG, 234), + + /* Proxy Service Name */ + CINIT(PROXY_SERVICE_NAME, STRINGPOINT, 235), + + /* Service Name */ + CINIT(SERVICE_NAME, STRINGPOINT, 236), + + /* Wait/don't wait for pipe/mutex to clarify */ + CINIT(PIPEWAIT, LONG, 237), + + /* Set the protocol used when curl is given a URL without a protocol */ + CINIT(DEFAULT_PROTOCOL, STRINGPOINT, 238), + + /* Set stream weight, 1 - 256 (default is 16) */ + CINIT(STREAM_WEIGHT, LONG, 239), + + /* Set stream dependency on another CURL handle */ + CINIT(STREAM_DEPENDS, OBJECTPOINT, 240), + + /* Set E-xclusive stream dependency on another CURL handle */ + CINIT(STREAM_DEPENDS_E, OBJECTPOINT, 241), + + /* Do not send any tftp option requests to the server */ + CINIT(TFTP_NO_OPTIONS, LONG, 242), + + /* Linked-list of host:port:connect-to-host:connect-to-port, + overrides the URL's host:port (only for the network layer) */ + CINIT(CONNECT_TO, OBJECTPOINT, 243), + + /* Set TCP Fast Open */ + CINIT(TCP_FASTOPEN, LONG, 244), + + /* Continue to send data if the server responds early with an + * HTTP status code >= 300 */ + CINIT(KEEP_SENDING_ON_ERROR, LONG, 245), + + /* The CApath or CAfile used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CINIT(PROXY_CAINFO, STRINGPOINT, 246), + + /* The CApath directory used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CINIT(PROXY_CAPATH, STRINGPOINT, 247), + + /* Set if we should verify the proxy in ssl handshake, + set 1 to verify. */ + CINIT(PROXY_SSL_VERIFYPEER, LONG, 248), + + /* Set if we should verify the Common name from the proxy certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches + * the provided hostname. */ + CINIT(PROXY_SSL_VERIFYHOST, LONG, 249), + + /* What version to specifically try to use for proxy. + See CURL_SSLVERSION defines below. */ + CINIT(PROXY_SSLVERSION, LONG, 250), + + /* Set a username for authenticated TLS for proxy */ + CINIT(PROXY_TLSAUTH_USERNAME, STRINGPOINT, 251), + + /* Set a password for authenticated TLS for proxy */ + CINIT(PROXY_TLSAUTH_PASSWORD, STRINGPOINT, 252), + + /* Set authentication type for authenticated TLS for proxy */ + CINIT(PROXY_TLSAUTH_TYPE, STRINGPOINT, 253), + + /* name of the file keeping your private SSL-certificate for proxy */ + CINIT(PROXY_SSLCERT, STRINGPOINT, 254), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") for + proxy */ + CINIT(PROXY_SSLCERTTYPE, STRINGPOINT, 255), + + /* name of the file keeping your private SSL-key for proxy */ + CINIT(PROXY_SSLKEY, STRINGPOINT, 256), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") for + proxy */ + CINIT(PROXY_SSLKEYTYPE, STRINGPOINT, 257), + + /* password for the SSL private key for proxy */ + CINIT(PROXY_KEYPASSWD, STRINGPOINT, 258), + + /* Specify which SSL ciphers to use for proxy */ + CINIT(PROXY_SSL_CIPHER_LIST, STRINGPOINT, 259), + + /* CRL file for proxy */ + CINIT(PROXY_CRLFILE, STRINGPOINT, 260), + + /* Enable/disable specific SSL features with a bitmask for proxy, see + CURLSSLOPT_* */ + CINIT(PROXY_SSL_OPTIONS, LONG, 261), + + /* Name of pre proxy to use. */ + CINIT(PRE_PROXY, STRINGPOINT, 262), + + /* The public key in DER form used to validate the proxy public key + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CINIT(PROXY_PINNEDPUBLICKEY, STRINGPOINT, 263), + + /* Path to an abstract Unix domain socket */ + CINIT(ABSTRACT_UNIX_SOCKET, STRINGPOINT, 264), + + /* Suppress proxy CONNECT response headers from user callbacks */ + CINIT(SUPPRESS_CONNECT_HEADERS, LONG, 265), + + CURLOPT_LASTENTRY /* the last unused */ +} CURLoption; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2011 */ + +/* This was added in version 7.19.1 */ +#define CURLOPT_POST301 CURLOPT_POSTREDIR + +/* These are scheduled to disappear by 2009 */ + +/* The following were added in 7.17.0 */ +#define CURLOPT_SSLKEYPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_FTPAPPEND CURLOPT_APPEND +#define CURLOPT_FTPLISTONLY CURLOPT_DIRLISTONLY +#define CURLOPT_FTP_SSL CURLOPT_USE_SSL + +/* The following were added earlier */ + +#define CURLOPT_SSLCERTPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_KRB4LEVEL CURLOPT_KRBLEVEL + +#else +/* This is set if CURL_NO_OLDIES is defined at compile-time */ +#undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ +#endif + + + /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ +#define CURL_IPRESOLVE_WHATEVER 0 /* default, resolves addresses to all IP + versions that your system allows */ +#define CURL_IPRESOLVE_V4 1 /* resolve to IPv4 addresses */ +#define CURL_IPRESOLVE_V6 2 /* resolve to IPv6 addresses */ + + /* three convenient "aliases" that follow the name scheme better */ +#define CURLOPT_RTSPHEADER CURLOPT_HTTPHEADER + + /* These enums are for use with the CURLOPT_HTTP_VERSION option. */ +enum { + CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd + like the library to choose the best possible + for us! */ + CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */ + CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */ + CURL_HTTP_VERSION_2_0, /* please use HTTP 2 in the request */ + CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */ + CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1 + Upgrade */ + + CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ +}; + +/* Convenience definition simple because the name of the version is HTTP/2 and + not 2.0. The 2_0 version of the enum name was set while the version was + still planned to be 2.0 and we stick to it for compatibility. */ +#define CURL_HTTP_VERSION_2 CURL_HTTP_VERSION_2_0 + +/* + * Public API enums for RTSP requests + */ +enum { + CURL_RTSPREQ_NONE, /* first in list */ + CURL_RTSPREQ_OPTIONS, + CURL_RTSPREQ_DESCRIBE, + CURL_RTSPREQ_ANNOUNCE, + CURL_RTSPREQ_SETUP, + CURL_RTSPREQ_PLAY, + CURL_RTSPREQ_PAUSE, + CURL_RTSPREQ_TEARDOWN, + CURL_RTSPREQ_GET_PARAMETER, + CURL_RTSPREQ_SET_PARAMETER, + CURL_RTSPREQ_RECORD, + CURL_RTSPREQ_RECEIVE, + CURL_RTSPREQ_LAST /* last in list */ +}; + + /* These enums are for use with the CURLOPT_NETRC option. */ +enum CURL_NETRC_OPTION { + CURL_NETRC_IGNORED, /* The .netrc will never be read. + * This is the default. */ + CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred + * to one in the .netrc. */ + CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. + * Unless one is set programmatically, the .netrc + * will be queried. */ + CURL_NETRC_LAST +}; + +enum { + CURL_SSLVERSION_DEFAULT, + CURL_SSLVERSION_TLSv1, /* TLS 1.x */ + CURL_SSLVERSION_SSLv2, + CURL_SSLVERSION_SSLv3, + CURL_SSLVERSION_TLSv1_0, + CURL_SSLVERSION_TLSv1_1, + CURL_SSLVERSION_TLSv1_2, + CURL_SSLVERSION_TLSv1_3, + + CURL_SSLVERSION_LAST /* never use, keep last */ +}; + +enum { + CURL_SSLVERSION_MAX_NONE = 0, + CURL_SSLVERSION_MAX_DEFAULT = (CURL_SSLVERSION_TLSv1 << 16), + CURL_SSLVERSION_MAX_TLSv1_0 = (CURL_SSLVERSION_TLSv1_0 << 16), + CURL_SSLVERSION_MAX_TLSv1_1 = (CURL_SSLVERSION_TLSv1_1 << 16), + CURL_SSLVERSION_MAX_TLSv1_2 = (CURL_SSLVERSION_TLSv1_2 << 16), + CURL_SSLVERSION_MAX_TLSv1_3 = (CURL_SSLVERSION_TLSv1_3 << 16), + + /* never use, keep last */ + CURL_SSLVERSION_MAX_LAST = (CURL_SSLVERSION_LAST << 16) +}; + +enum CURL_TLSAUTH { + CURL_TLSAUTH_NONE, + CURL_TLSAUTH_SRP, + CURL_TLSAUTH_LAST /* never use, keep last */ +}; + +/* symbols to use with CURLOPT_POSTREDIR. + CURL_REDIR_POST_301, CURL_REDIR_POST_302 and CURL_REDIR_POST_303 + can be bitwise ORed so that CURL_REDIR_POST_301 | CURL_REDIR_POST_302 + | CURL_REDIR_POST_303 == CURL_REDIR_POST_ALL */ + +#define CURL_REDIR_GET_ALL 0 +#define CURL_REDIR_POST_301 1 +#define CURL_REDIR_POST_302 2 +#define CURL_REDIR_POST_303 4 +#define CURL_REDIR_POST_ALL \ + (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) + +typedef enum { + CURL_TIMECOND_NONE, + + CURL_TIMECOND_IFMODSINCE, + CURL_TIMECOND_IFUNMODSINCE, + CURL_TIMECOND_LASTMOD, + + CURL_TIMECOND_LAST +} curl_TimeCond; + + +/* curl_strequal() and curl_strnequal() are subject for removal in a future + libcurl, see lib/README.curlx for details + + !checksrc! disable SPACEBEFOREPAREN 2 +*/ +CURL_EXTERN int (curl_strequal)(const char *s1, const char *s2); +CURL_EXTERN int (curl_strnequal)(const char *s1, const char *s2, size_t n); + +/* name is uppercase CURLFORM_ */ +#ifdef CFINIT +#undef CFINIT +#endif + +#ifdef CURL_ISOCPP +#define CFINIT(name) CURLFORM_ ## name +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define CFINIT(name) CURLFORM_/**/name +#endif + +typedef enum { + CFINIT(NOTHING), /********* the first one is unused ************/ + + /* */ + CFINIT(COPYNAME), + CFINIT(PTRNAME), + CFINIT(NAMELENGTH), + CFINIT(COPYCONTENTS), + CFINIT(PTRCONTENTS), + CFINIT(CONTENTSLENGTH), + CFINIT(FILECONTENT), + CFINIT(ARRAY), + CFINIT(OBSOLETE), + CFINIT(FILE), + + CFINIT(BUFFER), + CFINIT(BUFFERPTR), + CFINIT(BUFFERLENGTH), + + CFINIT(CONTENTTYPE), + CFINIT(CONTENTHEADER), + CFINIT(FILENAME), + CFINIT(END), + CFINIT(OBSOLETE2), + + CFINIT(STREAM), + CFINIT(CONTENTLEN), /* added in 7.46.0, provide a curl_off_t length */ + + CURLFORM_LASTENTRY /* the last unused */ +} CURLformoption; + +#undef CFINIT /* done */ + +/* structure to be used as parameter for CURLFORM_ARRAY */ +struct curl_forms { + CURLformoption option; + const char *value; +}; + +/* use this for multipart formpost building */ +/* Returns code for curl_formadd() + * + * Returns: + * CURL_FORMADD_OK on success + * CURL_FORMADD_MEMORY if the FormInfo allocation fails + * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form + * CURL_FORMADD_NULL if a null pointer was given for a char + * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed + * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used + * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) + * CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated + * CURL_FORMADD_MEMORY if some allocation for string copying failed. + * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array + * + ***************************************************************************/ +typedef enum { + CURL_FORMADD_OK, /* first, no error */ + + CURL_FORMADD_MEMORY, + CURL_FORMADD_OPTION_TWICE, + CURL_FORMADD_NULL, + CURL_FORMADD_UNKNOWN_OPTION, + CURL_FORMADD_INCOMPLETE, + CURL_FORMADD_ILLEGAL_ARRAY, + CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */ + + CURL_FORMADD_LAST /* last */ +} CURLFORMcode; + +/* + * NAME curl_formadd() + * + * DESCRIPTION + * + * Pretty advanced function for building multi-part formposts. Each invoke + * adds one part that together construct a full post. Then use + * CURLOPT_HTTPPOST to send it off to libcurl. + */ +CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, + struct curl_httppost **last_post, + ...); + +/* + * callback function for curl_formget() + * The void *arg pointer will be the one passed as second argument to + * curl_formget(). + * The character buffer passed to it must not be freed. + * Should return the buffer length passed to it as the argument "len" on + * success. + */ +typedef size_t (*curl_formget_callback)(void *arg, const char *buf, + size_t len); + +/* + * NAME curl_formget() + * + * DESCRIPTION + * + * Serialize a curl_httppost struct built with curl_formadd(). + * Accepts a void pointer as second argument which will be passed to + * the curl_formget_callback function. + * Returns 0 on success. + */ +CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, + curl_formget_callback append); +/* + * NAME curl_formfree() + * + * DESCRIPTION + * + * Free a multipart formpost previously built with curl_formadd(). + */ +CURL_EXTERN void curl_formfree(struct curl_httppost *form); + +/* + * NAME curl_getenv() + * + * DESCRIPTION + * + * Returns a malloc()'ed string that MUST be curl_free()ed after usage is + * complete. DEPRECATED - see lib/README.curlx + */ +CURL_EXTERN char *curl_getenv(const char *variable); + +/* + * NAME curl_version() + * + * DESCRIPTION + * + * Returns a static ascii string of the libcurl version. + */ +CURL_EXTERN char *curl_version(void); + +/* + * NAME curl_easy_escape() + * + * DESCRIPTION + * + * Escapes URL strings (converts all letters consider illegal in URLs to their + * %XX versions). This function returns a new allocated string or NULL if an + * error occurred. + */ +CURL_EXTERN char *curl_easy_escape(CURL *handle, + const char *string, + int length); + +/* the previous version: */ +CURL_EXTERN char *curl_escape(const char *string, + int length); + + +/* + * NAME curl_easy_unescape() + * + * DESCRIPTION + * + * Unescapes URL encoding in strings (converts all %XX codes to their 8bit + * versions). This function returns a new allocated string or NULL if an error + * occurred. + * Conversion Note: On non-ASCII platforms the ASCII %XX codes are + * converted into the host encoding. + */ +CURL_EXTERN char *curl_easy_unescape(CURL *handle, + const char *string, + int length, + int *outlength); + +/* the previous version */ +CURL_EXTERN char *curl_unescape(const char *string, + int length); + +/* + * NAME curl_free() + * + * DESCRIPTION + * + * Provided for de-allocation in the same translation unit that did the + * allocation. Added in libcurl 7.10 + */ +CURL_EXTERN void curl_free(void *p); + +/* + * NAME curl_global_init() + * + * DESCRIPTION + * + * curl_global_init() should be invoked exactly once for each application that + * uses libcurl and before any call of other libcurl functions. + * + * This function is not thread-safe! + */ +CURL_EXTERN CURLcode curl_global_init(long flags); + +/* + * NAME curl_global_init_mem() + * + * DESCRIPTION + * + * curl_global_init() or curl_global_init_mem() should be invoked exactly once + * for each application that uses libcurl. This function can be used to + * initialize libcurl and set user defined memory management callback + * functions. Users can implement memory management routines to check for + * memory leaks, check for mis-use of the curl library etc. User registered + * callback routines with be invoked by this library instead of the system + * memory management routines like malloc, free etc. + */ +CURL_EXTERN CURLcode curl_global_init_mem(long flags, + curl_malloc_callback m, + curl_free_callback f, + curl_realloc_callback r, + curl_strdup_callback s, + curl_calloc_callback c); + +/* + * NAME curl_global_cleanup() + * + * DESCRIPTION + * + * curl_global_cleanup() should be invoked exactly once for each application + * that uses libcurl + */ +CURL_EXTERN void curl_global_cleanup(void); + +/* linked-list structure for the CURLOPT_QUOTE option (and other) */ +struct curl_slist { + char *data; + struct curl_slist *next; +}; + +/* + * NAME curl_slist_append() + * + * DESCRIPTION + * + * Appends a string to a linked list. If no list exists, it will be created + * first. Returns the new list, after appending. + */ +CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *, + const char *); + +/* + * NAME curl_slist_free_all() + * + * DESCRIPTION + * + * free a previously built curl_slist. + */ +CURL_EXTERN void curl_slist_free_all(struct curl_slist *); + +/* + * NAME curl_getdate() + * + * DESCRIPTION + * + * Returns the time, in seconds since 1 Jan 1970 of the time string given in + * the first argument. The time argument in the second parameter is unused + * and should be set to NULL. + */ +CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); + +/* info about the certificate chain, only for OpenSSL builds. Asked + for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ +struct curl_certinfo { + int num_of_certs; /* number of certificates with information */ + struct curl_slist **certinfo; /* for each index in this array, there's a + linked list with textual information in the + format "name: value" */ +}; + +/* enum for the different supported SSL backends */ +typedef enum { + CURLSSLBACKEND_NONE = 0, + CURLSSLBACKEND_OPENSSL = 1, + CURLSSLBACKEND_GNUTLS = 2, + CURLSSLBACKEND_NSS = 3, + CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */ + CURLSSLBACKEND_GSKIT = 5, + CURLSSLBACKEND_POLARSSL = 6, + CURLSSLBACKEND_CYASSL = 7, + CURLSSLBACKEND_SCHANNEL = 8, + CURLSSLBACKEND_DARWINSSL = 9, + CURLSSLBACKEND_AXTLS = 10, + CURLSSLBACKEND_MBEDTLS = 11 +} curl_sslbackend; + +/* aliases for library clones and renames */ +#define CURLSSLBACKEND_LIBRESSL 1 +#define CURLSSLBACKEND_BORINGSSL 1 +#define CURLSSLBACKEND_WOLFSSL 6 + +/* Information about the SSL library used and the respective internal SSL + handle, which can be used to obtain further information regarding the + connection. Asked for with CURLINFO_TLS_SSL_PTR or CURLINFO_TLS_SESSION. */ +struct curl_tlssessioninfo { + curl_sslbackend backend; + void *internals; +}; + +#define CURLINFO_STRING 0x100000 +#define CURLINFO_LONG 0x200000 +#define CURLINFO_DOUBLE 0x300000 +#define CURLINFO_SLIST 0x400000 +#define CURLINFO_SOCKET 0x500000 +#define CURLINFO_MASK 0x0fffff +#define CURLINFO_TYPEMASK 0xf00000 + +typedef enum { + CURLINFO_NONE, /* first, never use this */ + CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1, + CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, + CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3, + CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4, + CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5, + CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6, + CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7, + CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8, + CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9, + CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10, + CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11, + CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12, + CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13, + CURLINFO_FILETIME = CURLINFO_LONG + 14, + CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15, + CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16, + CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17, + CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18, + CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19, + CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20, + CURLINFO_PRIVATE = CURLINFO_STRING + 21, + CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22, + CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23, + CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24, + CURLINFO_OS_ERRNO = CURLINFO_LONG + 25, + CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26, + CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27, + CURLINFO_COOKIELIST = CURLINFO_SLIST + 28, + CURLINFO_LASTSOCKET = CURLINFO_LONG + 29, + CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30, + CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31, + CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32, + CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33, + CURLINFO_CERTINFO = CURLINFO_SLIST + 34, + CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35, + CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36, + CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37, + CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38, + CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39, + CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40, + CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, + CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, + CURLINFO_TLS_SESSION = CURLINFO_SLIST + 43, + CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44, + CURLINFO_TLS_SSL_PTR = CURLINFO_SLIST + 45, + CURLINFO_HTTP_VERSION = CURLINFO_LONG + 46, + CURLINFO_PROXY_SSL_VERIFYRESULT = CURLINFO_LONG + 47, + CURLINFO_PROTOCOL = CURLINFO_LONG + 48, + CURLINFO_SCHEME = CURLINFO_STRING + 49, + /* Fill in new entries below here! */ + + CURLINFO_LASTONE = 49 +} CURLINFO; + +/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as + CURLINFO_HTTP_CODE */ +#define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE + +typedef enum { + CURLCLOSEPOLICY_NONE, /* first, never use this */ + + CURLCLOSEPOLICY_OLDEST, + CURLCLOSEPOLICY_LEAST_RECENTLY_USED, + CURLCLOSEPOLICY_LEAST_TRAFFIC, + CURLCLOSEPOLICY_SLOWEST, + CURLCLOSEPOLICY_CALLBACK, + + CURLCLOSEPOLICY_LAST /* last, never use this */ +} curl_closepolicy; + +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_NOTHING 0 +#define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL +#define CURL_GLOBAL_ACK_EINTR (1<<2) + + +/***************************************************************************** + * Setup defines, protos etc for the sharing stuff. + */ + +/* Different data locks for a single share */ +typedef enum { + CURL_LOCK_DATA_NONE = 0, + /* CURL_LOCK_DATA_SHARE is used internally to say that + * the locking is just made to change the internal state of the share + * itself. + */ + CURL_LOCK_DATA_SHARE, + CURL_LOCK_DATA_COOKIE, + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_SSL_SESSION, + CURL_LOCK_DATA_CONNECT, + CURL_LOCK_DATA_LAST +} curl_lock_data; + +/* Different lock access types */ +typedef enum { + CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */ + CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */ + CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */ + CURL_LOCK_ACCESS_LAST /* never use */ +} curl_lock_access; + +typedef void (*curl_lock_function)(CURL *handle, + curl_lock_data data, + curl_lock_access locktype, + void *userptr); +typedef void (*curl_unlock_function)(CURL *handle, + curl_lock_data data, + void *userptr); + + +typedef enum { + CURLSHE_OK, /* all is fine */ + CURLSHE_BAD_OPTION, /* 1 */ + CURLSHE_IN_USE, /* 2 */ + CURLSHE_INVALID, /* 3 */ + CURLSHE_NOMEM, /* 4 out of memory */ + CURLSHE_NOT_BUILT_IN, /* 5 feature not present in lib */ + CURLSHE_LAST /* never use */ +} CURLSHcode; + +typedef enum { + CURLSHOPT_NONE, /* don't use */ + CURLSHOPT_SHARE, /* specify a data type to share */ + CURLSHOPT_UNSHARE, /* specify which data type to stop sharing */ + CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */ + CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */ + CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock + callback functions */ + CURLSHOPT_LAST /* never use */ +} CURLSHoption; + +CURL_EXTERN CURLSH *curl_share_init(void); +CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...); +CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *); + +/**************************************************************************** + * Structures for querying information about the curl library at runtime. + */ + +typedef enum { + CURLVERSION_FIRST, + CURLVERSION_SECOND, + CURLVERSION_THIRD, + CURLVERSION_FOURTH, + CURLVERSION_LAST /* never actually use this */ +} CURLversion; + +/* The 'CURLVERSION_NOW' is the symbolic name meant to be used by + basically all programs ever that want to get version information. It is + meant to be a built-in version number for what kind of struct the caller + expects. If the struct ever changes, we redefine the NOW to another enum + from above. */ +#define CURLVERSION_NOW CURLVERSION_FOURTH + +typedef struct { + CURLversion age; /* age of the returned struct */ + const char *version; /* LIBCURL_VERSION */ + unsigned int version_num; /* LIBCURL_VERSION_NUM */ + const char *host; /* OS/host/cpu/machine when configured */ + int features; /* bitmask, see defines below */ + const char *ssl_version; /* human readable string */ + long ssl_version_num; /* not used anymore, always 0 */ + const char *libz_version; /* human readable string */ + /* protocols is terminated by an entry with a NULL protoname */ + const char * const *protocols; + + /* The fields below this were added in CURLVERSION_SECOND */ + const char *ares; + int ares_num; + + /* This field was added in CURLVERSION_THIRD */ + const char *libidn; + + /* These field were added in CURLVERSION_FOURTH */ + + /* Same as '_libiconv_version' if built with HAVE_ICONV */ + int iconv_ver_num; + + const char *libssh_version; /* human readable string */ + +} curl_version_info_data; + +#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */ +#define CURL_VERSION_KERBEROS4 (1<<1) /* Kerberos V4 auth is supported + (deprecated) */ +#define CURL_VERSION_SSL (1<<2) /* SSL options are present */ +#define CURL_VERSION_LIBZ (1<<3) /* libz features are present */ +#define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */ +#define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth is supported + (deprecated) */ +#define CURL_VERSION_DEBUG (1<<6) /* Built with debug capabilities */ +#define CURL_VERSION_ASYNCHDNS (1<<7) /* Asynchronous DNS resolves */ +#define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth is supported */ +#define CURL_VERSION_LARGEFILE (1<<9) /* Supports files larger than 2GB */ +#define CURL_VERSION_IDN (1<<10) /* Internationized Domain Names are + supported */ +#define CURL_VERSION_SSPI (1<<11) /* Built against Windows SSPI */ +#define CURL_VERSION_CONV (1<<12) /* Character conversions supported */ +#define CURL_VERSION_CURLDEBUG (1<<13) /* Debug memory tracking supported */ +#define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */ +#define CURL_VERSION_NTLM_WB (1<<15) /* NTLM delegation to winbind helper + is supported */ +#define CURL_VERSION_HTTP2 (1<<16) /* HTTP2 support built-in */ +#define CURL_VERSION_GSSAPI (1<<17) /* Built against a GSS-API library */ +#define CURL_VERSION_KERBEROS5 (1<<18) /* Kerberos V5 auth is supported */ +#define CURL_VERSION_UNIX_SOCKETS (1<<19) /* Unix domain sockets support */ +#define CURL_VERSION_PSL (1<<20) /* Mozilla's Public Suffix List, used + for cookie domain verification */ +#define CURL_VERSION_HTTPS_PROXY (1<<21) /* HTTPS-proxy support built-in */ + + /* + * NAME curl_version_info() + * + * DESCRIPTION + * + * This function returns a pointer to a static copy of the version info + * struct. See above. + */ +CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion); + +/* + * NAME curl_easy_strerror() + * + * DESCRIPTION + * + * The curl_easy_strerror function may be used to turn a CURLcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_easy_strerror(CURLcode); + +/* + * NAME curl_share_strerror() + * + * DESCRIPTION + * + * The curl_share_strerror function may be used to turn a CURLSHcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_share_strerror(CURLSHcode); + +/* + * NAME curl_easy_pause() + * + * DESCRIPTION + * + * The curl_easy_pause function pauses or unpauses transfers. Select the new + * state by setting the bitmask, use the convenience defines below. + * + */ +CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); + +#define CURLPAUSE_RECV (1<<0) +#define CURLPAUSE_RECV_CONT (0) + +#define CURLPAUSE_SEND (1<<2) +#define CURLPAUSE_SEND_CONT (0) + +#define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) +#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) + +#ifdef __cplusplus +} +#endif + +/* unfortunately, the easy.h and multi.h include files need options and info + stuff before they can be included! */ +#include "easy.h" /* nothing in curl is fun without the easy stuff */ +#include "multi.h" + +/* the typechecker doesn't work in C++ (yet) */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \ + !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK) +#include "typecheck-gcc.h" +#else +#if defined(__STDC__) && (__STDC__ >= 1) +/* This preprocessor magic that replaces a call with the exact same call is + only done to make sure application authors pass exactly three arguments + to these functions. */ +#define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) +#define curl_easy_getinfo(handle,info,arg) curl_easy_getinfo(handle,info,arg) +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) +#endif /* __STDC__ >= 1 */ +#endif /* gcc >= 4.3 && !__cplusplus */ + +#endif /* __CURL_CURL_H */ diff --git a/compat/includes/curl/curlbuild.h b/compat/includes/curl/curlbuild.h new file mode 100644 index 0000000..ae95095 --- /dev/null +++ b/compat/includes/curl/curlbuild.h @@ -0,0 +1,586 @@ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * See file include/curl/curlbuild.h.in, run configure, and forget + * that this file exists it is only used for non-configure systems. + * But you can keep reading if you want ;-) + * + */ + +/* ================================================================ */ +/* NOTES FOR NON-CONFIGURE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * Try to keep one section per platform, compiler and architecture, + * otherwise, if an existing section is reused for a different one and + * later on the original is adjusted, probably the piggybacking one can + * be adversely changed. + * + * In order to differentiate between platforms/compilers/architectures + * use only compiler built in predefined preprocessor symbols. + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * For any given platform/compiler curl_off_t must be typedef'ed to a + * 64-bit wide signed integral data type. The width of this data type + * must remain constant and independent of any possible large file + * support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a + * 32-bit wide signed integral data type if there is no 64-bit type. + * + * As a general rule, curl_off_t shall not be mapped to off_t. This + * rule shall only be violated if off_t is the only 64-bit data type + * available and the size of off_t is independent of large file support + * settings. Keep your build on the safe side avoiding an off_t gating. + * If you have a 64-bit off_t then take for sure that another 64-bit + * data type exists, dig deeper and you will find it. + * + * NOTE 3: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.dist or + * at file include/curl/curlbuild.h, this is due to the following reason: + * file include/curl/curlbuild.h.dist is renamed to include/curl/curlbuild.h + * when the libcurl source code distribution archive file is created. + * + * File include/curl/curlbuild.h.dist is not included in the distribution + * archive. File include/curl/curlbuild.h is not present in the git tree. + * + * The distributed include/curl/curlbuild.h file is only intended to be used + * on systems which can not run the also distributed configure script. + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + * If you check out from git on a non-configure platform, you must run the + * appropriate buildconf* script to set up curlbuild.h and other local files. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY */ +/* ================================================================ */ + +#if defined(__DJGPP__) || defined(__GO32__) +# if defined(__DJGPP__) && (__DJGPP__ > 1) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SALFORDC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__BORLANDC__) +# if (__BORLANDC__ < 0x520) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__TURBOC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__WATCOMC__) +# if defined(__386__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__POCC__) +# if (__POCC__ < 280) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# elif defined(_MSC_VER) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__LCC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SYMBIAN32__) +# if defined(__EABI__) /* Treat all ARM compilers equally */ +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__CW32__) +# pragma longlong on +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__VC32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MWERKS__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(_WIN32_WCE) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MINGW32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__VMS) +# if defined(__VAX) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__OS400__) +# if defined(__ILEC400__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__MVS__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__370__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(TPF) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP MSVC THE PENULTIMATE ENTRY */ +/* ===================================== */ + +#elif defined(_MSC_VER) +# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP GENERIC GCC THE LAST ENTRY */ +/* ===================================== */ + +#elif defined(__GNUC__) +# if !defined(__LP64__) && (defined(__ILP32__) || \ + defined(__i386__) || defined(__ppc__) || defined(__arm__) || \ + defined(__sparc__) || defined(__mips__) || defined(__sh__)) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64__) || \ + defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#else +# error "Unknown non-configure build target!" + Error Compilation_aborted_Unknown_non_configure_build_target +#endif + +/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ +/* sys/types.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ +/* sys/socket.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* Data type definition of curl_socklen_t. */ + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T + typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; +#endif + +/* Data type definition of curl_off_t. */ + +#ifdef CURL_TYPEOF_CURL_OFF_T + typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; +#endif + +#endif /* __CURL_CURLBUILD_H */ diff --git a/compat/includes/curl/curlrules.h b/compat/includes/curl/curlrules.h new file mode 100644 index 0000000..0abd9f7 --- /dev/null +++ b/compat/includes/curl/curlrules.h @@ -0,0 +1,239 @@ +#ifndef __CURL_CURLRULES_H +#define __CURL_CURLRULES_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* COMPILE TIME SANITY CHECKS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * All checks done in this file are intentionally placed in a public + * header file which is pulled by curl/curl.h when an application is + * being built using an already built libcurl library. Additionally + * this file is also included and used when building the library. + * + * If compilation fails on this file it is certainly sure that the + * problem is elsewhere. It could be a problem in the curlbuild.h + * header file, or simply that you are using different compilation + * settings than those used to build the library. + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * Do not deactivate any check, these are done to make sure that the + * library is properly built and used. + * + * You can find further help on the libcurl development mailing list: + * https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * NOTE 2 + * ------ + * + * Some of the following compile time checks are based on the fact + * that the dimension of a constant array can not be a negative one. + * In this way if the compile time verification fails, the compilation + * will fail issuing an error. The error description wording is compiler + * dependent but it will be quite similar to one of the following: + * + * "negative subscript or subscript is too large" + * "array must have at least one element" + * "-1 is an illegal array size" + * "size of array is negative" + * + * If you are building an application which tries to use an already + * built libcurl library and you are getting this kind of errors on + * this file, it is a clear indication that there is a mismatch between + * how the library was built and how you are trying to use it for your + * application. Your already compiled or binary library provider is the + * only one who can give you the details you need to properly use it. + */ + +/* + * Verify that some macros are actually defined. + */ + +#ifndef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing +#endif + +/* + * Macros private to this header file. + */ + +#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1 + +#define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 + +/* + * Verify that the size previously defined and expected for long + * is the same as the one reported by sizeof() at compile time. + */ + +typedef char + __curl_rule_01__ + [CurlchkszEQ(long, CURL_SIZEOF_LONG)]; + +/* + * Verify that the size previously defined and expected for + * curl_off_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_02__ + [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)]; + +/* + * Verify at compile time that the size of curl_off_t as reported + * by sizeof() is greater or equal than the one reported for long + * for the current compilation. + */ + +typedef char + __curl_rule_03__ + [CurlchkszGE(curl_off_t, long)]; + +/* + * Verify that the size previously defined and expected for + * curl_socklen_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_04__ + [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)]; + +/* + * Verify at compile time that the size of curl_socklen_t as reported + * by sizeof() is greater or equal than the one reported for int for + * the current compilation. + */ + +typedef char + __curl_rule_05__ + [CurlchkszGE(curl_socklen_t, int)]; + +/* ================================================================ */ +/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ +/* ================================================================ */ + +/* + * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow + * these to be visible and exported by the external libcurl interface API, + * while also making them visible to the library internals, simply including + * curl_setup.h, without actually needing to include curl.h internally. + * If some day this section would grow big enough, all this should be moved + * to its own header file. + */ + +/* + * Figure out if we can use the ## preprocessor operator, which is supported + * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ + * or __cplusplus so we need to carefully check for them too. + */ + +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ + defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ + defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ + defined(__ILEC400__) + /* This compiler is believed to have an ISO compatible preprocessor */ +#define CURL_ISOCPP +#else + /* This compiler is believed NOT to have an ISO compatible preprocessor */ +#undef CURL_ISOCPP +#endif + +/* + * Macros for minimum-width signed and unsigned curl_off_t integer constants. + */ + +#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) +# define __CURL_OFF_T_C_HLPR2(x) x +# define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) +#else +# ifdef CURL_ISOCPP +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix +# else +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix +# endif +# define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) +#endif + +/* + * Get rid of macros private to this header file. + */ + +#undef CurlchkszEQ +#undef CurlchkszGE + +#endif /* __CURL_CURLRULES_H */ diff --git a/compat/includes/curl/curlver.h b/compat/includes/curl/curlver.h new file mode 100644 index 0000000..95a2cbb --- /dev/null +++ b/compat/includes/curl/curlver.h @@ -0,0 +1,77 @@ +#ifndef __CURL_CURLVER_H +#define __CURL_CURLVER_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* This header file contains nothing but libcurl version info, generated by + a script at release-time. This was made its own header file in 7.11.2 */ + +/* This is the global package copyright */ +#define LIBCURL_COPYRIGHT "1996 - 2017 Daniel Stenberg, ." + +/* This is the version number of the libcurl package from which this header + file origins: */ +#define LIBCURL_VERSION "7.54.0" + +/* The numeric version number is also available "in parts" by using these + defines: */ +#define LIBCURL_VERSION_MAJOR 7 +#define LIBCURL_VERSION_MINOR 54 +#define LIBCURL_VERSION_PATCH 0 + +/* This is the numeric version of the libcurl version number, meant for easier + parsing and comparions by programs. The LIBCURL_VERSION_NUM define will + always follow this syntax: + + 0xXXYYZZ + + Where XX, YY and ZZ are the main version, release and patch numbers in + hexadecimal (using 8 bits each). All three numbers are always represented + using two digits. 1.2 would appear as "0x010200" while version 9.11.7 + appears as "0x090b07". + + This 6-digit (24 bits) hexadecimal number does not show pre-release number, + and it is always a greater number in a more recent release. It makes + comparisons with greater than and less than work. + + Note: This define is the full hex number and _does not_ use the + CURL_VERSION_BITS() macro since curl's own configure script greps for it + and needs it to contain the full number. +*/ +#define LIBCURL_VERSION_NUM 0x073600 + +/* + * This is the date and time when the full source package was created. The + * timestamp is not stored in git, as the timestamp is properly set in the + * tarballs by the maketgz script. + * + * The format of the date should follow this template: + * + * "Mon Feb 12 11:35:33 UTC 2007" + */ +#define LIBCURL_TIMESTAMP "Wed Apr 19 05:43:55 UTC 2017" + +#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z) +#define CURL_AT_LEAST_VERSION(x,y,z) \ + (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) + +#endif /* __CURL_CURLVER_H */ diff --git a/compat/includes/curl/easy.h b/compat/includes/curl/easy.h new file mode 100644 index 0000000..752c504 --- /dev/null +++ b/compat/includes/curl/easy.h @@ -0,0 +1,102 @@ +#ifndef __CURL_EASY_H +#define __CURL_EASY_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN CURL *curl_easy_init(void); +CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); +CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); +CURL_EXTERN void curl_easy_cleanup(CURL *curl); + +/* + * NAME curl_easy_getinfo() + * + * DESCRIPTION + * + * Request internal information from the curl session with this function. The + * third argument MUST be a pointer to a long, a pointer to a char * or a + * pointer to a double (as the documentation describes elsewhere). The data + * pointed to will be filled in accordingly and can be relied upon only if the + * function returns CURLE_OK. This function is intended to get used *AFTER* a + * performed transfer, all results from this function are undefined until the + * transfer is completed. + */ +CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); + + +/* + * NAME curl_easy_duphandle() + * + * DESCRIPTION + * + * Creates a new curl session handle with the same options set for the handle + * passed in. Duplicating a handle could only be a matter of cloning data and + * options, internal state info and things like persistent connections cannot + * be transferred. It is useful in multithreaded applications when you can run + * curl_easy_duphandle() for each new thread to avoid a series of identical + * curl_easy_setopt() invokes in every thread. + */ +CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl); + +/* + * NAME curl_easy_reset() + * + * DESCRIPTION + * + * Re-initializes a CURL handle to the default values. This puts back the + * handle to the same state as it was in when it was just created. + * + * It does keep: live connections, the Session ID cache, the DNS cache and the + * cookies. + */ +CURL_EXTERN void curl_easy_reset(CURL *curl); + +/* + * NAME curl_easy_recv() + * + * DESCRIPTION + * + * Receives data from the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, + size_t *n); + +/* + * NAME curl_easy_send() + * + * DESCRIPTION + * + * Sends data over the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, + size_t buflen, size_t *n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/compat/includes/curl/mprintf.h b/compat/includes/curl/mprintf.h new file mode 100644 index 0000000..e20f546 --- /dev/null +++ b/compat/includes/curl/mprintf.h @@ -0,0 +1,50 @@ +#ifndef __CURL_MPRINTF_H +#define __CURL_MPRINTF_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include +#include /* needed for FILE */ +#include "curl.h" /* for CURL_EXTERN */ + +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN int curl_mprintf(const char *format, ...); +CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); +CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); +CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, + const char *format, ...); +CURL_EXTERN int curl_mvprintf(const char *format, va_list args); +CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); +CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); +CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, + const char *format, va_list args); +CURL_EXTERN char *curl_maprintf(const char *format, ...); +CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); + +#ifdef __cplusplus +} +#endif + +#endif /* __CURL_MPRINTF_H */ diff --git a/compat/includes/curl/multi.h b/compat/includes/curl/multi.h new file mode 100644 index 0000000..f93e511 --- /dev/null +++ b/compat/includes/curl/multi.h @@ -0,0 +1,439 @@ +#ifndef __CURL_MULTI_H +#define __CURL_MULTI_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* + This is an "external" header file. Don't give away any internals here! + + GOALS + + o Enable a "pull" interface. The application that uses libcurl decides where + and when to ask libcurl to get/send data. + + o Enable multiple simultaneous transfers in the same thread without making it + complicated for the application. + + o Enable the application to select() on its own file descriptors and curl's + file descriptors simultaneous easily. + +*/ + +/* + * This header file should not really need to include "curl.h" since curl.h + * itself includes this file and we expect user applications to do #include + * without the need for especially including multi.h. + * + * For some reason we added this include here at one point, and rather than to + * break existing (wrongly written) libcurl applications, we leave it as-is + * but with this warning attached. + */ +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) +typedef struct Curl_multi CURLM; +#else +typedef void CURLM; +#endif + +typedef enum { + CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or + curl_multi_socket*() soon */ + CURLM_OK, + CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ + CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ + CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ + CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ + CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ + CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ + CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was + attempted to get added - again */ + CURLM_LAST +} CURLMcode; + +/* just to make code nicer when using curl_multi_socket() you can now check + for CURLM_CALL_MULTI_SOCKET too in the same style it works for + curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ +#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM + +/* bitmask bits for CURLMOPT_PIPELINING */ +#define CURLPIPE_NOTHING 0L +#define CURLPIPE_HTTP1 1L +#define CURLPIPE_MULTIPLEX 2L + +typedef enum { + CURLMSG_NONE, /* first, not used */ + CURLMSG_DONE, /* This easy handle has completed. 'result' contains + the CURLcode of the transfer */ + CURLMSG_LAST /* last, not used */ +} CURLMSG; + +struct CURLMsg { + CURLMSG msg; /* what this message means */ + CURL *easy_handle; /* the handle it concerns */ + union { + void *whatever; /* message-specific data */ + CURLcode result; /* return code for transfer */ + } data; +}; +typedef struct CURLMsg CURLMsg; + +/* Based on poll(2) structure and values. + * We don't use pollfd and POLL* constants explicitly + * to cover platforms without poll(). */ +#define CURL_WAIT_POLLIN 0x0001 +#define CURL_WAIT_POLLPRI 0x0002 +#define CURL_WAIT_POLLOUT 0x0004 + +struct curl_waitfd { + curl_socket_t fd; + short events; + short revents; /* not supported yet */ +}; + +/* + * Name: curl_multi_init() + * + * Desc: inititalize multi-style curl usage + * + * Returns: a new CURLM handle to use in all 'curl_multi' functions. + */ +CURL_EXTERN CURLM *curl_multi_init(void); + +/* + * Name: curl_multi_add_handle() + * + * Desc: add a standard curl handle to the multi stack + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, + fd_set *read_fd_set, + fd_set *write_fd_set, + fd_set *exc_fd_set, + int *max_fd); + +/* + * Name: curl_multi_wait() + * + * Desc: Poll on all fds within a CURLM set as well as any + * additional fds passed to the function. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, + struct curl_waitfd extra_fds[], + unsigned int extra_nfds, + int timeout_ms, + int *ret); + + /* + * Name: curl_multi_perform() + * + * Desc: When the app thinks there's data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on invidual transfers even when this + * returns OK. + */ +CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, + int *running_handles); + + /* + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); + +/* + * Name: curl_multi_info_read() + * + * Desc: Ask the multi handle if there's any messages/informationals from + * the individual transfers. Messages include informationals such as + * error code from the transfer or just the fact that a transfer is + * completed. More details on these should be written down as well. + * + * Repeated calls to this function will return a new struct each + * time, until a special "end of msgs" struct is returned as a signal + * that there is no more to get at this point. + * + * The data the returned pointer points to will not survive calling + * curl_multi_cleanup(). + * + * The 'CURLMsg' struct is meant to be very simple and only contain + * very basic information. If more involved information is wanted, + * we will provide the particular "transfer handle" in that struct + * and that should/could/would be used in subsequent + * curl_easy_getinfo() calls (or similar). The point being that we + * must never expose complex structs to applications, as then we'll + * undoubtably get backwards compatibility problems in the future. + * + * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out + * of structs. It also writes the number of messages left in the + * queue (after this read) in the integer the second argument points + * to. + */ +CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, + int *msgs_in_queue); + +/* + * Name: curl_multi_strerror() + * + * Desc: The curl_multi_strerror function may be used to turn a CURLMcode + * value into the equivalent human readable error string. This is + * useful for printing meaningful error messages. + * + * Returns: A pointer to a zero-terminated error message. + */ +CURL_EXTERN const char *curl_multi_strerror(CURLMcode); + +/* + * Name: curl_multi_socket() and + * curl_multi_socket_all() + * + * Desc: An alternative version of curl_multi_perform() that allows the + * application to pass in one of the file descriptors that have been + * detected to have "action" on them and let libcurl perform. + * See man page for details. + */ +#define CURL_POLL_NONE 0 +#define CURL_POLL_IN 1 +#define CURL_POLL_OUT 2 +#define CURL_POLL_INOUT 3 +#define CURL_POLL_REMOVE 4 + +#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD + +#define CURL_CSELECT_IN 0x01 +#define CURL_CSELECT_OUT 0x02 +#define CURL_CSELECT_ERR 0x04 + +typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ + curl_socket_t s, /* socket */ + int what, /* see above */ + void *userp, /* private callback + pointer */ + void *socketp); /* private socket + pointer */ +/* + * Name: curl_multi_timer_callback + * + * Desc: Called by libcurl whenever the library detects a change in the + * maximum number of milliseconds the app is allowed to wait before + * curl_multi_socket() or curl_multi_perform() must be called + * (to allow libcurl's timed events to take place). + * + * Returns: The callback should return zero. + */ +typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ + long timeout_ms, /* see above */ + void *userp); /* private callback + pointer */ + +CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, + curl_socket_t s, + int ev_bitmask, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, + int *running_handles); + +#ifndef CURL_ALLOW_OLD_MULTI_SOCKET +/* This macro below was added in 7.16.3 to push users who recompile to use + the new curl_multi_socket_action() instead of the old curl_multi_socket() +*/ +#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) +#endif + +/* + * Name: curl_multi_timeout() + * + * Desc: Returns the maximum number of milliseconds the app is allowed to + * wait before curl_multi_socket() or curl_multi_perform() must be + * called (to allow libcurl's timed events to take place). + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, + long *milliseconds); + +#undef CINIT /* re-using the same name as in curl.h */ + +#ifdef CURL_ISOCPP +#define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLMOPT_/**/name = type + number +#endif + +typedef enum { + /* This is the socket callback function pointer */ + CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), + + /* This is the argument passed to the socket callback */ + CINIT(SOCKETDATA, OBJECTPOINT, 2), + + /* set to 1 to enable pipelining for this multi handle */ + CINIT(PIPELINING, LONG, 3), + + /* This is the timer callback function pointer */ + CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), + + /* This is the argument passed to the timer callback */ + CINIT(TIMERDATA, OBJECTPOINT, 5), + + /* maximum number of entries in the connection cache */ + CINIT(MAXCONNECTS, LONG, 6), + + /* maximum number of (pipelining) connections to one host */ + CINIT(MAX_HOST_CONNECTIONS, LONG, 7), + + /* maximum number of requests in a pipeline */ + CINIT(MAX_PIPELINE_LENGTH, LONG, 8), + + /* a connection with a content-length longer than this + will not be considered for pipelining */ + CINIT(CONTENT_LENGTH_PENALTY_SIZE, OFF_T, 9), + + /* a connection with a chunk length longer than this + will not be considered for pipelining */ + CINIT(CHUNK_LENGTH_PENALTY_SIZE, OFF_T, 10), + + /* a list of site names(+port) that are blacklisted from + pipelining */ + CINIT(PIPELINING_SITE_BL, OBJECTPOINT, 11), + + /* a list of server types that are blacklisted from + pipelining */ + CINIT(PIPELINING_SERVER_BL, OBJECTPOINT, 12), + + /* maximum number of open connections in total */ + CINIT(MAX_TOTAL_CONNECTIONS, LONG, 13), + + /* This is the server push callback function pointer */ + CINIT(PUSHFUNCTION, FUNCTIONPOINT, 14), + + /* This is the argument passed to the server push callback */ + CINIT(PUSHDATA, OBJECTPOINT, 15), + + CURLMOPT_LASTENTRY /* the last unused */ +} CURLMoption; + + +/* + * Name: curl_multi_setopt() + * + * Desc: Sets options for the multi handle. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, + CURLMoption option, ...); + + +/* + * Name: curl_multi_assign() + * + * Desc: This function sets an association in the multi handle between the + * given socket and a private pointer of the application. This is + * (only) useful for curl_multi_socket uses. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, + curl_socket_t sockfd, void *sockp); + + +/* + * Name: curl_push_callback + * + * Desc: This callback gets called when a new stream is being pushed by the + * server. It approves or denies the new stream. + * + * Returns: CURL_PUSH_OK or CURL_PUSH_DENY. + */ +#define CURL_PUSH_OK 0 +#define CURL_PUSH_DENY 1 + +struct curl_pushheaders; /* forward declaration only */ + +CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, + size_t num); +CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, + const char *name); + +typedef int (*curl_push_callback)(CURL *parent, + CURL *easy, + size_t num_headers, + struct curl_pushheaders *headers, + void *userp); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/compat/includes/curl/stdcheaders.h b/compat/includes/curl/stdcheaders.h new file mode 100644 index 0000000..027b6f4 --- /dev/null +++ b/compat/includes/curl/stdcheaders.h @@ -0,0 +1,33 @@ +#ifndef __STDC_HEADERS_H +#define __STDC_HEADERS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include + +size_t fread(void *, size_t, size_t, FILE *); +size_t fwrite(const void *, size_t, size_t, FILE *); + +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); + +#endif /* __STDC_HEADERS_H */ diff --git a/compat/includes/curl/system.h b/compat/includes/curl/system.h new file mode 100644 index 0000000..ed3a55c --- /dev/null +++ b/compat/includes/curl/system.h @@ -0,0 +1,484 @@ +#ifndef __CURL_SYSTEM_H +#define __CURL_SYSTEM_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * This header is supposed to eventually replace curlbuild.h. This little one + * is still learning. During the experimental phase, this header files + * defines symbols using the prefixes CURLSYS_ or curlsys_. When we feel + * confident enough, we replace curlbuild.h with this file and rename all + * prefixes to CURL_ and curl_. + */ + +/* + * Try to keep one section per platform, compiler and architecture, otherwise, + * if an existing section is reused for a different one and later on the + * original is adjusted, probably the piggybacking one can be adversely + * changed. + * + * In order to differentiate between platforms/compilers/architectures use + * only compiler built in predefined preprocessor symbols. + * + * curl_off_t + * ---------- + * + * For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit + * wide signed integral data type. The width of this data type must remain + * constant and independent of any possible large file support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit + * wide signed integral data type if there is no 64-bit type. + * + * As a general rule, curl_off_t shall not be mapped to off_t. This rule shall + * only be violated if off_t is the only 64-bit data type available and the + * size of off_t is independent of large file support settings. Keep your + * build on the safe side avoiding an off_t gating. If you have a 64-bit + * off_t then take for sure that another 64-bit data type exists, dig deeper + * and you will find it. + * + */ + +#if defined(__DJGPP__) || defined(__GO32__) +# if defined(__DJGPP__) && (__DJGPP__ > 1) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# else +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SALFORDC__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__BORLANDC__) +# if (__BORLANDC__ < 0x520) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# else +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T __int64 +# define CURLSYS_FORMAT_CURL_OFF_T "I64d" +# define CURLSYS_FORMAT_CURL_OFF_TU "I64u" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T i64 +# define CURLSYS_SUFFIX_CURL_OFF_TU ui64 +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__TURBOC__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__WATCOMC__) +# if defined(__386__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T __int64 +# define CURLSYS_FORMAT_CURL_OFF_T "I64d" +# define CURLSYS_FORMAT_CURL_OFF_TU "I64u" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T i64 +# define CURLSYS_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__POCC__) +# if (__POCC__ < 280) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# elif defined(_MSC_VER) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T __int64 +# define CURLSYS_FORMAT_CURL_OFF_T "I64d" +# define CURLSYS_FORMAT_CURL_OFF_TU "I64u" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T i64 +# define CURLSYS_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__LCC__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SYMBIAN32__) +# if defined(__EABI__) /* Treat all ARM compilers equally */ +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# elif defined(__CW32__) +# pragma longlong on +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# elif defined(__VC32__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T __int64 +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MWERKS__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(_WIN32_WCE) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T __int64 +# define CURLSYS_FORMAT_CURL_OFF_T "I64d" +# define CURLSYS_FORMAT_CURL_OFF_TU "I64u" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T i64 +# define CURLSYS_SUFFIX_CURL_OFF_TU ui64 +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MINGW32__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "I64d" +# define CURLSYS_FORMAT_CURL_OFF_TU "I64u" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 +# define CURLSYS_PULL_SYS_TYPES_H 1 +# define CURLSYS_PULL_WS2TCPIP_H 1 + +#elif defined(__VMS) +# if defined(__VAX) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# else +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__OS400__) +# if defined(__ILEC400__) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 +# define CURLSYS_PULL_SYS_TYPES_H 1 +# define CURLSYS_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__MVS__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURLSYS_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURLSYS_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# else +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 +# define CURLSYS_PULL_SYS_TYPES_H 1 +# define CURLSYS_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__370__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURLSYS_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURLSYS_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# else +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 +# define CURLSYS_PULL_SYS_TYPES_H 1 +# define CURLSYS_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(TPF) +# define CURLSYS_SIZEOF_LONG 8 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__TINYC__) /* also known as tcc */ + +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURLSYS_PULL_SYS_TYPES_H 1 +# define CURLSYS_PULL_SYS_SOCKET_H 1 + +/* ===================================== */ +/* KEEP MSVC THE PENULTIMATE ENTRY */ +/* ===================================== */ + +#elif defined(_MSC_VER) +# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T __int64 +# define CURLSYS_FORMAT_CURL_OFF_T "I64d" +# define CURLSYS_FORMAT_CURL_OFF_TU "I64u" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T i64 +# define CURLSYS_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP GENERIC GCC THE LAST ENTRY */ +/* ===================================== */ + +#elif defined(__GNUC__) +# if !defined(__LP64__) && (defined(__ILP32__) || \ + defined(__i386__) || defined(__ppc__) || defined(__arm__) || \ + defined(__sparc__) || defined(__mips__) || defined(__sh__)) +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long long +# define CURLSYS_FORMAT_CURL_OFF_T "lld" +# define CURLSYS_FORMAT_CURL_OFF_TU "llu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T LL +# define CURLSYS_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64__) || \ + defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) +# define CURLSYS_SIZEOF_LONG 8 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SIZEOF_CURL_OFF_T 8 +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# endif +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 +# define CURLSYS_PULL_SYS_TYPES_H 1 +# define CURLSYS_PULL_SYS_SOCKET_H 1 + +#else +/* generic "safe guess" on old 32 bit style */ +# define CURLSYS_SIZEOF_LONG 4 +# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4 +# define CURLSYS_SIZEOF_CURL_OFF_T 4 +# define CURLSYS_TYPEOF_CURL_OFF_T long +# define CURLSYS_FORMAT_CURL_OFF_T "ld" +# define CURLSYS_FORMAT_CURL_OFF_TU "lu" +# define CURLSYS_SUFFIX_CURL_OFF_T L +# define CURLSYS_SUFFIX_CURL_OFF_TU UL +# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int +#endif + +/* CURLSYS_PULL_WS2TCPIP_H is defined above when inclusion of header file */ +/* ws2tcpip.h is required here to properly make type definitions below. */ +#ifdef CURLSYS_PULL_WS2TCPIP_H +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# include +#endif + +/* CURLSYS_PULL_SYS_TYPES_H is defined above when inclusion of header file */ +/* sys/types.h is required here to properly make type definitions below. */ +#ifdef CURLSYS_PULL_SYS_TYPES_H +# include +#endif + +/* CURLSYS_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ +/* sys/socket.h is required here to properly make type definitions below. */ +#ifdef CURLSYS_PULL_SYS_SOCKET_H +# include +#endif + +/* Data type definition of curl_socklen_t. */ +#ifdef CURLSYS_TYPEOF_CURL_SOCKLEN_T + typedef CURLSYS_TYPEOF_CURL_SOCKLEN_T curlsys_socklen_t; +#endif + +/* Data type definition of curl_off_t. */ + +#ifdef CURLSYS_TYPEOF_CURL_OFF_T + typedef CURLSYS_TYPEOF_CURL_OFF_T curlsys_off_t; +#endif + +#endif /* __CURL_SYSTEM_H */ + diff --git a/compat/includes/curl/typecheck-gcc.h b/compat/includes/curl/typecheck-gcc.h new file mode 100644 index 0000000..3d68315 --- /dev/null +++ b/compat/includes/curl/typecheck-gcc.h @@ -0,0 +1,624 @@ +#ifndef __CURL_TYPECHECK_GCC_H +#define __CURL_TYPECHECK_GCC_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* wraps curl_easy_setopt() with typechecking */ + +/* To add a new kind of warning, add an + * if(_curl_is_sometype_option(_curl_opt)) + * if(!_curl_is_sometype(value)) + * _curl_easy_setopt_err_sometype(); + * block and define _curl_is_sometype_option, _curl_is_sometype and + * _curl_easy_setopt_err_sometype below + * + * NOTE: We use two nested 'if' statements here instead of the && operator, in + * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x + * when compiling with -Wlogical-op. + * + * To add an option that uses the same type as an existing option, you'll just + * need to extend the appropriate _curl_*_option macro + */ +#define curl_easy_setopt(handle, option, value) \ +__extension__ ({ \ + __typeof__(option) _curl_opt = option; \ + if(__builtin_constant_p(_curl_opt)) { \ + if(_curl_is_long_option(_curl_opt)) \ + if(!_curl_is_long(value)) \ + _curl_easy_setopt_err_long(); \ + if(_curl_is_off_t_option(_curl_opt)) \ + if(!_curl_is_off_t(value)) \ + _curl_easy_setopt_err_curl_off_t(); \ + if(_curl_is_string_option(_curl_opt)) \ + if(!_curl_is_string(value)) \ + _curl_easy_setopt_err_string(); \ + if(_curl_is_write_cb_option(_curl_opt)) \ + if(!_curl_is_write_cb(value)) \ + _curl_easy_setopt_err_write_callback(); \ + if((_curl_opt) == CURLOPT_READFUNCTION) \ + if(!_curl_is_read_cb(value)) \ + _curl_easy_setopt_err_read_cb(); \ + if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ + if(!_curl_is_ioctl_cb(value)) \ + _curl_easy_setopt_err_ioctl_cb(); \ + if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ + if(!_curl_is_sockopt_cb(value)) \ + _curl_easy_setopt_err_sockopt_cb(); \ + if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ + if(!_curl_is_opensocket_cb(value)) \ + _curl_easy_setopt_err_opensocket_cb(); \ + if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ + if(!_curl_is_progress_cb(value)) \ + _curl_easy_setopt_err_progress_cb(); \ + if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ + if(!_curl_is_debug_cb(value)) \ + _curl_easy_setopt_err_debug_cb(); \ + if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ + if(!_curl_is_ssl_ctx_cb(value)) \ + _curl_easy_setopt_err_ssl_ctx_cb(); \ + if(_curl_is_conv_cb_option(_curl_opt)) \ + if(!_curl_is_conv_cb(value)) \ + _curl_easy_setopt_err_conv_cb(); \ + if((_curl_opt) == CURLOPT_SEEKFUNCTION) \ + if(!_curl_is_seek_cb(value)) \ + _curl_easy_setopt_err_seek_cb(); \ + if(_curl_is_cb_data_option(_curl_opt)) \ + if(!_curl_is_cb_data(value)) \ + _curl_easy_setopt_err_cb_data(); \ + if((_curl_opt) == CURLOPT_ERRORBUFFER) \ + if(!_curl_is_error_buffer(value)) \ + _curl_easy_setopt_err_error_buffer(); \ + if((_curl_opt) == CURLOPT_STDERR) \ + if(!_curl_is_FILE(value)) \ + _curl_easy_setopt_err_FILE(); \ + if(_curl_is_postfields_option(_curl_opt)) \ + if(!_curl_is_postfields(value)) \ + _curl_easy_setopt_err_postfields(); \ + if((_curl_opt) == CURLOPT_HTTPPOST) \ + if(!_curl_is_arr((value), struct curl_httppost)) \ + _curl_easy_setopt_err_curl_httpost(); \ + if(_curl_is_slist_option(_curl_opt)) \ + if(!_curl_is_arr((value), struct curl_slist)) \ + _curl_easy_setopt_err_curl_slist(); \ + if((_curl_opt) == CURLOPT_SHARE) \ + if(!_curl_is_ptr((value), CURLSH)) \ + _curl_easy_setopt_err_CURLSH(); \ + } \ + curl_easy_setopt(handle, _curl_opt, value); \ +}) + +/* wraps curl_easy_getinfo() with typechecking */ +/* FIXME: don't allow const pointers */ +#define curl_easy_getinfo(handle, info, arg) \ +__extension__ ({ \ + __typeof__(info) _curl_info = info; \ + if(__builtin_constant_p(_curl_info)) { \ + if(_curl_is_string_info(_curl_info)) \ + if(!_curl_is_arr((arg), char *)) \ + _curl_easy_getinfo_err_string(); \ + if(_curl_is_long_info(_curl_info)) \ + if(!_curl_is_arr((arg), long)) \ + _curl_easy_getinfo_err_long(); \ + if(_curl_is_double_info(_curl_info)) \ + if(!_curl_is_arr((arg), double)) \ + _curl_easy_getinfo_err_double(); \ + if(_curl_is_slist_info(_curl_info)) \ + if(!_curl_is_arr((arg), struct curl_slist *)) \ + _curl_easy_getinfo_err_curl_slist(); \ + } \ + curl_easy_getinfo(handle, _curl_info, arg); \ +}) + +/* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(), + * for now just make sure that the functions are called with three + * arguments + */ +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) + + +/* the actual warnings, triggered by calling the _curl_easy_setopt_err* + * functions */ + +/* To define a new warning, use _CURL_WARNING(identifier, "message") */ +#define _CURL_WARNING(id, message) \ + static void __attribute__((__warning__(message))) \ + __attribute__((__unused__)) __attribute__((__noinline__)) \ + id(void) { __asm__(""); } + +_CURL_WARNING(_curl_easy_setopt_err_long, + "curl_easy_setopt expects a long argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_off_t, + "curl_easy_setopt expects a curl_off_t argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_string, + "curl_easy_setopt expects a " + "string ('char *' or char[]) argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_write_callback, + "curl_easy_setopt expects a curl_write_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_read_cb, + "curl_easy_setopt expects a curl_read_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ioctl_cb, + "curl_easy_setopt expects a curl_ioctl_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_sockopt_cb, + "curl_easy_setopt expects a curl_sockopt_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_opensocket_cb, + "curl_easy_setopt expects a " + "curl_opensocket_callback argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_progress_cb, + "curl_easy_setopt expects a curl_progress_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_debug_cb, + "curl_easy_setopt expects a curl_debug_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb, + "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_conv_cb, + "curl_easy_setopt expects a curl_conv_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_seek_cb, + "curl_easy_setopt expects a curl_seek_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_cb_data, + "curl_easy_setopt expects a " + "private data pointer as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_error_buffer, + "curl_easy_setopt expects a " + "char buffer of CURL_ERROR_SIZE as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_FILE, + "curl_easy_setopt expects a 'FILE *' argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_postfields, + "curl_easy_setopt expects a 'void *' or 'char *' argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_httpost, + "curl_easy_setopt expects a 'struct curl_httppost *' " + "argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_slist, + "curl_easy_setopt expects a 'struct curl_slist *' argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_CURLSH, + "curl_easy_setopt expects a CURLSH* argument for this option") + +_CURL_WARNING(_curl_easy_getinfo_err_string, + "curl_easy_getinfo expects a pointer to 'char *' for this info") +_CURL_WARNING(_curl_easy_getinfo_err_long, + "curl_easy_getinfo expects a pointer to long for this info") +_CURL_WARNING(_curl_easy_getinfo_err_double, + "curl_easy_getinfo expects a pointer to double for this info") +_CURL_WARNING(_curl_easy_getinfo_err_curl_slist, + "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info") + +/* groups of curl_easy_setops options that take the same type of argument */ + +/* To add a new option to one of the groups, just add + * (option) == CURLOPT_SOMETHING + * to the or-expression. If the option takes a long or curl_off_t, you don't + * have to do anything + */ + +/* evaluates to true if option takes a long argument */ +#define _curl_is_long_option(option) \ + (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) + +#define _curl_is_off_t_option(option) \ + ((option) > CURLOPTTYPE_OFF_T) + +/* evaluates to true if option takes a char* argument */ +#define _curl_is_string_option(option) \ + ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \ + (option) == CURLOPT_ACCEPT_ENCODING || \ + (option) == CURLOPT_CAINFO || \ + (option) == CURLOPT_CAPATH || \ + (option) == CURLOPT_COOKIE || \ + (option) == CURLOPT_COOKIEFILE || \ + (option) == CURLOPT_COOKIEJAR || \ + (option) == CURLOPT_COOKIELIST || \ + (option) == CURLOPT_CRLFILE || \ + (option) == CURLOPT_CUSTOMREQUEST || \ + (option) == CURLOPT_DEFAULT_PROTOCOL || \ + (option) == CURLOPT_DNS_INTERFACE || \ + (option) == CURLOPT_DNS_LOCAL_IP4 || \ + (option) == CURLOPT_DNS_LOCAL_IP6 || \ + (option) == CURLOPT_DNS_SERVERS || \ + (option) == CURLOPT_EGDSOCKET || \ + (option) == CURLOPT_FTPPORT || \ + (option) == CURLOPT_FTP_ACCOUNT || \ + (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ + (option) == CURLOPT_INTERFACE || \ + (option) == CURLOPT_ISSUERCERT || \ + (option) == CURLOPT_KEYPASSWD || \ + (option) == CURLOPT_KRBLEVEL || \ + (option) == CURLOPT_LOGIN_OPTIONS || \ + (option) == CURLOPT_MAIL_AUTH || \ + (option) == CURLOPT_MAIL_FROM || \ + (option) == CURLOPT_NETRC_FILE || \ + (option) == CURLOPT_NOPROXY || \ + (option) == CURLOPT_PASSWORD || \ + (option) == CURLOPT_PINNEDPUBLICKEY || \ + (option) == CURLOPT_PROXY || \ + (option) == CURLOPT_PROXYPASSWORD || \ + (option) == CURLOPT_PROXYUSERNAME || \ + (option) == CURLOPT_PROXYUSERPWD || \ + (option) == CURLOPT_PROXY_SERVICE_NAME || \ + (option) == CURLOPT_RANDOM_FILE || \ + (option) == CURLOPT_RANGE || \ + (option) == CURLOPT_REFERER || \ + (option) == CURLOPT_RTSP_SESSION_ID || \ + (option) == CURLOPT_RTSP_STREAM_URI || \ + (option) == CURLOPT_RTSP_TRANSPORT || \ + (option) == CURLOPT_SERVICE_NAME || \ + (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ + (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ + (option) == CURLOPT_SSH_KNOWNHOSTS || \ + (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ + (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ + (option) == CURLOPT_SSLCERT || \ + (option) == CURLOPT_SSLCERTTYPE || \ + (option) == CURLOPT_SSLENGINE || \ + (option) == CURLOPT_SSLKEY || \ + (option) == CURLOPT_SSLKEYTYPE || \ + (option) == CURLOPT_SSL_CIPHER_LIST || \ + (option) == CURLOPT_TLSAUTH_PASSWORD || \ + (option) == CURLOPT_TLSAUTH_TYPE || \ + (option) == CURLOPT_TLSAUTH_USERNAME || \ + (option) == CURLOPT_UNIX_SOCKET_PATH || \ + (option) == CURLOPT_URL || \ + (option) == CURLOPT_USERAGENT || \ + (option) == CURLOPT_USERNAME || \ + (option) == CURLOPT_USERPWD || \ + (option) == CURLOPT_XOAUTH2_BEARER || \ + 0) + +/* evaluates to true if option takes a curl_write_callback argument */ +#define _curl_is_write_cb_option(option) \ + ((option) == CURLOPT_HEADERFUNCTION || \ + (option) == CURLOPT_WRITEFUNCTION) + +/* evaluates to true if option takes a curl_conv_callback argument */ +#define _curl_is_conv_cb_option(option) \ + ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) + +/* evaluates to true if option takes a data argument to pass to a callback */ +#define _curl_is_cb_data_option(option) \ + ((option) == CURLOPT_CHUNK_DATA || \ + (option) == CURLOPT_CLOSESOCKETDATA || \ + (option) == CURLOPT_DEBUGDATA || \ + (option) == CURLOPT_FNMATCH_DATA || \ + (option) == CURLOPT_HEADERDATA || \ + (option) == CURLOPT_INTERLEAVEDATA || \ + (option) == CURLOPT_IOCTLDATA || \ + (option) == CURLOPT_OPENSOCKETDATA || \ + (option) == CURLOPT_PRIVATE || \ + (option) == CURLOPT_PROGRESSDATA || \ + (option) == CURLOPT_READDATA || \ + (option) == CURLOPT_SEEKDATA || \ + (option) == CURLOPT_SOCKOPTDATA || \ + (option) == CURLOPT_SSH_KEYDATA || \ + (option) == CURLOPT_SSL_CTX_DATA || \ + (option) == CURLOPT_WRITEDATA || \ + 0) + +/* evaluates to true if option takes a POST data argument (void* or char*) */ +#define _curl_is_postfields_option(option) \ + ((option) == CURLOPT_POSTFIELDS || \ + (option) == CURLOPT_COPYPOSTFIELDS || \ + 0) + +/* evaluates to true if option takes a struct curl_slist * argument */ +#define _curl_is_slist_option(option) \ + ((option) == CURLOPT_HTTP200ALIASES || \ + (option) == CURLOPT_HTTPHEADER || \ + (option) == CURLOPT_MAIL_RCPT || \ + (option) == CURLOPT_POSTQUOTE || \ + (option) == CURLOPT_PREQUOTE || \ + (option) == CURLOPT_PROXYHEADER || \ + (option) == CURLOPT_QUOTE || \ + (option) == CURLOPT_RESOLVE || \ + (option) == CURLOPT_TELNETOPTIONS || \ + 0) + +/* groups of curl_easy_getinfo infos that take the same type of argument */ + +/* evaluates to true if info expects a pointer to char * argument */ +#define _curl_is_string_info(info) \ + (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG) + +/* evaluates to true if info expects a pointer to long argument */ +#define _curl_is_long_info(info) \ + (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) + +/* evaluates to true if info expects a pointer to double argument */ +#define _curl_is_double_info(info) \ + (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) + +/* true if info expects a pointer to struct curl_slist * argument */ +#define _curl_is_slist_info(info) \ + (CURLINFO_SLIST < (info)) + + +/* typecheck helpers -- check whether given expression has requested type*/ + +/* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros, + * otherwise define a new macro. Search for __builtin_types_compatible_p + * in the GCC manual. + * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is + * the actual expression passed to the curl_easy_setopt macro. This + * means that you can only apply the sizeof and __typeof__ operators, no + * == or whatsoever. + */ + +/* XXX: should evaluate to true iff expr is a pointer */ +#define _curl_is_any_ptr(expr) \ + (sizeof(expr) == sizeof(void *)) + +/* evaluates to true if expr is NULL */ +/* XXX: must not evaluate expr, so this check is not accurate */ +#define _curl_is_NULL(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) + +/* evaluates to true if expr is type*, const type* or NULL */ +#define _curl_is_ptr(expr, type) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), type *) || \ + __builtin_types_compatible_p(__typeof__(expr), const type *)) + +/* evaluates to true if expr is one of type[], type*, NULL or const type* */ +#define _curl_is_arr(expr, type) \ + (_curl_is_ptr((expr), type) || \ + __builtin_types_compatible_p(__typeof__(expr), type [])) + +/* evaluates to true if expr is a string */ +#define _curl_is_string(expr) \ + (_curl_is_arr((expr), char) || \ + _curl_is_arr((expr), signed char) || \ + _curl_is_arr((expr), unsigned char)) + +/* evaluates to true if expr is a long (no matter the signedness) + * XXX: for now, int is also accepted (and therefore short and char, which + * are promoted to int when passed to a variadic function) */ +#define _curl_is_long(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), long) || \ + __builtin_types_compatible_p(__typeof__(expr), signed long) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ + __builtin_types_compatible_p(__typeof__(expr), int) || \ + __builtin_types_compatible_p(__typeof__(expr), signed int) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ + __builtin_types_compatible_p(__typeof__(expr), short) || \ + __builtin_types_compatible_p(__typeof__(expr), signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), char) || \ + __builtin_types_compatible_p(__typeof__(expr), signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned char)) + +/* evaluates to true if expr is of type curl_off_t */ +#define _curl_is_off_t(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) + +/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ +/* XXX: also check size of an char[] array? */ +#define _curl_is_error_buffer(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), char *) || \ + __builtin_types_compatible_p(__typeof__(expr), char[])) + +/* evaluates to true if expr is of type (const) void* or (const) FILE* */ +#if 0 +#define _curl_is_cb_data(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_ptr((expr), FILE)) +#else /* be less strict */ +#define _curl_is_cb_data(expr) \ + _curl_is_any_ptr(expr) +#endif + +/* evaluates to true if expr is of type FILE* */ +#define _curl_is_FILE(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), FILE *)) + +/* evaluates to true if expr can be passed as POST data (void* or char*) */ +#define _curl_is_postfields(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_arr((expr), char)) + +/* FIXME: the whole callback checking is messy... + * The idea is to tolerate char vs. void and const vs. not const + * pointers in arguments at least + */ +/* helper: __builtin_types_compatible_p distinguishes between functions and + * function pointers, hide it */ +#define _curl_callback_compatible(func, type) \ + (__builtin_types_compatible_p(__typeof__(func), type) || \ + __builtin_types_compatible_p(__typeof__(func), type*)) + +/* evaluates to true if expr is of type curl_read_callback or "similar" */ +#define _curl_is_read_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fread)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_read_callback) || \ + _curl_callback_compatible((expr), _curl_read_callback1) || \ + _curl_callback_compatible((expr), _curl_read_callback2) || \ + _curl_callback_compatible((expr), _curl_read_callback3) || \ + _curl_callback_compatible((expr), _curl_read_callback4) || \ + _curl_callback_compatible((expr), _curl_read_callback5) || \ + _curl_callback_compatible((expr), _curl_read_callback6)) +typedef size_t (_curl_read_callback1)(char *, size_t, size_t, void *); +typedef size_t (_curl_read_callback2)(char *, size_t, size_t, const void *); +typedef size_t (_curl_read_callback3)(char *, size_t, size_t, FILE *); +typedef size_t (_curl_read_callback4)(void *, size_t, size_t, void *); +typedef size_t (_curl_read_callback5)(void *, size_t, size_t, const void *); +typedef size_t (_curl_read_callback6)(void *, size_t, size_t, FILE *); + +/* evaluates to true if expr is of type curl_write_callback or "similar" */ +#define _curl_is_write_cb(expr) \ + (_curl_is_read_cb(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fwrite)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_write_callback) || \ + _curl_callback_compatible((expr), _curl_write_callback1) || \ + _curl_callback_compatible((expr), _curl_write_callback2) || \ + _curl_callback_compatible((expr), _curl_write_callback3) || \ + _curl_callback_compatible((expr), _curl_write_callback4) || \ + _curl_callback_compatible((expr), _curl_write_callback5) || \ + _curl_callback_compatible((expr), _curl_write_callback6)) +typedef size_t (_curl_write_callback1)(const char *, size_t, size_t, void *); +typedef size_t (_curl_write_callback2)(const char *, size_t, size_t, + const void *); +typedef size_t (_curl_write_callback3)(const char *, size_t, size_t, FILE *); +typedef size_t (_curl_write_callback4)(const void *, size_t, size_t, void *); +typedef size_t (_curl_write_callback5)(const void *, size_t, size_t, + const void *); +typedef size_t (_curl_write_callback6)(const void *, size_t, size_t, FILE *); + +/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ +#define _curl_is_ioctl_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ioctl_callback) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback1) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback2) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback3) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback4)) +typedef curlioerr (_curl_ioctl_callback1)(CURL *, int, void *); +typedef curlioerr (_curl_ioctl_callback2)(CURL *, int, const void *); +typedef curlioerr (_curl_ioctl_callback3)(CURL *, curliocmd, void *); +typedef curlioerr (_curl_ioctl_callback4)(CURL *, curliocmd, const void *); + +/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ +#define _curl_is_sockopt_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_sockopt_callback) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback1) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback2)) +typedef int (_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); +typedef int (_curl_sockopt_callback2)(const void *, curl_socket_t, + curlsocktype); + +/* evaluates to true if expr is of type curl_opensocket_callback or + "similar" */ +#define _curl_is_opensocket_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_opensocket_callback) ||\ + _curl_callback_compatible((expr), _curl_opensocket_callback1) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback2) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback3) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback4)) +typedef curl_socket_t (_curl_opensocket_callback1) + (void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback2) + (void *, curlsocktype, const struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback3) + (const void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback4) + (const void *, curlsocktype, const struct curl_sockaddr *); + +/* evaluates to true if expr is of type curl_progress_callback or "similar" */ +#define _curl_is_progress_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_progress_callback) || \ + _curl_callback_compatible((expr), _curl_progress_callback1) || \ + _curl_callback_compatible((expr), _curl_progress_callback2)) +typedef int (_curl_progress_callback1)(void *, + double, double, double, double); +typedef int (_curl_progress_callback2)(const void *, + double, double, double, double); + +/* evaluates to true if expr is of type curl_debug_callback or "similar" */ +#define _curl_is_debug_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_debug_callback) || \ + _curl_callback_compatible((expr), _curl_debug_callback1) || \ + _curl_callback_compatible((expr), _curl_debug_callback2) || \ + _curl_callback_compatible((expr), _curl_debug_callback3) || \ + _curl_callback_compatible((expr), _curl_debug_callback4) || \ + _curl_callback_compatible((expr), _curl_debug_callback5) || \ + _curl_callback_compatible((expr), _curl_debug_callback6) || \ + _curl_callback_compatible((expr), _curl_debug_callback7) || \ + _curl_callback_compatible((expr), _curl_debug_callback8)) +typedef int (_curl_debug_callback1) (CURL *, + curl_infotype, char *, size_t, void *); +typedef int (_curl_debug_callback2) (CURL *, + curl_infotype, char *, size_t, const void *); +typedef int (_curl_debug_callback3) (CURL *, + curl_infotype, const char *, size_t, void *); +typedef int (_curl_debug_callback4) (CURL *, + curl_infotype, const char *, size_t, const void *); +typedef int (_curl_debug_callback5) (CURL *, + curl_infotype, unsigned char *, size_t, void *); +typedef int (_curl_debug_callback6) (CURL *, + curl_infotype, unsigned char *, size_t, const void *); +typedef int (_curl_debug_callback7) (CURL *, + curl_infotype, const unsigned char *, size_t, void *); +typedef int (_curl_debug_callback8) (CURL *, + curl_infotype, const unsigned char *, size_t, const void *); + +/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ +/* this is getting even messier... */ +#define _curl_is_ssl_ctx_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ssl_ctx_callback) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback8)) +typedef CURLcode (_curl_ssl_ctx_callback1)(CURL *, void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback2)(CURL *, void *, const void *); +typedef CURLcode (_curl_ssl_ctx_callback3)(CURL *, const void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback4)(CURL *, const void *, const void *); +#ifdef HEADER_SSL_H +/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX + * this will of course break if we're included before OpenSSL headers... + */ +typedef CURLcode (_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *); +typedef CURLcode (_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, + const void *); +#else +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; +#endif + +/* evaluates to true if expr is of type curl_conv_callback or "similar" */ +#define _curl_is_conv_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_conv_callback) || \ + _curl_callback_compatible((expr), _curl_conv_callback1) || \ + _curl_callback_compatible((expr), _curl_conv_callback2) || \ + _curl_callback_compatible((expr), _curl_conv_callback3) || \ + _curl_callback_compatible((expr), _curl_conv_callback4)) +typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); +typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); +typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); +typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); + +/* evaluates to true if expr is of type curl_seek_callback or "similar" */ +#define _curl_is_seek_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_seek_callback) || \ + _curl_callback_compatible((expr), _curl_seek_callback1) || \ + _curl_callback_compatible((expr), _curl_seek_callback2)) +typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); +typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); + + +#endif /* __CURL_TYPECHECK_GCC_H */ diff --git a/compat/includes/openssl/e_os2.h b/compat/includes/openssl/e_os2.h new file mode 100644 index 0000000..99ea347 --- /dev/null +++ b/compat/includes/openssl/e_os2.h @@ -0,0 +1,311 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_E_OS2_H +# define HEADER_E_OS2_H + +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Detect operating systems. This probably needs completing. + * The result is that at least one OPENSSL_SYS_os macro should be defined. + * However, if none is defined, Unix is assumed. + **/ + +# define OPENSSL_SYS_UNIX + +/* --------------------- Microsoft operating systems ---------------------- */ + +/* + * Note that MSDOS actually denotes 32-bit environments running on top of + * MS-DOS, such as DJGPP one. + */ +# if defined(OPENSSL_SYS_MSDOS) +# undef OPENSSL_SYS_UNIX +# endif + +/* + * For 32 bit environment, there seems to be the CygWin environment and then + * all the others that try to do the same thing Microsoft does... + */ +/* + * UEFI lives here because it might be built with a Microsoft toolchain and + * we need to avoid the false positive match on Windows. + */ +# if defined(OPENSSL_SYS_UEFI) +# undef OPENSSL_SYS_UNIX +# elif defined(OPENSSL_SYS_UWIN) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_UWIN +# else +# if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_CYGWIN +# else +# if defined(_WIN32) || defined(OPENSSL_SYS_WIN32) +# undef OPENSSL_SYS_UNIX +# if !defined(OPENSSL_SYS_WIN32) +# define OPENSSL_SYS_WIN32 +# endif +# endif +# if defined(_WIN64) || defined(OPENSSL_SYS_WIN64) +# undef OPENSSL_SYS_UNIX +# if !defined(OPENSSL_SYS_WIN64) +# define OPENSSL_SYS_WIN64 +# endif +# endif +# if defined(OPENSSL_SYS_WINNT) +# undef OPENSSL_SYS_UNIX +# endif +# if defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# endif +# endif +# endif + +/* Anything that tries to look like Microsoft is "Windows" */ +# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_SYS_MSDOS +# define OPENSSL_SYS_MSDOS +# endif +# endif + +/* + * DLL settings. This part is a bit tough, because it's up to the + * application implementor how he or she will link the application, so it + * requires some macro to be used. + */ +# ifdef OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_OPT_WINDLL +# if defined(_WINDLL) /* This is used when building OpenSSL to + * indicate that DLL linkage should be used */ +# define OPENSSL_OPT_WINDLL +# endif +# endif +# endif + +/* ------------------------------- OpenVMS -------------------------------- */ +# if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS) +# if !defined(OPENSSL_SYS_VMS) +# undef OPENSSL_SYS_UNIX +# endif +# define OPENSSL_SYS_VMS +# if defined(__DECC) +# define OPENSSL_SYS_VMS_DECC +# elif defined(__DECCXX) +# define OPENSSL_SYS_VMS_DECC +# define OPENSSL_SYS_VMS_DECCXX +# else +# define OPENSSL_SYS_VMS_NODECC +# endif +# endif + +/* -------------------------------- Unix ---------------------------------- */ +# ifdef OPENSSL_SYS_UNIX +# if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX) +# define OPENSSL_SYS_LINUX +# endif +# if defined(_AIX) && !defined(OPENSSL_SYS_AIX) +# define OPENSSL_SYS_AIX +# endif +# endif + +/* -------------------------------- VOS ----------------------------------- */ +# if defined(__VOS__) && !defined(OPENSSL_SYS_VOS) +# define OPENSSL_SYS_VOS +# ifdef __HPPA__ +# define OPENSSL_SYS_VOS_HPPA +# endif +# ifdef __IA32__ +# define OPENSSL_SYS_VOS_IA32 +# endif +# endif + +/** + * That's it for OS-specific stuff + *****************************************************************************/ + +/* Specials for I/O an exit */ +# ifdef OPENSSL_SYS_MSDOS +# define OPENSSL_UNISTD_IO +# define OPENSSL_DECLARE_EXIT extern void exit(int); +# else +# define OPENSSL_UNISTD_IO OPENSSL_UNISTD +# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */ +# endif + +/*- + * Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare + * certain global symbols that, with some compilers under VMS, have to be + * defined and declared explicitly with globaldef and globalref. + * Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare + * DLL exports and imports for compilers under Win32. These are a little + * more complicated to use. Basically, for any library that exports some + * global variables, the following code must be present in the header file + * that declares them, before OPENSSL_EXTERN is used: + * + * #ifdef SOME_BUILD_FLAG_MACRO + * # undef OPENSSL_EXTERN + * # define OPENSSL_EXTERN OPENSSL_EXPORT + * #endif + * + * The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL + * have some generally sensible values. + */ + +# if defined(OPENSSL_SYS_VMS_NODECC) +# define OPENSSL_EXPORT globalref +# define OPENSSL_EXTERN globalref +# define OPENSSL_GLOBAL globaldef +# elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL) +# define OPENSSL_EXPORT extern __declspec(dllexport) +# define OPENSSL_EXTERN extern __declspec(dllimport) +# define OPENSSL_GLOBAL +# else +# define OPENSSL_EXPORT extern +# define OPENSSL_EXTERN extern +# define OPENSSL_GLOBAL +# endif + +/*- + * Macros to allow global variables to be reached through function calls when + * required (if a shared library version requires it, for example. + * The way it's done allows definitions like this: + * + * // in foobar.c + * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0) + * // in foobar.h + * OPENSSL_DECLARE_GLOBAL(int,foobar); + * #define foobar OPENSSL_GLOBAL_REF(foobar) + */ +# ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION +# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \ + type *_shadow_##name(void) \ + { static type _hide_##name=value; return &_hide_##name; } +# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void) +# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name())) +# else +# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value; +# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name +# define OPENSSL_GLOBAL_REF(name) _shadow_##name +# endif + +# ifdef _WIN32 +# ifdef _WIN64 +# define ossl_ssize_t __int64 +# define OSSL_SSIZE_MAX _I64_MAX +# else +# define ossl_ssize_t int +# define OSSL_SSIZE_MAX INT_MAX +# endif +# endif + +# if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t) +# define ossl_ssize_t int +# define OSSL_SSIZE_MAX INT_MAX +# endif + +# ifndef ossl_ssize_t +# define ossl_ssize_t ssize_t +# if defined(SSIZE_MAX) +# define OSSL_SSIZE_MAX SSIZE_MAX +# elif defined(_POSIX_SSIZE_MAX) +# define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX +# endif +# endif + +# ifdef DEBUG_UNUSED +# define __owur __attribute__((__warn_unused_result__)) +# else +# define __owur +# endif + +/* Standard integer types */ +# if defined(OPENSSL_SYS_UEFI) +typedef INT8 int8_t; +typedef UINT8 uint8_t; +typedef INT16 int16_t; +typedef UINT16 uint16_t; +typedef INT32 int32_t; +typedef UINT32 uint32_t; +typedef INT64 int64_t; +typedef UINT64 uint64_t; +# define PRIu64 "%Lu" +# elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + defined(__osf__) || defined(__sgi) || defined(__hpux) || \ + defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__) +# include +# elif defined(_MSC_VER) && _MSC_VER<=1500 +/* + * minimally required typdefs for systems not supporting inttypes.h or + * stdint.h: currently just older VC++ + */ +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +# else +# include +# endif + +/* + * We need a format operator for some client tools for uint64_t. If inttypes.h + * isn't available or did not define it, just go with hard-coded. + */ +# ifndef PRIu64 +# ifdef SIXTY_FOUR_BIT_LONG +# define PRIu64 "lu" +# else +# define PRIu64 "llu" +# endif +# endif + +/* ossl_inline: portable inline definition usable in public headers */ +# if !defined(inline) && !defined(__cplusplus) +# if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L + /* just use inline */ +# define ossl_inline inline +# elif defined(__GNUC__) && __GNUC__>=2 +# define ossl_inline __inline__ +# elif defined(_MSC_VER) + /* + * Visual Studio: inline is available in C++ only, however + * __inline is available for C, see + * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx + */ +# define ossl_inline __inline +# else +# define ossl_inline +# endif +# else +# define ossl_inline inline +# endif + +# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define ossl_noreturn _Noreturn +# elif defined(__GNUC__) && __GNUC__ >= 2 +# define ossl_noreturn __attribute__((noreturn)) +# else +# define ossl_noreturn +# endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/compat/includes/openssl/opensslconf.h b/compat/includes/openssl/opensslconf.h new file mode 100644 index 0000000..77861ec --- /dev/null +++ b/compat/includes/openssl/opensslconf.h @@ -0,0 +1,172 @@ +/* + * WARNING: do not edit! + * Generated by makefile from include\openssl\opensslconf.h.in + * + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_ALGORITHM_DEFINES +# error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif + +/* + * OpenSSL was configured with the following options: + */ + +#ifndef OPENSSL_SYS_WIN64A +# define OPENSSL_SYS_WIN64A 1 +#endif +#ifndef OPENSSL_NO_MD2 +# define OPENSSL_NO_MD2 +#endif +#ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif +#ifndef OPENSSL_NO_ASAN +# define OPENSSL_NO_ASAN +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_NO_CRYPTO_MDEBUG +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#endif +#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +# define OPENSSL_NO_EC_NISTP_64_GCC_128 +#endif +#ifndef OPENSSL_NO_EGD +# define OPENSSL_NO_EGD +#endif +#ifndef OPENSSL_NO_FUZZ_AFL +# define OPENSSL_NO_FUZZ_AFL +#endif +#ifndef OPENSSL_NO_FUZZ_LIBFUZZER +# define OPENSSL_NO_FUZZ_LIBFUZZER +#endif +#ifndef OPENSSL_NO_HEARTBEATS +# define OPENSSL_NO_HEARTBEATS +#endif +#ifndef OPENSSL_NO_MSAN +# define OPENSSL_NO_MSAN +#endif +#ifndef OPENSSL_NO_SCTP +# define OPENSSL_NO_SCTP +#endif +#ifndef OPENSSL_NO_SSL_TRACE +# define OPENSSL_NO_SSL_TRACE +#endif +#ifndef OPENSSL_NO_SSL3 +# define OPENSSL_NO_SSL3 +#endif +#ifndef OPENSSL_NO_SSL3_METHOD +# define OPENSSL_NO_SSL3_METHOD +#endif +#ifndef OPENSSL_NO_UBSAN +# define OPENSSL_NO_UBSAN +#endif +#ifndef OPENSSL_NO_UNIT_TEST +# define OPENSSL_NO_UNIT_TEST +#endif +#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +# define OPENSSL_NO_WEAK_SSL_CIPHERS +#endif +#ifndef OPENSSL_NO_AFALGENG +# define OPENSSL_NO_AFALGENG +#endif + + +/* + * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers + * don't like that. This will hopefully silence them. + */ +#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; + +/* + * Applications should use -DOPENSSL_API_COMPAT= to suppress the + * declarations of functions deprecated in or before . Otherwise, they + * still won't see them if the library has been built to disable deprecated + * functions. + */ +#if defined(OPENSSL_NO_DEPRECATED) +# define DECLARE_DEPRECATED(f) +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); +#else +# define DECLARE_DEPRECATED(f) f; +#endif + +#ifndef OPENSSL_FILE +# ifdef OPENSSL_NO_FILENAMES +# define OPENSSL_FILE "" +# define OPENSSL_LINE 0 +# else +# define OPENSSL_FILE __FILE__ +# define OPENSSL_LINE __LINE__ +# endif +#endif + +#ifndef OPENSSL_MIN_API +# define OPENSSL_MIN_API 0 +#endif + +#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API +# undef OPENSSL_API_COMPAT +# define OPENSSL_API_COMPAT OPENSSL_MIN_API +#endif + +#if OPENSSL_API_COMPAT < 0x10100000L +# define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_1_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x10000000L +# define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_0_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x00908000L +# define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_0_9_8(f) +#endif + +#define OPENSSL_CPUID_OBJ + +/* Generate 80386 code? */ +#undef I386_ONLY + +#undef OPENSSL_UNISTD +#define OPENSSL_UNISTD + +#define OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* + * The following are cipher-specific, but are part of the public API. + */ +#if !defined(OPENSSL_SYS_UEFI) +# undef BN_LLONG +/* Only one for the following should be defined */ +# undef SIXTY_FOUR_BIT_LONG +# define SIXTY_FOUR_BIT +# undef THIRTY_TWO_BIT +#endif + +#define RC4_INT unsigned int + +#ifdef __cplusplus +} +#endif diff --git a/compat/includes/openssl/sha.h b/compat/includes/openssl/sha.h new file mode 100644 index 0000000..6a1eb0d --- /dev/null +++ b/compat/includes/openssl/sha.h @@ -0,0 +1,119 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SHA_H +# define HEADER_SHA_H + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! SHA_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define SHA_LONG unsigned int + +# define SHA_LBLOCK 16 +# define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a + * contiguous array of 32 bit wide + * big-endian values. */ +# define SHA_LAST_BLOCK (SHA_CBLOCK-8) +# define SHA_DIGEST_LENGTH 20 + +typedef struct SHAstate_st { + SHA_LONG h0, h1, h2, h3, h4; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num; +} SHA_CTX; + +int SHA1_Init(SHA_CTX *c); +int SHA1_Update(SHA_CTX *c, const void *data, size_t len); +int SHA1_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); +void SHA1_Transform(SHA_CTX *c, const unsigned char *data); + +# define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a + * contiguous array of 32 bit wide + * big-endian values. */ + +typedef struct SHA256state_st { + SHA_LONG h[8]; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num, md_len; +} SHA256_CTX; + +int SHA224_Init(SHA256_CTX *c); +int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA224_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); +int SHA256_Init(SHA256_CTX *c); +int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA256_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); +void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); + +# define SHA224_DIGEST_LENGTH 28 +# define SHA256_DIGEST_LENGTH 32 +# define SHA384_DIGEST_LENGTH 48 +# define SHA512_DIGEST_LENGTH 64 + +/* + * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 + * being exactly 64-bit wide. See Implementation Notes in sha512.c + * for further details. + */ +/* + * SHA-512 treats input data as a + * contiguous array of 64 bit + * wide big-endian values. + */ +# define SHA512_CBLOCK (SHA_LBLOCK*8) +# if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) +# define SHA_LONG64 unsigned __int64 +# define U64(C) C##UI64 +# elif defined(__arch64__) +# define SHA_LONG64 unsigned long +# define U64(C) C##UL +# else +# define SHA_LONG64 unsigned long long +# define U64(C) C##ULL +# endif + +typedef struct SHA512state_st { + SHA_LONG64 h[8]; + SHA_LONG64 Nl, Nh; + union { + SHA_LONG64 d[SHA_LBLOCK]; + unsigned char p[SHA512_CBLOCK]; + } u; + unsigned int num, md_len; +} SHA512_CTX; + +int SHA384_Init(SHA512_CTX *c); +int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA384_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md); +int SHA512_Init(SHA512_CTX *c); +int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA512_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); +void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/compat/includes/pthreads/pthread.h b/compat/includes/pthreads/pthread.h new file mode 100644 index 0000000..eb2ad9d --- /dev/null +++ b/compat/includes/pthreads/pthread.h @@ -0,0 +1,1372 @@ +/* This is an implementation of the threads API of POSIX 1003.1-2001. + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This 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 of the License, or (at your option) any later version. + * + * This 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 this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +// undef for DLLs +#define PTW32_STATIC_LIB + + +#if !defined( PTHREAD_H ) +#define PTHREAD_H + +/* + * See the README file for an explanation of the pthreads-win32 version + * numbering scheme and how the DLL is named etc. + */ +#define PTW32_VERSION 2,9,1,0 +#define PTW32_VERSION_STRING "2, 9, 1, 0\0" + +/* There are three implementations of cancel cleanup. + * Note that pthread.h is included in both application + * compilation units and also internally for the library. + * The code here and within the library aims to work + * for all reasonable combinations of environments. + * + * The three implementations are: + * + * WIN32 SEH + * C + * C++ + * + * Please note that exiting a push/pop block via + * "return", "exit", "break", or "continue" will + * lead to different behaviour amongst applications + * depending upon whether the library was built + * using SEH, C++, or C. For example, a library built + * with SEH will call the cleanup routine, while both + * C++ and C built versions will not. + */ + +/* + * Define defaults for cleanup code. + * Note: Unless the build explicitly defines one of the following, then + * we default to standard C style cleanup. This style uses setjmp/longjmp + * in the cancelation and thread exit implementations and therefore won't + * do stack unwinding if linked to applications that have it (e.g. + * C++ apps). This is currently consistent with most/all commercial Unix + * POSIX threads implementations. + */ +#if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C ) +# define __CLEANUP_C +#endif + +#if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC)) +#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler. +#endif + +/* + * Stop here if we are being included by the resource compiler. + */ +#if !defined(RC_INVOKED) + +#undef PTW32_LEVEL + +#if defined(_POSIX_SOURCE) +#define PTW32_LEVEL 0 +/* Early POSIX */ +#endif + +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 +#undef PTW32_LEVEL +#define PTW32_LEVEL 1 +/* Include 1b, 1c and 1d */ +#endif + +#if defined(INCLUDE_NP) +#undef PTW32_LEVEL +#define PTW32_LEVEL 2 +/* Include Non-Portable extensions */ +#endif + +#define PTW32_LEVEL_MAX 3 + +#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_LEVEL) +#define PTW32_LEVEL PTW32_LEVEL_MAX +/* Include everything */ +#endif + +#if defined(_UWIN) +# define HAVE_STRUCT_TIMESPEC 1 +# define HAVE_SIGNAL_H 1 +# undef HAVE_PTW32_CONFIG_H +# pragma comment(lib, "pthread") +#endif + +/* + * ------------------------------------------------------------- + * + * + * Module: pthread.h + * + * Purpose: + * Provides an implementation of PThreads based upon the + * standard: + * + * POSIX 1003.1-2001 + * and + * The Single Unix Specification version 3 + * + * (these two are equivalent) + * + * in order to enhance code portability between Windows, + * various commercial Unix implementations, and Linux. + * + * See the ANNOUNCE file for a full list of conforming + * routines and defined constants, and a list of missing + * routines and constants not defined in this implementation. + * + * Authors: + * There have been many contributors to this library. + * The initial implementation was contributed by + * John Bossom, and several others have provided major + * sections or revisions of parts of the implementation. + * Often significant effort has been contributed to + * find and fix important bugs and other problems to + * improve the reliability of the library, which sometimes + * is not reflected in the amount of code which changed as + * result. + * As much as possible, the contributors are acknowledged + * in the ChangeLog file in the source code distribution + * where their changes are noted in detail. + * + * Contributors are listed in the CONTRIBUTORS file. + * + * As usual, all bouquets go to the contributors, and all + * brickbats go to the project maintainer. + * + * Maintainer: + * The code base for this project is coordinated and + * eventually pre-tested, packaged, and made available by + * + * Ross Johnson + * + * QA Testers: + * Ultimately, the library is tested in the real world by + * a host of competent and demanding scientists and + * engineers who report bugs and/or provide solutions + * which are then fixed or incorporated into subsequent + * versions of the library. Each time a bug is fixed, a + * test case is written to prove the fix and ensure + * that later changes to the code don't reintroduce the + * same error. The number of test cases is slowly growing + * and therefore so is the code reliability. + * + * Compliance: + * See the file ANNOUNCE for the list of implemented + * and not-implemented routines and defined options. + * Of course, these are all defined is this file as well. + * + * Web site: + * The source code and other information about this library + * are available from + * + * http://sources.redhat.com/pthreads-win32/ + * + * ------------------------------------------------------------- + */ + +/* Try to avoid including windows.h */ +#if (defined(__MINGW64__) || defined(__MINGW32__)) && defined(__cplusplus) +#define PTW32_INCLUDE_WINDOWS_H +#endif + +#if defined(PTW32_INCLUDE_WINDOWS_H) +#include +#endif + +#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__) +/* + * VC++6.0 or early compiler's header has no DWORD_PTR type. + */ +typedef unsigned long DWORD_PTR; +typedef unsigned long ULONG_PTR; +#endif +/* + * ----------------- + * autoconf switches + * ----------------- + */ + +#if defined(HAVE_PTW32_CONFIG_H) +#include "config.h" +#endif /* HAVE_PTW32_CONFIG_H */ + +#if !defined(NEED_FTIME) +#include +#else /* NEED_FTIME */ +/* use native WIN32 time API */ +#endif /* NEED_FTIME */ + +#if defined(HAVE_SIGNAL_H) +#include +#endif /* HAVE_SIGNAL_H */ + +#include + +/* + * Boolean values to make us independent of system includes. + */ +enum { + PTW32_FALSE = 0, + PTW32_TRUE = (! PTW32_FALSE) +}; + +/* + * This is a duplicate of what is in the autoconf config.h, + * which is only used when building the pthread-win32 libraries. + */ + +#if !defined(PTW32_CONFIG_H) +# if defined(WINCE) +# define NEED_ERRNO +# define NEED_SEM +# endif +# if defined(__MINGW64__) +# define HAVE_STRUCT_TIMESPEC +# define HAVE_MODE_T +# elif defined(_UWIN) || defined(__MINGW32__) +# define HAVE_MODE_T +# endif +#endif + +/* + * + */ + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX +#if defined(NEED_ERRNO) +#include "need_errno.h" +#else +#include +#endif +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +/* + * Several systems don't define some error numbers. + */ +#if !defined(ENOTSUP) +# define ENOTSUP 48 /* This is the value in Solaris. */ +#endif + +#if !defined(ETIMEDOUT) +# define ETIMEDOUT 10060 /* Same as WSAETIMEDOUT */ +#endif + +#if !defined(ENOSYS) +# define ENOSYS 140 /* Semi-arbitrary value */ +#endif + +#if !defined(EDEADLK) +# if defined(EDEADLOCK) +# define EDEADLK EDEADLOCK +# else +# define EDEADLK 36 /* This is the value in MSVC. */ +# endif +#endif + +/* POSIX 2008 - related to robust mutexes */ +#if !defined(EOWNERDEAD) +# define EOWNERDEAD 43 +#endif +#if !defined(ENOTRECOVERABLE) +# define ENOTRECOVERABLE 44 +#endif + +#include + +/* + * To avoid including windows.h we define only those things that we + * actually need from it. + */ +#if !defined(PTW32_INCLUDE_WINDOWS_H) +#if !defined(HANDLE) +# define PTW32__HANDLE_DEF +# define HANDLE void * +#endif +#if !defined(DWORD) +# define PTW32__DWORD_DEF +# define DWORD unsigned long +#endif +#endif + +#if !defined(HAVE_STRUCT_TIMESPEC) +#define HAVE_STRUCT_TIMESPEC +#if !defined(_TIMESPEC_DEFINED) +#define _TIMESPEC_DEFINED +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif /* _TIMESPEC_DEFINED */ +#endif /* HAVE_STRUCT_TIMESPEC */ + +#if !defined(SIG_BLOCK) +#define SIG_BLOCK 0 +#endif /* SIG_BLOCK */ + +#if !defined(SIG_UNBLOCK) +#define SIG_UNBLOCK 1 +#endif /* SIG_UNBLOCK */ + +#if !defined(SIG_SETMASK) +#define SIG_SETMASK 2 +#endif /* SIG_SETMASK */ + +#if defined(__cplusplus) +extern "C" +{ +#endif /* __cplusplus */ + +/* + * ------------------------------------------------------------- + * + * POSIX 1003.1-2001 Options + * ========================= + * + * Options are normally set in , which is not provided + * with pthreads-win32. + * + * For conformance with the Single Unix Specification (version 3), all of the + * options below are defined, and have a value of either -1 (not supported) + * or 200112L (supported). + * + * These options can neither be left undefined nor have a value of 0, because + * either indicates that sysconf(), which is not implemented, may be used at + * runtime to check the status of the option. + * + * _POSIX_THREADS (== 200112L) + * If == 200112L, you can use threads + * + * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L) + * If == 200112L, you can control the size of a thread's + * stack + * pthread_attr_getstacksize + * pthread_attr_setstacksize + * + * _POSIX_THREAD_ATTR_STACKADDR (== -1) + * If == 200112L, you can allocate and control a thread's + * stack. If not supported, the following functions + * will return ENOSYS, indicating they are not + * supported: + * pthread_attr_getstackaddr + * pthread_attr_setstackaddr + * + * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1) + * If == 200112L, you can use realtime scheduling. + * This option indicates that the behaviour of some + * implemented functions conforms to the additional TPS + * requirements in the standard. E.g. rwlocks favour + * writers over readers when threads have equal priority. + * + * _POSIX_THREAD_PRIO_INHERIT (== -1) + * If == 200112L, you can create priority inheritance + * mutexes. + * pthread_mutexattr_getprotocol + + * pthread_mutexattr_setprotocol + + * + * _POSIX_THREAD_PRIO_PROTECT (== -1) + * If == 200112L, you can create priority ceiling mutexes + * Indicates the availability of: + * pthread_mutex_getprioceiling + * pthread_mutex_setprioceiling + * pthread_mutexattr_getprioceiling + * pthread_mutexattr_getprotocol + + * pthread_mutexattr_setprioceiling + * pthread_mutexattr_setprotocol + + * + * _POSIX_THREAD_PROCESS_SHARED (== -1) + * If set, you can create mutexes and condition + * variables that can be shared with another + * process.If set, indicates the availability + * of: + * pthread_mutexattr_getpshared + * pthread_mutexattr_setpshared + * pthread_condattr_getpshared + * pthread_condattr_setpshared + * + * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L) + * If == 200112L you can use the special *_r library + * functions that provide thread-safe behaviour + * + * _POSIX_READER_WRITER_LOCKS (== 200112L) + * If == 200112L, you can use read/write locks + * + * _POSIX_SPIN_LOCKS (== 200112L) + * If == 200112L, you can use spin locks + * + * _POSIX_BARRIERS (== 200112L) + * If == 200112L, you can use barriers + * + * + These functions provide both 'inherit' and/or + * 'protect' protocol, based upon these macro + * settings. + * + * ------------------------------------------------------------- + */ + +/* + * POSIX Options + */ +#undef _POSIX_THREADS +#define _POSIX_THREADS 200809L + +#undef _POSIX_READER_WRITER_LOCKS +#define _POSIX_READER_WRITER_LOCKS 200809L + +#undef _POSIX_SPIN_LOCKS +#define _POSIX_SPIN_LOCKS 200809L + +#undef _POSIX_BARRIERS +#define _POSIX_BARRIERS 200809L + +#undef _POSIX_THREAD_SAFE_FUNCTIONS +#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L + +#undef _POSIX_THREAD_ATTR_STACKSIZE +#define _POSIX_THREAD_ATTR_STACKSIZE 200809L + +/* + * The following options are not supported + */ +#undef _POSIX_THREAD_ATTR_STACKADDR +#define _POSIX_THREAD_ATTR_STACKADDR -1 + +#undef _POSIX_THREAD_PRIO_INHERIT +#define _POSIX_THREAD_PRIO_INHERIT -1 + +#undef _POSIX_THREAD_PRIO_PROTECT +#define _POSIX_THREAD_PRIO_PROTECT -1 + +/* TPS is not fully supported. */ +#undef _POSIX_THREAD_PRIORITY_SCHEDULING +#define _POSIX_THREAD_PRIORITY_SCHEDULING -1 + +#undef _POSIX_THREAD_PROCESS_SHARED +#define _POSIX_THREAD_PROCESS_SHARED -1 + + +/* + * POSIX 1003.1-2001 Limits + * =========================== + * + * These limits are normally set in , which is not provided with + * pthreads-win32. + * + * PTHREAD_DESTRUCTOR_ITERATIONS + * Maximum number of attempts to destroy + * a thread's thread-specific data on + * termination (must be at least 4) + * + * PTHREAD_KEYS_MAX + * Maximum number of thread-specific data keys + * available per process (must be at least 128) + * + * PTHREAD_STACK_MIN + * Minimum supported stack size for a thread + * + * PTHREAD_THREADS_MAX + * Maximum number of threads supported per + * process (must be at least 64). + * + * SEM_NSEMS_MAX + * The maximum number of semaphores a process can have. + * (must be at least 256) + * + * SEM_VALUE_MAX + * The maximum value a semaphore can have. + * (must be at least 32767) + * + */ +#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 + +#undef PTHREAD_DESTRUCTOR_ITERATIONS +#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS + +#undef _POSIX_THREAD_KEYS_MAX +#define _POSIX_THREAD_KEYS_MAX 128 + +#undef PTHREAD_KEYS_MAX +#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX + +#undef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 0 + +#undef _POSIX_THREAD_THREADS_MAX +#define _POSIX_THREAD_THREADS_MAX 64 + + /* Arbitrary value */ +#undef PTHREAD_THREADS_MAX +#define PTHREAD_THREADS_MAX 2019 + +#undef _POSIX_SEM_NSEMS_MAX +#define _POSIX_SEM_NSEMS_MAX 256 + + /* Arbitrary value */ +#undef SEM_NSEMS_MAX +#define SEM_NSEMS_MAX 1024 + +#undef _POSIX_SEM_VALUE_MAX +#define _POSIX_SEM_VALUE_MAX 32767 + +#undef SEM_VALUE_MAX +#define SEM_VALUE_MAX INT_MAX + + +#if defined(__GNUC__) && !defined(__declspec) +# error Please upgrade your GNU compiler to one that supports __declspec. +#endif + +/* + * When building the library, you should define PTW32_BUILD so that + * the variables/functions are exported correctly. When using the library, + * do NOT define PTW32_BUILD, and then the variables/functions will + * be imported correctly. + */ +#if !defined(PTW32_STATIC_LIB) +# if defined(PTW32_BUILD) +# define PTW32_DLLPORT __declspec (dllexport) +# else +# define PTW32_DLLPORT __declspec (dllimport) +# endif +#else +# define PTW32_DLLPORT +#endif + +/* + * The Open Watcom C/C++ compiler uses a non-standard calling convention + * that passes function args in registers unless __cdecl is explicitly specified + * in exposed function prototypes. + * + * We force all calls to cdecl even though this could slow Watcom code down + * slightly. If you know that the Watcom compiler will be used to build both + * the DLL and application, then you can probably define this as a null string. + * Remember that pthread.h (this file) is used for both the DLL and application builds. + */ +#define PTW32_CDECL __cdecl + +#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX +# include +#else +/* + * Generic handle type - intended to extend uniqueness beyond + * that available with a simple pointer. It should scale for either + * IA-32 or IA-64. + */ +typedef struct { + void * p; /* Pointer to actual object */ + unsigned int x; /* Extra information - reuse count etc */ +} ptw32_handle_t; + +typedef ptw32_handle_t pthread_t; +typedef struct pthread_attr_t_ * pthread_attr_t; +typedef struct pthread_once_t_ pthread_once_t; +typedef struct pthread_key_t_ * pthread_key_t; +typedef struct pthread_mutex_t_ * pthread_mutex_t; +typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t; +typedef struct pthread_cond_t_ * pthread_cond_t; +typedef struct pthread_condattr_t_ * pthread_condattr_t; +#endif +typedef struct pthread_rwlock_t_ * pthread_rwlock_t; +typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t; +typedef struct pthread_spinlock_t_ * pthread_spinlock_t; +typedef struct pthread_barrier_t_ * pthread_barrier_t; +typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t; + +/* + * ==================== + * ==================== + * POSIX Threads + * ==================== + * ==================== + */ + +enum { +/* + * pthread_attr_{get,set}detachstate + */ + PTHREAD_CREATE_JOINABLE = 0, /* Default */ + PTHREAD_CREATE_DETACHED = 1, + +/* + * pthread_attr_{get,set}inheritsched + */ + PTHREAD_INHERIT_SCHED = 0, + PTHREAD_EXPLICIT_SCHED = 1, /* Default */ + +/* + * pthread_{get,set}scope + */ + PTHREAD_SCOPE_PROCESS = 0, + PTHREAD_SCOPE_SYSTEM = 1, /* Default */ + +/* + * pthread_setcancelstate paramters + */ + PTHREAD_CANCEL_ENABLE = 0, /* Default */ + PTHREAD_CANCEL_DISABLE = 1, + +/* + * pthread_setcanceltype parameters + */ + PTHREAD_CANCEL_ASYNCHRONOUS = 0, + PTHREAD_CANCEL_DEFERRED = 1, /* Default */ + +/* + * pthread_mutexattr_{get,set}pshared + * pthread_condattr_{get,set}pshared + */ + PTHREAD_PROCESS_PRIVATE = 0, + PTHREAD_PROCESS_SHARED = 1, + +/* + * pthread_mutexattr_{get,set}robust + */ + PTHREAD_MUTEX_STALLED = 0, /* Default */ + PTHREAD_MUTEX_ROBUST = 1, + +/* + * pthread_barrier_wait + */ + PTHREAD_BARRIER_SERIAL_THREAD = -1 +}; + +/* + * ==================== + * ==================== + * Cancelation + * ==================== + * ==================== + */ +#define PTHREAD_CANCELED ((void *)(size_t) -1) + + +/* + * ==================== + * ==================== + * Once Key + * ==================== + * ==================== + */ +#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0} + +struct pthread_once_t_ +{ + int done; /* indicates if user function has been executed */ + void * lock; + int reserved1; + int reserved2; +}; + + +/* + * ==================== + * ==================== + * Object initialisers + * ==================== + * ==================== + */ +#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -1) +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -2) +#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -3) + +/* + * Compatibility with LinuxThreads + */ +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER +#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER + +#define PTHREAD_COND_INITIALIZER ((pthread_cond_t)(size_t) -1) + +#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t)(size_t) -1) + +#define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t)(size_t) -1) + + +/* + * Mutex types. + */ +enum +{ + /* Compatibility with LinuxThreads */ + PTHREAD_MUTEX_FAST_NP, + PTHREAD_MUTEX_RECURSIVE_NP, + PTHREAD_MUTEX_ERRORCHECK_NP, + PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP, + PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP, + /* For compatibility with POSIX */ + PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP, + PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, + PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, + PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL +}; + + +typedef struct ptw32_cleanup_t ptw32_cleanup_t; + +#if defined(_MSC_VER) +/* Disable MSVC 'anachronism used' warning */ +#pragma warning( disable : 4229 ) +#endif + +typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *); + +#if defined(_MSC_VER) +#pragma warning( default : 4229 ) +#endif + +struct ptw32_cleanup_t +{ + ptw32_cleanup_callback_t routine; + void *arg; + struct ptw32_cleanup_t *prev; +}; + +#if defined(__CLEANUP_SEH) + /* + * WIN32 SEH version of cancel cleanup. + */ + +#define pthread_cleanup_push( _rout, _arg ) \ + { \ + ptw32_cleanup_t _cleanup; \ + \ + _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \ + _cleanup.arg = (_arg); \ + __try \ + { \ + +#define pthread_cleanup_pop( _execute ) \ + } \ + __finally \ + { \ + if( _execute || AbnormalTermination()) \ + { \ + (*(_cleanup.routine))( _cleanup.arg ); \ + } \ + } \ + } + +#else /* __CLEANUP_SEH */ + +#if defined(__CLEANUP_C) + + /* + * C implementation of PThreads cancel cleanup + */ + +#define pthread_cleanup_push( _rout, _arg ) \ + { \ + ptw32_cleanup_t _cleanup; \ + \ + ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \ + +#define pthread_cleanup_pop( _execute ) \ + (void) ptw32_pop_cleanup( _execute ); \ + } + +#else /* __CLEANUP_C */ + +#if defined(__CLEANUP_CXX) + + /* + * C++ version of cancel cleanup. + * - John E. Bossom. + */ + + class PThreadCleanup { + /* + * PThreadCleanup + * + * Purpose + * This class is a C++ helper class that is + * used to implement pthread_cleanup_push/ + * pthread_cleanup_pop. + * The destructor of this class automatically + * pops the pushed cleanup routine regardless + * of how the code exits the scope + * (i.e. such as by an exception) + */ + ptw32_cleanup_callback_t cleanUpRout; + void * obj; + int executeIt; + + public: + PThreadCleanup() : + cleanUpRout( 0 ), + obj( 0 ), + executeIt( 0 ) + /* + * No cleanup performed + */ + { + } + + PThreadCleanup( + ptw32_cleanup_callback_t routine, + void * arg ) : + cleanUpRout( routine ), + obj( arg ), + executeIt( 1 ) + /* + * Registers a cleanup routine for 'arg' + */ + { + } + + ~PThreadCleanup() + { + if ( executeIt && ((void *) cleanUpRout != (void *) 0) ) + { + (void) (*cleanUpRout)( obj ); + } + } + + void execute( int exec ) + { + executeIt = exec; + } + }; + + /* + * C++ implementation of PThreads cancel cleanup; + * This implementation takes advantage of a helper + * class who's destructor automatically calls the + * cleanup routine if we exit our scope weirdly + */ +#define pthread_cleanup_push( _rout, _arg ) \ + { \ + PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \ + (void *) (_arg) ); + +#define pthread_cleanup_pop( _execute ) \ + cleanup.execute( _execute ); \ + } + +#else + +#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. + +#endif /* __CLEANUP_CXX */ + +#endif /* __CLEANUP_C */ + +#endif /* __CLEANUP_SEH */ + +/* + * =============== + * =============== + * Methods + * =============== + * =============== + */ + +/* + * PThread Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr, + int *detachstate); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr, + void **stackaddr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr, + size_t * stacksize); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr, + int detachstate); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr, + void *stackaddr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr, + size_t stacksize); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr, + struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr, + const struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *, + int); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (const pthread_attr_t *, + int *); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr, + int inheritsched); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(const pthread_attr_t * attr, + int * inheritsched); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *, + int); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *, + int *); + +/* + * PThread Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid, + const pthread_attr_t * attr, + void *(PTW32_CDECL *start) (void *), + void *arg); + +PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid); + +PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1, + pthread_t t2); + +PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr); + +PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread, + void **value_ptr); + +PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void); + +PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread); + +PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state, + int *oldstate); + +PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type, + int *oldtype); + +PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void); + +PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control, + void (PTW32_CDECL *init_routine) (void)); + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX +PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute); + +PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, + ptw32_cleanup_callback_t routine, + void *arg); +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +/* + * Thread Specific Data Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key, + void (PTW32_CDECL *destructor) (void *)); + +PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key); + +PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key, + const void *value); + +PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key); + + +/* + * Mutex Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t + * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, + int pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setrobust( + pthread_mutexattr_t *attr, + int robust); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getrobust( + const pthread_mutexattr_t * attr, + int * robust); + +/* + * Barrier Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t + * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, + int pshared); + +/* + * Mutex Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex, + const pthread_mutexattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t * mutex, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_consistent (pthread_mutex_t * mutex); + +/* + * Spinlock Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock); + +/* + * Barrier Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier, + const pthread_barrierattr_t * attr, + unsigned int count); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier); + +/* + * Condition Variable Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr, + int pshared); + +/* + * Condition Variable Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond, + const pthread_condattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond, + pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond, + pthread_mutex_t * mutex, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond); + +/* + * Scheduling + */ +PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread, + int policy, + const struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread, + int *policy, + struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int); + +PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void); + +/* + * Read-Write Lock Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, + const pthread_rwlockattr_t *attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, + int pshared); + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 + +/* + * Signal Functions. Should be defined in but MSVC and MinGW32 + * already have signal.h that don't define these. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); + +/* + * Non-portable functions + */ + +/* + * Compatibility with Linux. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, + int kind); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, + int *kind); + +/* + * Possibly supported by other POSIX threads implementations + */ +PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); +PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); +PTW32_DLLPORT unsigned __int64 PTW32_CDECL pthread_getunique_np(pthread_t thread); + +/* + * Useful if an application wants to statically link + * the lib rather than load the DLL at run-time. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void); + +/* + * Features that are auto-detected at load/run time. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int); +enum ptw32_features { + PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */ + PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */ +}; + +/* + * Register a system time change with the library. + * Causes the library to perform various functions + * in response to the change. Should be called whenever + * the application's top level window receives a + * WM_TIMECHANGE message. It can be passed directly to + * pthread_create() as a new thread if desired. + */ +PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *); + +#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */ + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX + +/* + * Returns the Win32 HANDLE for the POSIX thread. + */ +PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread); +/* + * Returns the win32 thread ID for POSIX thread. + */ +PTW32_DLLPORT DWORD PTW32_CDECL pthread_getw32threadid_np (pthread_t thread); + + +/* + * Protected Methods + * + * This function blocks until the given WIN32 handle + * is signaled or pthread_cancel had been called. + * This function allows the caller to hook into the + * PThreads cancel mechanism. It is implemented using + * + * WaitForMultipleObjects + * + * on 'waitHandle' and a manually reset WIN32 Event + * used to implement pthread_cancel. The 'timeout' + * argument to TimedWait is simply passed to + * WaitForMultipleObjects. + */ +PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle); +PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle, + DWORD timeout); + +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +/* + * Thread-Safe C Runtime Library Mappings. + */ +#if !defined(_UWIN) +# if defined(NEED_ERRNO) + PTW32_DLLPORT int * PTW32_CDECL _errno( void ); +# else +# if !defined(errno) +# if (defined(_MT) || defined(_DLL)) + __declspec(dllimport) extern int * __cdecl _errno(void); +# define errno (*_errno()) +# endif +# endif +# endif +#endif + +/* + * Some compiler environments don't define some things. + */ +#if defined(__BORLANDC__) +# define _ftime ftime +# define _timeb timeb +#endif + +#if defined(__cplusplus) + +/* + * Internal exceptions + */ +class ptw32_exception {}; +class ptw32_exception_cancel : public ptw32_exception {}; +class ptw32_exception_exit : public ptw32_exception {}; + +#endif + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX + +/* FIXME: This is only required if the library was built using SEH */ +/* + * Get internal SEH tag + */ +PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); + +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +#if !defined(PTW32_BUILD) + +#if defined(__CLEANUP_SEH) + +/* + * Redefine the SEH __except keyword to ensure that applications + * propagate our internal exceptions up to the library's internal handlers. + */ +#define __except( E ) \ + __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \ + ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) + +#endif /* __CLEANUP_SEH */ + +#if defined(__CLEANUP_CXX) + +/* + * Redefine the C++ catch keyword to ensure that applications + * propagate our internal exceptions up to the library's internal handlers. + */ +#if defined(_MSC_VER) + /* + * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' + * if you want Pthread-Win32 cancelation and pthread_exit to work. + */ + +#if !defined(PtW32NoCatchWarn) + +#pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.") +#pragma message("------------------------------------------------------------------") +#pragma message("When compiling applications with MSVC++ and C++ exception handling:") +#pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads") +#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") +#pragma message(" cancelation and pthread_exit to work. For example:") +#pragma message("") +#pragma message(" #if defined(PtW32CatchAll)") +#pragma message(" PtW32CatchAll") +#pragma message(" #else") +#pragma message(" catch(...)") +#pragma message(" #endif") +#pragma message(" {") +#pragma message(" /* Catchall block processing */") +#pragma message(" }") +#pragma message("------------------------------------------------------------------") + +#endif + +#define PtW32CatchAll \ + catch( ptw32_exception & ) { throw; } \ + catch( ... ) + +#else /* _MSC_VER */ + +#define catch( E ) \ + catch( ptw32_exception & ) { throw; } \ + catch( E ) + +#endif /* _MSC_VER */ + +#endif /* __CLEANUP_CXX */ + +#endif /* ! PTW32_BUILD */ + +#if defined(__cplusplus) +} /* End of extern "C" */ +#endif /* __cplusplus */ + +#if defined(PTW32__HANDLE_DEF) +# undef HANDLE +#endif +#if defined(PTW32__DWORD_DEF) +# undef DWORD +#endif + +#undef PTW32_LEVEL +#undef PTW32_LEVEL_MAX + +#endif /* ! RC_INVOKED */ + +#endif /* PTHREAD_H */ diff --git a/compat/includes/pthreads/sched.h b/compat/includes/pthreads/sched.h new file mode 100644 index 0000000..e25eb56 --- /dev/null +++ b/compat/includes/pthreads/sched.h @@ -0,0 +1,183 @@ +/* + * Module: sched.h + * + * Purpose: + * Provides an implementation of POSIX realtime extensions + * as defined in + * + * POSIX 1003.1b-1993 (POSIX.1b) + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This 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 of the License, or (at your option) any later version. + * + * This 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 this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(_SCHED_H) +#define _SCHED_H + +#undef PTW32_SCHED_LEVEL + +#if defined(_POSIX_SOURCE) +#define PTW32_SCHED_LEVEL 0 +/* Early POSIX */ +#endif + +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 +#undef PTW32_SCHED_LEVEL +#define PTW32_SCHED_LEVEL 1 +/* Include 1b, 1c and 1d */ +#endif + +#if defined(INCLUDE_NP) +#undef PTW32_SCHED_LEVEL +#define PTW32_SCHED_LEVEL 2 +/* Include Non-Portable extensions */ +#endif + +#define PTW32_SCHED_LEVEL_MAX 3 + +#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL) +#define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX +/* Include everything */ +#endif + + +#if defined(__GNUC__) && !defined(__declspec) +# error Please upgrade your GNU compiler to one that supports __declspec. +#endif + +/* + * When building the library, you should define PTW32_BUILD so that + * the variables/functions are exported correctly. When using the library, + * do NOT define PTW32_BUILD, and then the variables/functions will + * be imported correctly. + */ +#if !defined(PTW32_STATIC_LIB) +# if defined(PTW32_BUILD) +# define PTW32_DLLPORT __declspec (dllexport) +# else +# define PTW32_DLLPORT __declspec (dllimport) +# endif +#else +# define PTW32_DLLPORT +#endif + +/* + * This is a duplicate of what is in the autoconf config.h, + * which is only used when building the pthread-win32 libraries. + */ + +#if !defined(PTW32_CONFIG_H) +# if defined(WINCE) +# define NEED_ERRNO +# define NEED_SEM +# endif +# if defined(__MINGW64__) +# define HAVE_STRUCT_TIMESPEC +# define HAVE_MODE_T +# elif defined(_UWIN) || defined(__MINGW32__) +# define HAVE_MODE_T +# endif +#endif + +/* + * + */ + +#if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX +#if defined(NEED_ERRNO) +#include "need_errno.h" +#else +#include +#endif +#endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */ + +#if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN) +# if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX +/* For pid_t */ +# include +/* Required by Unix 98 */ +# include +# else + typedef int pid_t; +# endif +#else + typedef int pid_t; +#endif + +/* Thread scheduling policies */ + +enum { + SCHED_OTHER = 0, + SCHED_FIFO, + SCHED_RR, + SCHED_MIN = SCHED_OTHER, + SCHED_MAX = SCHED_RR +}; + +struct sched_param { + int sched_priority; +}; + +#if defined(__cplusplus) +extern "C" +{ +#endif /* __cplusplus */ + +PTW32_DLLPORT int __cdecl sched_yield (void); + +PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy); + +PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy); + +PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy); + +PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid); + +/* + * Note that this macro returns ENOTSUP rather than + * ENOSYS as might be expected. However, returning ENOSYS + * should mean that sched_get_priority_{min,max} are + * not implemented as well as sched_rr_get_interval. + * This is not the case, since we just don't support + * round-robin scheduling. Therefore I have chosen to + * return the same value as sched_setscheduler when + * SCHED_RR is passed to it. + */ +#define sched_rr_get_interval(_pid, _interval) \ + ( errno = ENOTSUP, (int) -1 ) + + +#if defined(__cplusplus) +} /* End of extern "C" */ +#endif /* __cplusplus */ + +#undef PTW32_SCHED_LEVEL +#undef PTW32_SCHED_LEVEL_MAX + +#endif /* !_SCHED_H */ + diff --git a/compat/includes/zlib/zconf.h b/compat/includes/zlib/zconf.h new file mode 100644 index 0000000..add1675 --- /dev/null +++ b/compat/includes/zlib/zconf.h @@ -0,0 +1,511 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2013 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_bits z__tr_flush_bits +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzvprintf z_gzvprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateGetDictionary z_inflateGetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# elif (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# elif (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +# include /* for va_list */ +# endif +#endif + +#ifdef _WIN32 +# ifndef Z_SOLO +# include /* for wchar_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/compat/includes/zlib/zlib.h b/compat/includes/zlib/zlib.h new file mode 100644 index 0000000..1d98298 --- /dev/null +++ b/compat/includes/zlib/zlib.h @@ -0,0 +1,1768 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.8, April 28th, 2013 + + Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.8" +#define ZLIB_VERNUM 0x1280 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 8 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ + + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). Then deflate is guaranteed to + return Z_STREAM_END. If not enough output space is provided, deflate will + not return Z_STREAM_END, and it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + producted so far. The CRC-32 is checked against the gzip trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurrences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, + z_const unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + +#ifndef Z_SOLO + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + +#endif /* !Z_SOLO */ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +#ifdef Z_PREFIX_SET +# undef z_gzgetc +# define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#else +# define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#endif + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#ifdef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#if defined(_WIN32) && !defined(Z_SOLO) +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, + const char *mode)); +#endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, + const char *format, + va_list va)); +# endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/compat/jansson/Makefile.am b/compat/jansson/Makefile.am index ff38e51..324219d 100644 --- a/compat/jansson/Makefile.am +++ b/compat/jansson/Makefile.am @@ -1,18 +1,22 @@ - -noinst_LIBRARIES = libjansson.a - -libjansson_a_SOURCES = \ - config.h \ - dump.c \ - hashtable.c \ - hashtable.h \ - jansson.h \ - jansson_private.h \ - load.c \ - strbuffer.c \ - strbuffer.h \ - utf.c \ - utf.h \ - util.h \ - value.c - +noinst_LIBRARIES = libjansson.a + +libjansson_a_SOURCES = \ + config.h \ + dump.c \ + error.c \ + hashtable.c \ + hashtable.h \ + jansson.h \ + jansson_config.h \ + jansson_private.h \ + load.c \ + memory.c \ + pack_unpack.c \ + strbuffer.c \ + strbuffer.h \ + strconv.c \ + utf.c \ + utf.h \ + util.h \ + value.c + diff --git a/compat/jansson/Makefile.in b/compat/jansson/Makefile.in deleted file mode 100644 index 010caa2..0000000 --- a/compat/jansson/Makefile.in +++ /dev/null @@ -1,478 +0,0 @@ -# Makefile.in generated by automake 1.11.3 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software -# Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -target_triplet = @target@ -subdir = compat/jansson -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/cpuminer-config.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -LIBRARIES = $(noinst_LIBRARIES) -AR = ar -ARFLAGS = cru -libjansson_a_AR = $(AR) $(ARFLAGS) -libjansson_a_LIBADD = -am_libjansson_a_OBJECTS = dump.$(OBJEXT) hashtable.$(OBJEXT) \ - load.$(OBJEXT) strbuffer.$(OBJEXT) utf.$(OBJEXT) \ - value.$(OBJEXT) -libjansson_a_OBJECTS = $(am_libjansson_a_OBJECTS) -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(libjansson_a_SOURCES) -DIST_SOURCES = $(libjansson_a_SOURCES) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -ALLOCA = @ALLOCA@ -AMTAR = @AMTAR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCAS = @CCAS@ -CCASDEPMODE = @CCASDEPMODE@ -CCASFLAGS = @CCASFLAGS@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CUDA_CFLAGS = @CUDA_CFLAGS@ -CUDA_LDFLAGS = @CUDA_LDFLAGS@ -CUDA_LIBS = @CUDA_LIBS@ -CXX = @CXX@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -GREP = @GREP@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -JANSSON_LIBS = @JANSSON_LIBS@ -LDFLAGS = @LDFLAGS@ -LIBCURL = @LIBCURL@ -LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LTLIBOBJS = @LTLIBOBJS@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MKDIR_P = @MKDIR_P@ -NVCC = @NVCC@ -OBJEXT = @OBJEXT@ -OPENMP_CFLAGS = @OPENMP_CFLAGS@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_URL = @PACKAGE_URL@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -PTHREAD_FLAGS = @PTHREAD_FLAGS@ -PTHREAD_LIBS = @PTHREAD_LIBS@ -RANLIB = @RANLIB@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -WS2_LIBS = @WS2_LIBS@ -_libcurl_config = @_libcurl_config@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target = @target@ -target_alias = @target_alias@ -target_cpu = @target_cpu@ -target_os = @target_os@ -target_vendor = @target_vendor@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -noinst_LIBRARIES = libjansson.a -libjansson_a_SOURCES = \ - config.h \ - dump.c \ - hashtable.c \ - hashtable.h \ - jansson.h \ - jansson_private.h \ - load.c \ - strbuffer.c \ - strbuffer.h \ - utf.c \ - utf.h \ - util.h \ - value.c - -all: all-am - -.SUFFIXES: -.SUFFIXES: .c .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu compat/jansson/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu compat/jansson/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(am__aclocal_m4_deps): - -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) -libjansson.a: $(libjansson_a_OBJECTS) $(libjansson_a_DEPENDENCIES) $(EXTRA_libjansson_a_DEPENDENCIES) - -rm -f libjansson.a - $(libjansson_a_AR) libjansson.a $(libjansson_a_OBJECTS) $(libjansson_a_LIBADD) - $(RANLIB) libjansson.a - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dump.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashtable.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/load.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strbuffer.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utf.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/value.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c $< - -.c.obj: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - set x; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - shift; \ - if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - if test $$# -gt 0; then \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - "$$@" $$unique; \ - else \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$unique; \ - fi; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) "$$here" - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(LIBRARIES) -installdirs: -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -html-am: - -info: info-am - -info-am: - -install-data-am: - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: - -install-html: install-html-am - -install-html-am: - -install-info: install-info-am - -install-info-am: - -install-man: - -install-pdf: install-pdf-am - -install-pdf-am: - -install-ps: install-ps-am - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: - -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-noinstLIBRARIES ctags distclean distclean-compile \ - distclean-generic distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ - uninstall-am - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/compat/jansson/dump.c b/compat/jansson/dump.c index a8c9cc6..3b19c73 100644 --- a/compat/jansson/dump.c +++ b/compat/jansson/dump.c @@ -1,460 +1,456 @@ -/* - * Copyright (c) 2009, 2010 Petri Lehtinen - * - * Jansson is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See LICENSE for details. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include - -#include -#include "jansson_private.h" -#include "strbuffer.h" -#include "utf.h" - -#define MAX_INTEGER_STR_LENGTH 100 -#define MAX_REAL_STR_LENGTH 100 - -typedef int (*dump_func)(const char *buffer, int size, void *data); - -struct string -{ - char *buffer; - int length; - int size; -}; - -static int dump_to_strbuffer(const char *buffer, int size, void *data) -{ - return strbuffer_append_bytes((strbuffer_t *)data, buffer, size); -} - -static int dump_to_file(const char *buffer, int size, void *data) -{ - FILE *dest = (FILE *)data; - if(fwrite(buffer, size, 1, dest) != 1) - return -1; - return 0; -} - -/* 256 spaces (the maximum indentation size) */ -static char whitespace[] = " "; - -static int dump_indent(unsigned long flags, int depth, int space, dump_func dump, void *data) -{ - if(JSON_INDENT(flags) > 0) - { - int i, ws_count = JSON_INDENT(flags); - - if(dump("\n", 1, data)) - return -1; - - for(i = 0; i < depth; i++) - { - if(dump(whitespace, ws_count, data)) - return -1; - } - } - else if(space && !(flags & JSON_COMPACT)) - { - return dump(" ", 1, data); - } - return 0; -} - -static int dump_string(const char *str, int ascii, dump_func dump, void *data) -{ - const char *pos, *end; - int32_t codepoint; - - if(dump("\"", 1, data)) - return -1; - - end = pos = str; - while(1) - { - const char *text; - char seq[13]; - int length; - - while(*end) - { - end = utf8_iterate(pos, &codepoint); - if(!end) - return -1; - - /* mandatory escape or control char */ - if(codepoint == '\\' || codepoint == '"' || codepoint < 0x20) - break; - - /* non-ASCII */ - if(ascii && codepoint > 0x7F) - break; - - pos = end; - } - - if(pos != str) { - if(dump(str, pos - str, data)) - return -1; - } - - if(end == pos) - break; - - /* handle \, ", and control codes */ - length = 2; - switch(codepoint) - { - case '\\': text = "\\\\"; break; - case '\"': text = "\\\""; break; - case '\b': text = "\\b"; break; - case '\f': text = "\\f"; break; - case '\n': text = "\\n"; break; - case '\r': text = "\\r"; break; - case '\t': text = "\\t"; break; - default: - { - /* codepoint is in BMP */ - if(codepoint < 0x10000) - { - sprintf(seq, "\\u%04x", codepoint); - length = 6; - } - - /* not in BMP -> construct a UTF-16 surrogate pair */ - else - { - int32_t first, last; - - codepoint -= 0x10000; - first = 0xD800 | ((codepoint & 0xffc00) >> 10); - last = 0xDC00 | (codepoint & 0x003ff); - - sprintf(seq, "\\u%04x\\u%04x", first, last); - length = 12; - } - - text = seq; - break; - } - } - - if(dump(text, length, data)) - return -1; - - str = pos = end; - } - - return dump("\"", 1, data); -} - -static int object_key_compare_keys(const void *key1, const void *key2) -{ - return strcmp((*(const object_key_t **)key1)->key, - (*(const object_key_t **)key2)->key); -} - -static int object_key_compare_serials(const void *key1, const void *key2) -{ - return (*(const object_key_t **)key1)->serial - - (*(const object_key_t **)key2)->serial; -} - -static int do_dump(const json_t *json, unsigned long flags, int depth, - dump_func dump, void *data) -{ - int ascii = flags & JSON_ENSURE_ASCII ? 1 : 0; - - switch(json_typeof(json)) { - case JSON_NULL: - return dump("null", 4, data); - - case JSON_TRUE: - return dump("true", 4, data); - - case JSON_FALSE: - return dump("false", 5, data); - - case JSON_INTEGER: - { - char buffer[MAX_INTEGER_STR_LENGTH]; - int size; - - size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%d", json_integer_value(json)); - if(size >= MAX_INTEGER_STR_LENGTH) - return -1; - - return dump(buffer, size, data); - } - - case JSON_REAL: - { - char buffer[MAX_REAL_STR_LENGTH]; - int size; - - size = snprintf(buffer, MAX_REAL_STR_LENGTH, "%.17g", - json_real_value(json)); - if(size >= MAX_REAL_STR_LENGTH) - return -1; - - /* Make sure there's a dot or 'e' in the output. Otherwise - a real is converted to an integer when decoding */ - if(strchr(buffer, '.') == NULL && - strchr(buffer, 'e') == NULL) - { - if(size + 2 >= MAX_REAL_STR_LENGTH) { - /* No space to append ".0" */ - return -1; - } - buffer[size] = '.'; - buffer[size + 1] = '0'; - size += 2; - } - - return dump(buffer, size, data); - } - - case JSON_STRING: - return dump_string(json_string_value(json), ascii, dump, data); - - case JSON_ARRAY: - { - int i; - int n; - json_array_t *array; - - /* detect circular references */ - array = json_to_array(json); - if(array->visited) - goto array_error; - array->visited = 1; - - n = json_array_size(json); - - if(dump("[", 1, data)) - goto array_error; - if(n == 0) { - array->visited = 0; - return dump("]", 1, data); - } - if(dump_indent(flags, depth + 1, 0, dump, data)) - goto array_error; - - for(i = 0; i < n; ++i) { - if(do_dump(json_array_get(json, i), flags, depth + 1, - dump, data)) - goto array_error; - - if(i < n - 1) - { - if(dump(",", 1, data) || - dump_indent(flags, depth + 1, 1, dump, data)) - goto array_error; - } - else - { - if(dump_indent(flags, depth, 0, dump, data)) - goto array_error; - } - } - - array->visited = 0; - return dump("]", 1, data); - - array_error: - array->visited = 0; - return -1; - } - - case JSON_OBJECT: - { - json_object_t *object; - void *iter; - const char *separator; - int separator_length; - - if(flags & JSON_COMPACT) { - separator = ":"; - separator_length = 1; - } - else { - separator = ": "; - separator_length = 2; - } - - /* detect circular references */ - object = json_to_object(json); - if(object->visited) - goto object_error; - object->visited = 1; - - iter = json_object_iter((json_t *)json); - - if(dump("{", 1, data)) - goto object_error; - if(!iter) { - object->visited = 0; - return dump("}", 1, data); - } - if(dump_indent(flags, depth + 1, 0, dump, data)) - goto object_error; - - if(flags & JSON_SORT_KEYS || flags & JSON_PRESERVE_ORDER) - { - const object_key_t **keys; - unsigned int size; - unsigned int i; - int (*cmp_func)(const void *, const void *); - - size = json_object_size(json); - keys = malloc(size * sizeof(object_key_t *)); - if(!keys) - goto object_error; - - i = 0; - while(iter) - { - keys[i] = jsonp_object_iter_fullkey(iter); - iter = json_object_iter_next((json_t *)json, iter); - i++; - } - assert(i == size); - - if(flags & JSON_SORT_KEYS) - cmp_func = object_key_compare_keys; - else - cmp_func = object_key_compare_serials; - - qsort((void*)keys, size, sizeof(object_key_t *), cmp_func); - - for(i = 0; i < size; i++) - { - const char *key; - json_t *value; - - key = keys[i]->key; - value = json_object_get(json, key); - assert(value); - - dump_string(key, ascii, dump, data); - if(dump(separator, separator_length, data) || - do_dump(value, flags, depth + 1, dump, data)) - { - free((void*)keys); - goto object_error; - } - - if(i < size - 1) - { - if(dump(",", 1, data) || - dump_indent(flags, depth + 1, 1, dump, data)) - { - free((void*)keys); - goto object_error; - } - } - else - { - if(dump_indent(flags, depth, 0, dump, data)) - { - free((void*)keys); - goto object_error; - } - } - } - - free((void*)keys); - } - else - { - /* Don't sort keys */ - - while(iter) - { - void *next = json_object_iter_next((json_t *)json, iter); - - dump_string(json_object_iter_key(iter), ascii, dump, data); - if(dump(separator, separator_length, data) || - do_dump(json_object_iter_value(iter), flags, depth + 1, - dump, data)) - goto object_error; - - if(next) - { - if(dump(",", 1, data) || - dump_indent(flags, depth + 1, 1, dump, data)) - goto object_error; - } - else - { - if(dump_indent(flags, depth, 0, dump, data)) - goto object_error; - } - - iter = next; - } - } - - object->visited = 0; - return dump("}", 1, data); - - object_error: - object->visited = 0; - return -1; - } - - default: - /* not reached */ - return -1; - } -} - - -char *json_dumps(const json_t *json, unsigned long flags) -{ - strbuffer_t strbuff; - char *result; - - if(!json_is_array(json) && !json_is_object(json)) - return NULL; - - if(strbuffer_init(&strbuff)) - return NULL; - - if(do_dump(json, flags, 0, dump_to_strbuffer, (void *)&strbuff)) { - strbuffer_close(&strbuff); - return NULL; - } - - result = strdup(strbuffer_value(&strbuff)); - strbuffer_close(&strbuff); - - return result; -} - -int json_dumpf(const json_t *json, FILE *output, unsigned long flags) -{ - if(!json_is_array(json) && !json_is_object(json)) - return -1; - - return do_dump(json, flags, 0, dump_to_file, (void *)output); -} - -int json_dump_file(const json_t *json, const char *path, unsigned long flags) -{ - int result; - - FILE *output = fopen(path, "w"); - if(!output) - return -1; - - result = json_dumpf(json, output, flags); - - fclose(output); - return result; -} +/* + * Copyright (c) 2009-2013 Petri Lehtinen + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include + +#include "jansson.h" +#include "jansson_private.h" +#include "strbuffer.h" +#include "utf.h" + +#define MAX_INTEGER_STR_LENGTH 100 +#define MAX_REAL_STR_LENGTH 100 + +struct object_key { + size_t serial; + const char *key; +}; + +static int dump_to_strbuffer(const char *buffer, size_t size, void *data) +{ + return strbuffer_append_bytes((strbuffer_t *)data, buffer, size); +} + +static int dump_to_file(const char *buffer, size_t size, void *data) +{ + FILE *dest = (FILE *)data; + if(fwrite(buffer, size, 1, dest) != 1) + return -1; + return 0; +} + +/* 32 spaces (the maximum indentation size) */ +static const char whitespace[] = " "; + +static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump, void *data) +{ + if(JSON_INDENT(flags) > 0) + { + int i, ws_count = JSON_INDENT(flags); + + if(dump("\n", 1, data)) + return -1; + + for(i = 0; i < depth; i++) + { + if(dump(whitespace, ws_count, data)) + return -1; + } + } + else if(space && !(flags & JSON_COMPACT)) + { + return dump(" ", 1, data); + } + return 0; +} + +static int dump_string(const char *str, json_dump_callback_t dump, void *data, size_t flags) +{ + const char *pos, *end; + int32_t codepoint; + + if(dump("\"", 1, data)) + return -1; + + end = pos = str; + while(1) + { + const char *text; + char seq[13]; + int length; + + while(*end) + { + end = utf8_iterate(pos, &codepoint); + if(!end) + return -1; + + /* mandatory escape or control char */ + if(codepoint == '\\' || codepoint == '"' || codepoint < 0x20) + break; + + /* slash */ + if((flags & JSON_ESCAPE_SLASH) && codepoint == '/') + break; + + /* non-ASCII */ + if((flags & JSON_ENSURE_ASCII) && codepoint > 0x7F) + break; + + pos = end; + } + + if(pos != str) { + if(dump(str, pos - str, data)) + return -1; + } + + if(end == pos) + break; + + /* handle \, /, ", and control codes */ + length = 2; + switch(codepoint) + { + case '\\': text = "\\\\"; break; + case '\"': text = "\\\""; break; + case '\b': text = "\\b"; break; + case '\f': text = "\\f"; break; + case '\n': text = "\\n"; break; + case '\r': text = "\\r"; break; + case '\t': text = "\\t"; break; + case '/': text = "\\/"; break; + default: + { + /* codepoint is in BMP */ + if(codepoint < 0x10000) + { + sprintf(seq, "\\u%04x", codepoint); + length = 6; + } + + /* not in BMP -> construct a UTF-16 surrogate pair */ + else + { + int32_t first, last; + + codepoint -= 0x10000; + first = 0xD800 | ((codepoint & 0xffc00) >> 10); + last = 0xDC00 | (codepoint & 0x003ff); + + sprintf(seq, "\\u%04x\\u%04x", first, last); + length = 12; + } + + text = seq; + break; + } + } + + if(dump(text, length, data)) + return -1; + + str = pos = end; + } + + return dump("\"", 1, data); +} + +static int object_key_compare_keys(const void *key1, const void *key2) +{ + return strcmp(((const struct object_key *)key1)->key, + ((const struct object_key *)key2)->key); +} + +static int object_key_compare_serials(const void *key1, const void *key2) +{ + size_t a = ((const struct object_key *)key1)->serial; + size_t b = ((const struct object_key *)key2)->serial; + + return a < b ? -1 : a == b ? 0 : 1; +} + +static int do_dump(const json_t *json, size_t flags, int depth, + json_dump_callback_t dump, void *data) +{ + if(!json) + return -1; + + switch(json_typeof(json)) { + case JSON_NULL: + return dump("null", 4, data); + + case JSON_TRUE: + return dump("true", 4, data); + + case JSON_FALSE: + return dump("false", 5, data); + + case JSON_INTEGER: + { + char buffer[MAX_INTEGER_STR_LENGTH]; + int size; + + size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, + "%" JSON_INTEGER_FORMAT, + json_integer_value(json)); + if(size < 0 || size >= MAX_INTEGER_STR_LENGTH) + return -1; + + return dump(buffer, size, data); + } + + case JSON_REAL: + { + char buffer[MAX_REAL_STR_LENGTH]; + int size; + double value = json_real_value(json); + + size = jsonp_dtostr(buffer, MAX_REAL_STR_LENGTH, value); + if(size < 0) + return -1; + + return dump(buffer, size, data); + } + + case JSON_STRING: + return dump_string(json_string_value(json), dump, data, flags); + + case JSON_ARRAY: + { + int i; + int n; + json_array_t *array; + + /* detect circular references */ + array = json_to_array(json); + if(array->visited) + goto array_error; + array->visited = 1; + + n = json_array_size(json); + + if(dump("[", 1, data)) + goto array_error; + if(n == 0) { + array->visited = 0; + return dump("]", 1, data); + } + if(dump_indent(flags, depth + 1, 0, dump, data)) + goto array_error; + + for(i = 0; i < n; ++i) { + if(do_dump(json_array_get(json, i), flags, depth + 1, + dump, data)) + goto array_error; + + if(i < n - 1) + { + if(dump(",", 1, data) || + dump_indent(flags, depth + 1, 1, dump, data)) + goto array_error; + } + else + { + if(dump_indent(flags, depth, 0, dump, data)) + goto array_error; + } + } + + array->visited = 0; + return dump("]", 1, data); + + array_error: + array->visited = 0; + return -1; + } + + case JSON_OBJECT: + { + json_object_t *object; + void *iter; + const char *separator; + int separator_length; + + if(flags & JSON_COMPACT) { + separator = ":"; + separator_length = 1; + } + else { + separator = ": "; + separator_length = 2; + } + + /* detect circular references */ + object = json_to_object(json); + if(object->visited) + goto object_error; + object->visited = 1; + + iter = json_object_iter((json_t *)json); + + if(dump("{", 1, data)) + goto object_error; + if(!iter) { + object->visited = 0; + return dump("}", 1, data); + } + if(dump_indent(flags, depth + 1, 0, dump, data)) + goto object_error; + + if(flags & JSON_SORT_KEYS || flags & JSON_PRESERVE_ORDER) + { + struct object_key *keys; + size_t size, i; + int (*cmp_func)(const void *, const void *); + + size = json_object_size(json); + keys = jsonp_malloc(size * sizeof(struct object_key)); + if(!keys) + goto object_error; + + i = 0; + while(iter) + { + keys[i].serial = hashtable_iter_serial(iter); + keys[i].key = json_object_iter_key(iter); + iter = json_object_iter_next((json_t *)json, iter); + i++; + } + assert(i == size); + + if(flags & JSON_SORT_KEYS) + cmp_func = object_key_compare_keys; + else + cmp_func = object_key_compare_serials; + + qsort(keys, size, sizeof(struct object_key), cmp_func); + + for(i = 0; i < size; i++) + { + const char *key; + json_t *value; + + key = keys[i].key; + value = json_object_get(json, key); + assert(value); + + dump_string(key, dump, data, flags); + if(dump(separator, separator_length, data) || + do_dump(value, flags, depth + 1, dump, data)) + { + jsonp_free(keys); + goto object_error; + } + + if(i < size - 1) + { + if(dump(",", 1, data) || + dump_indent(flags, depth + 1, 1, dump, data)) + { + jsonp_free(keys); + goto object_error; + } + } + else + { + if(dump_indent(flags, depth, 0, dump, data)) + { + jsonp_free(keys); + goto object_error; + } + } + } + + jsonp_free(keys); + } + else + { + /* Don't sort keys */ + + while(iter) + { + void *next = json_object_iter_next((json_t *)json, iter); + + dump_string(json_object_iter_key(iter), dump, data, flags); + if(dump(separator, separator_length, data) || + do_dump(json_object_iter_value(iter), flags, depth + 1, + dump, data)) + goto object_error; + + if(next) + { + if(dump(",", 1, data) || + dump_indent(flags, depth + 1, 1, dump, data)) + goto object_error; + } + else + { + if(dump_indent(flags, depth, 0, dump, data)) + goto object_error; + } + + iter = next; + } + } + + object->visited = 0; + return dump("}", 1, data); + + object_error: + object->visited = 0; + return -1; + } + + default: + /* not reached */ + return -1; + } +} + +char *json_dumps(const json_t *json, size_t flags) +{ + strbuffer_t strbuff; + char *result; + + if(strbuffer_init(&strbuff)) + return NULL; + + if(json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags)) + result = NULL; + else + result = jsonp_strdup(strbuffer_value(&strbuff)); + + strbuffer_close(&strbuff); + return result; +} + +int json_dumpf(const json_t *json, FILE *output, size_t flags) +{ + return json_dump_callback(json, dump_to_file, (void *)output, flags); +} + +int json_dump_file(const json_t *json, const char *path, size_t flags) +{ + int result; + + FILE *output = fopen(path, "w"); + if(!output) + return -1; + + result = json_dumpf(json, output, flags); + + fclose(output); + return result; +} + +int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags) +{ + if(!(flags & JSON_ENCODE_ANY)) { + if(!json_is_array(json) && !json_is_object(json)) + return -1; + } + + return do_dump(json, flags, 0, callback, data); +} diff --git a/compat/jansson/error.c b/compat/jansson/error.c new file mode 100644 index 0000000..a544a59 --- /dev/null +++ b/compat/jansson/error.c @@ -0,0 +1,63 @@ +#include +#include "jansson_private.h" + +void jsonp_error_init(json_error_t *error, const char *source) +{ + if(error) + { + error->text[0] = '\0'; + error->line = -1; + error->column = -1; + error->position = 0; + if(source) + jsonp_error_set_source(error, source); + else + error->source[0] = '\0'; + } +} + +void jsonp_error_set_source(json_error_t *error, const char *source) +{ + size_t length; + + if(!error || !source) + return; + + length = strlen(source); + if(length < JSON_ERROR_SOURCE_LENGTH) + strcpy(error->source, source); + else { + size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; + strcpy(error->source, "..."); + strcpy(error->source + 3, source + extra); + } +} + +void jsonp_error_set(json_error_t *error, int line, int column, + size_t position, const char *msg, ...) +{ + va_list ap; + + va_start(ap, msg); + jsonp_error_vset(error, line, column, position, msg, ap); + va_end(ap); +} + +void jsonp_error_vset(json_error_t *error, int line, int column, + size_t position, const char *msg, va_list ap) +{ + if(!error) + return; + + if(error->text[0] != '\0') { + /* error already set */ + return; + } + + error->line = line; + error->column = column; + error->position = position; + + vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap); + error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; +} diff --git a/compat/jansson/hashtable.c b/compat/jansson/hashtable.c index 791f9ac..a438bbb 100644 --- a/compat/jansson/hashtable.c +++ b/compat/jansson/hashtable.c @@ -1,35 +1,46 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. */ -#include - #include +#include +#include /* for JSON_INLINE */ +#include "jansson_private.h" /* for container_of() */ #include "hashtable.h" -#ifdef WIN32 -#define inline __inline -#endif - typedef struct hashtable_list list_t; typedef struct hashtable_pair pair_t; typedef struct hashtable_bucket bucket_t; -#define container_of(ptr_, type_, member_) \ - ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) - #define list_to_pair(list_) container_of(list_, pair_t, list) -static inline void list_init(list_t *list) +/* From http://www.cse.yorku.ca/~oz/hash.html */ +static size_t hash_str(const void *ptr) +{ + const char *str = (const char *)ptr; + + size_t hash = 5381; + size_t c; + + while((c = (size_t)*str)) + { + hash = ((hash << 5) + hash) + c; + str++; + } + + return hash; +} + +static JSON_INLINE void list_init(list_t *list) { list->next = list; list->prev = list; } -static inline void list_insert(list_t *list, list_t *node) +static JSON_INLINE void list_insert(list_t *list, list_t *node) { node->next = list; node->prev = list->prev; @@ -37,13 +48,13 @@ static inline void list_insert(list_t *list, list_t *node) list->prev = node; } -static inline void list_remove(list_t *list) +static JSON_INLINE void list_remove(list_t *list) { list->prev->next = list->next; list->next->prev = list->prev; } -static inline int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket) +static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket) { return bucket->first == &hashtable->list && bucket->first == bucket->last; } @@ -63,22 +74,21 @@ static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket, } } -static unsigned int primes[] = { +static const size_t primes[] = { 5, 13, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741 }; -static const unsigned int num_primes = sizeof(primes) / sizeof(unsigned int); -static inline unsigned int num_buckets(hashtable_t *hashtable) +static JSON_INLINE size_t num_buckets(hashtable_t *hashtable) { return primes[hashtable->num_buckets]; } static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket, - const void *key, unsigned int hash) + const char *key, size_t hash) { list_t *list; pair_t *pair; @@ -90,7 +100,7 @@ static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket, while(1) { pair = list_to_pair(list); - if(pair->hash == hash && hashtable->cmp_keys(pair->key, key)) + if(pair->hash == hash && strcmp(pair->key, key) == 0) return pair; if(list == bucket->last) @@ -104,11 +114,11 @@ static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket, /* returns 0 on success, -1 if key was not found */ static int hashtable_do_del(hashtable_t *hashtable, - const void *key, unsigned int hash) + const char *key, size_t hash) { pair_t *pair; bucket_t *bucket; - unsigned int index; + size_t index; index = hash % num_buckets(hashtable); bucket = &hashtable->buckets[index]; @@ -127,13 +137,9 @@ static int hashtable_do_del(hashtable_t *hashtable, bucket->last = pair->list.prev; list_remove(&pair->list); + json_decref(pair->value); - if(hashtable->free_key) - hashtable->free_key(pair->key); - if(hashtable->free_value) - hashtable->free_value(pair->value); - - free(pair); + jsonp_free(pair); hashtable->size--; return 0; @@ -148,11 +154,8 @@ static void hashtable_do_clear(hashtable_t *hashtable) { next = list->next; pair = list_to_pair(list); - if(hashtable->free_key) - hashtable->free_key(pair->key); - if(hashtable->free_value) - hashtable->free_value(pair->value); - free(pair); + json_decref(pair->value); + jsonp_free(pair); } } @@ -160,14 +163,14 @@ static int hashtable_do_rehash(hashtable_t *hashtable) { list_t *list, *next; pair_t *pair; - unsigned int i, index, new_size; + size_t i, index, new_size; - free(hashtable->buckets); + jsonp_free(hashtable->buckets); hashtable->num_buckets++; new_size = num_buckets(hashtable); - hashtable->buckets = malloc(new_size * sizeof(bucket_t)); + hashtable->buckets = jsonp_malloc(new_size * sizeof(bucket_t)); if(!hashtable->buckets) return -1; @@ -191,47 +194,18 @@ static int hashtable_do_rehash(hashtable_t *hashtable) } -hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys, - free_fn free_key, free_fn free_value) -{ - hashtable_t *hashtable = malloc(sizeof(hashtable_t)); - if(!hashtable) - return NULL; - - if(hashtable_init(hashtable, hash_key, cmp_keys, free_key, free_value)) - { - free(hashtable); - return NULL; - } - - return hashtable; -} - -void hashtable_destroy(hashtable_t *hashtable) -{ - hashtable_close(hashtable); - free(hashtable); -} - -int hashtable_init(hashtable_t *hashtable, - key_hash_fn hash_key, key_cmp_fn cmp_keys, - free_fn free_key, free_fn free_value) +int hashtable_init(hashtable_t *hashtable) { - unsigned int i; + size_t i; hashtable->size = 0; hashtable->num_buckets = 0; /* index to primes[] */ - hashtable->buckets = malloc(num_buckets(hashtable) * sizeof(bucket_t)); + hashtable->buckets = jsonp_malloc(num_buckets(hashtable) * sizeof(bucket_t)); if(!hashtable->buckets) return -1; list_init(&hashtable->list); - hashtable->hash_key = hash_key; - hashtable->cmp_keys = cmp_keys; - hashtable->free_key = free_key; - hashtable->free_value = free_value; - for(i = 0; i < num_buckets(hashtable); i++) { hashtable->buckets[i].first = hashtable->buckets[i].last = @@ -244,42 +218,45 @@ int hashtable_init(hashtable_t *hashtable, void hashtable_close(hashtable_t *hashtable) { hashtable_do_clear(hashtable); - free(hashtable->buckets); + jsonp_free(hashtable->buckets); } -int hashtable_set(hashtable_t *hashtable, void *key, void *value) +int hashtable_set(hashtable_t *hashtable, + const char *key, size_t serial, + json_t *value) { pair_t *pair; bucket_t *bucket; - unsigned int hash, index; + size_t hash, index; /* rehash if the load ratio exceeds 1 */ if(hashtable->size >= num_buckets(hashtable)) if(hashtable_do_rehash(hashtable)) return -1; - hash = hashtable->hash_key(key); + hash = hash_str(key); index = hash % num_buckets(hashtable); bucket = &hashtable->buckets[index]; pair = hashtable_find_pair(hashtable, bucket, key, hash); if(pair) { - if(hashtable->free_key) - hashtable->free_key(key); - if(hashtable->free_value) - hashtable->free_value(pair->value); + json_decref(pair->value); pair->value = value; } else { - pair = malloc(sizeof(pair_t)); + /* offsetof(...) returns the size of pair_t without the last, + flexible member. This way, the correct amount is + allocated. */ + pair = jsonp_malloc(offsetof(pair_t, key) + strlen(key) + 1); if(!pair) return -1; - pair->key = key; - pair->value = value; pair->hash = hash; + pair->serial = serial; + strcpy(pair->key, key); + pair->value = value; list_init(&pair->list); insert_to_bucket(hashtable, bucket, &pair->list); @@ -289,13 +266,13 @@ int hashtable_set(hashtable_t *hashtable, void *key, void *value) return 0; } -void *hashtable_get(hashtable_t *hashtable, const void *key) +void *hashtable_get(hashtable_t *hashtable, const char *key) { pair_t *pair; - unsigned int hash; + size_t hash; bucket_t *bucket; - hash = hashtable->hash_key(key); + hash = hash_str(key); bucket = &hashtable->buckets[hash % num_buckets(hashtable)]; pair = hashtable_find_pair(hashtable, bucket, key, hash); @@ -305,15 +282,15 @@ void *hashtable_get(hashtable_t *hashtable, const void *key) return pair->value; } -int hashtable_del(hashtable_t *hashtable, const void *key) +int hashtable_del(hashtable_t *hashtable, const char *key) { - unsigned int hash = hashtable->hash_key(key); + size_t hash = hash_str(key); return hashtable_do_del(hashtable, key, hash); } void hashtable_clear(hashtable_t *hashtable) { - unsigned int i; + size_t i; hashtable_do_clear(hashtable); @@ -332,13 +309,13 @@ void *hashtable_iter(hashtable_t *hashtable) return hashtable_iter_next(hashtable, &hashtable->list); } -void *hashtable_iter_at(hashtable_t *hashtable, const void *key) +void *hashtable_iter_at(hashtable_t *hashtable, const char *key) { pair_t *pair; - unsigned int hash; + size_t hash; bucket_t *bucket; - hash = hashtable->hash_key(key); + hash = hash_str(key); bucket = &hashtable->buckets[hash % num_buckets(hashtable)]; pair = hashtable_find_pair(hashtable, bucket, key, hash); @@ -362,18 +339,22 @@ void *hashtable_iter_key(void *iter) return pair->key; } +size_t hashtable_iter_serial(void *iter) +{ + pair_t *pair = list_to_pair((list_t *)iter); + return pair->serial; +} + void *hashtable_iter_value(void *iter) { pair_t *pair = list_to_pair((list_t *)iter); return pair->value; } -void hashtable_iter_set(hashtable_t *hashtable, void *iter, void *value) +void hashtable_iter_set(void *iter, json_t *value) { pair_t *pair = list_to_pair((list_t *)iter); - if(hashtable->free_value) - hashtable->free_value(pair->value); - + json_decref(pair->value); pair->value = value; } diff --git a/compat/jansson/hashtable.h b/compat/jansson/hashtable.h index 52f8549..3c9fdc2 100644 --- a/compat/jansson/hashtable.h +++ b/compat/jansson/hashtable.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -8,20 +8,20 @@ #ifndef HASHTABLE_H #define HASHTABLE_H -typedef unsigned int (*key_hash_fn)(const void *key); -typedef int (*key_cmp_fn)(const void *key1, const void *key2); -typedef void (*free_fn)(void *key); - struct hashtable_list { struct hashtable_list *prev; struct hashtable_list *next; }; +/* "pair" may be a bit confusing a name, but think of it as a + key-value pair. In this case, it just encodes some extra data, + too */ struct hashtable_pair { - void *key; - void *value; - unsigned int hash; + size_t hash; struct hashtable_list list; + json_t *value; + size_t serial; + char key[1]; }; struct hashtable_bucket { @@ -30,60 +30,27 @@ struct hashtable_bucket { }; typedef struct hashtable { - unsigned int size; + size_t size; struct hashtable_bucket *buckets; - unsigned int num_buckets; /* index to primes[] */ + size_t num_buckets; /* index to primes[] */ struct hashtable_list list; - - key_hash_fn hash_key; - key_cmp_fn cmp_keys; /* returns non-zero for equal keys */ - free_fn free_key; - free_fn free_value; } hashtable_t; -/** - * hashtable_create - Create a hashtable object - * - * @hash_key: The key hashing function - * @cmp_keys: The key compare function. Returns non-zero for equal and - * zero for unequal unequal keys - * @free_key: If non-NULL, called for a key that is no longer referenced. - * @free_value: If non-NULL, called for a value that is no longer referenced. - * - * Returns a new hashtable object that should be freed with - * hashtable_destroy when it's no longer used, or NULL on failure (out - * of memory). - */ -hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys, - free_fn free_key, free_fn free_value); -/** - * hashtable_destroy - Destroy a hashtable object - * - * @hashtable: The hashtable - * - * Destroys a hashtable created with hashtable_create(). - */ -void hashtable_destroy(hashtable_t *hashtable); +#define hashtable_key_to_iter(key_) \ + (&(container_of(key_, struct hashtable_pair, key)->list)) /** * hashtable_init - Initialize a hashtable object * * @hashtable: The (statically allocated) hashtable object - * @hash_key: The key hashing function - * @cmp_keys: The key compare function. Returns non-zero for equal and - * zero for unequal unequal keys - * @free_key: If non-NULL, called for a key that is no longer referenced. - * @free_value: If non-NULL, called for a value that is no longer referenced. * * Initializes a statically allocated hashtable object. The object * should be cleared with hashtable_close when it's no longer used. * * Returns 0 on success, -1 on error (out of memory). */ -int hashtable_init(hashtable_t *hashtable, - key_hash_fn hash_key, key_cmp_fn cmp_keys, - free_fn free_key, free_fn free_value); +int hashtable_init(hashtable_t *hashtable); /** * hashtable_close - Release all resources used by a hashtable object @@ -99,20 +66,19 @@ void hashtable_close(hashtable_t *hashtable); * * @hashtable: The hashtable object * @key: The key + * @serial: For addition order of keys * @value: The value * * If a value with the given key already exists, its value is replaced - * with the new value. - * - * Key and value are "stealed" in the sense that hashtable frees them - * automatically when they are no longer used. The freeing is - * accomplished by calling free_key and free_value functions that were - * supplied to hashtable_new. In case one or both of the free - * functions is NULL, the corresponding item is not "stealed". + * with the new value. Value is "stealed" in the sense that hashtable + * doesn't increment its refcount but decreases the refcount when the + * value is no longer needed. * * Returns 0 on success, -1 on failure (out of memory). */ -int hashtable_set(hashtable_t *hashtable, void *key, void *value); +int hashtable_set(hashtable_t *hashtable, + const char *key, size_t serial, + json_t *value); /** * hashtable_get - Get a value associated with a key @@ -122,7 +88,7 @@ int hashtable_set(hashtable_t *hashtable, void *key, void *value); * * Returns value if it is found, or NULL otherwise. */ -void *hashtable_get(hashtable_t *hashtable, const void *key); +void *hashtable_get(hashtable_t *hashtable, const char *key); /** * hashtable_del - Remove a value from the hashtable @@ -132,7 +98,7 @@ void *hashtable_get(hashtable_t *hashtable, const void *key); * * Returns 0 on success, or -1 if the key was not found. */ -int hashtable_del(hashtable_t *hashtable, const void *key); +int hashtable_del(hashtable_t *hashtable, const char *key); /** * hashtable_clear - Clear hashtable @@ -169,7 +135,7 @@ void *hashtable_iter(hashtable_t *hashtable); * Like hashtable_iter() but returns an iterator pointing to a * specific key. */ -void *hashtable_iter_at(hashtable_t *hashtable, const void *key); +void *hashtable_iter_at(hashtable_t *hashtable, const char *key); /** * hashtable_iter_next - Advance an iterator @@ -189,6 +155,13 @@ void *hashtable_iter_next(hashtable_t *hashtable, void *iter); */ void *hashtable_iter_key(void *iter); +/** + * hashtable_iter_serial - Retrieve the serial number pointed to by an iterator + * + * @iter: The iterator + */ +size_t hashtable_iter_serial(void *iter); + /** * hashtable_iter_value - Retrieve the value pointed by an iterator * @@ -202,6 +175,6 @@ void *hashtable_iter_value(void *iter); * @iter: The iterator * @value: The value to set */ -void hashtable_iter_set(hashtable_t *hashtable, void *iter, void *value); +void hashtable_iter_set(void *iter, json_t *value); #endif diff --git a/compat/jansson/jansson.h b/compat/jansson/jansson.h index 781896c..0a072dd 100644 --- a/compat/jansson/jansson.h +++ b/compat/jansson/jansson.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -9,23 +9,31 @@ #define JANSSON_H #include +#include /* for size_t */ +#include -#ifdef WIN32 -#define snprintf(...) _snprintf(__VA_ARGS__) -#define strdup(x) _strdup(x) -#endif - -#ifdef WIN32 -#define inline __inline -#endif +#include -#ifndef __cplusplus -#define JSON_INLINE inline -#else -#define JSON_INLINE inline +#ifdef __cplusplus extern "C" { #endif +/* version */ + +#define JANSSON_MAJOR_VERSION 2 +#define JANSSON_MINOR_VERSION 6 +#define JANSSON_MICRO_VERSION 0 + +/* Micro version is omitted if it's 0 */ +#define JANSSON_VERSION "2.6" + +/* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this + for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */ +#define JANSSON_VERSION_HEX ((JANSSON_MAJOR_VERSION << 16) | \ + (JANSSON_MINOR_VERSION << 8) | \ + (JANSSON_MICRO_VERSION << 0)) + + /* types */ typedef enum { @@ -39,11 +47,25 @@ typedef enum { JSON_NULL } json_type; -typedef struct { +typedef struct json_t { json_type type; - unsigned long refcount; + size_t refcount; } json_t; +#ifndef JANSSON_USING_CMAKE /* disabled if using cmake */ +#if JSON_INTEGER_IS_LONG_LONG +#ifdef _WIN32 +#define JSON_INTEGER_FORMAT "I64d" +#else +#define JSON_INTEGER_FORMAT "lld" +#endif +typedef long long json_int_t; +#else +#define JSON_INTEGER_FORMAT "ld" +typedef long json_int_t; +#endif /* JSON_INTEGER_IS_LONG_LONG */ +#endif + #define json_typeof(json) ((json)->type) #define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT) #define json_is_array(json) (json && json_typeof(json) == JSON_ARRAY) @@ -62,16 +84,17 @@ json_t *json_object(void); json_t *json_array(void); json_t *json_string(const char *value); json_t *json_string_nocheck(const char *value); -json_t *json_integer(int value); +json_t *json_integer(json_int_t value); json_t *json_real(double value); json_t *json_true(void); json_t *json_false(void); +#define json_boolean(val) ((val) ? json_true() : json_false()) json_t *json_null(void); static JSON_INLINE json_t *json_incref(json_t *json) { - if(json && json->refcount != (unsigned int)-1) + if(json && json->refcount != (size_t)-1) ++json->refcount; return json; } @@ -82,27 +105,54 @@ void json_delete(json_t *json); static JSON_INLINE void json_decref(json_t *json) { - if(json && json->refcount != (unsigned int)-1 && --json->refcount == 0) + if(json && json->refcount != (size_t)-1 && --json->refcount == 0) json_delete(json); } +/* error reporting */ + +#define JSON_ERROR_TEXT_LENGTH 160 +#define JSON_ERROR_SOURCE_LENGTH 80 + +typedef struct { + int line; + int column; + int position; + char source[JSON_ERROR_SOURCE_LENGTH]; + char text[JSON_ERROR_TEXT_LENGTH]; +} json_error_t; + + /* getters, setters, manipulation */ -unsigned int json_object_size(const json_t *object); +size_t json_object_size(const json_t *object); json_t *json_object_get(const json_t *object, const char *key); int json_object_set_new(json_t *object, const char *key, json_t *value); int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value); int json_object_del(json_t *object, const char *key); int json_object_clear(json_t *object); int json_object_update(json_t *object, json_t *other); +int json_object_update_existing(json_t *object, json_t *other); +int json_object_update_missing(json_t *object, json_t *other); void *json_object_iter(json_t *object); void *json_object_iter_at(json_t *object, const char *key); +void *json_object_key_to_iter(const char *key); void *json_object_iter_next(json_t *object, void *iter); const char *json_object_iter_key(void *iter); json_t *json_object_iter_value(void *iter); int json_object_iter_set_new(json_t *object, void *iter, json_t *value); +#define json_object_foreach(object, key, value) \ + for(key = json_object_iter_key(json_object_iter(object)); \ + key && (value = json_object_iter_value(json_object_key_to_iter(key))); \ + key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key)))) + +#define json_array_foreach(array, index, value) \ + for(index = 0; \ + index < json_array_size(array) && (value = json_array_get(array, index)); \ + index++) + static JSON_INLINE int json_object_set(json_t *object, const char *key, json_t *value) { @@ -115,25 +165,25 @@ int json_object_set_nocheck(json_t *object, const char *key, json_t *value) return json_object_set_new_nocheck(object, key, json_incref(value)); } -static inline +static JSON_INLINE int json_object_iter_set(json_t *object, void *iter, json_t *value) { return json_object_iter_set_new(object, iter, json_incref(value)); } -unsigned int json_array_size(const json_t *array); -json_t *json_array_get(const json_t *array, unsigned int index); -int json_array_set_new(json_t *array, unsigned int index, json_t *value); +size_t json_array_size(const json_t *array); +json_t *json_array_get(const json_t *array, size_t index); +int json_array_set_new(json_t *array, size_t index, json_t *value); int json_array_append_new(json_t *array, json_t *value); -int json_array_insert_new(json_t *array, unsigned int index, json_t *value); -int json_array_remove(json_t *array, unsigned int index); +int json_array_insert_new(json_t *array, size_t index, json_t *value); +int json_array_remove(json_t *array, size_t index); int json_array_clear(json_t *array); int json_array_extend(json_t *array, json_t *other); static JSON_INLINE -int json_array_set(json_t *array, unsigned int index, json_t *value) +int json_array_set(json_t *array, size_t ind, json_t *value) { - return json_array_set_new(array, index, json_incref(value)); + return json_array_set_new(array, ind, json_incref(value)); } static JSON_INLINE @@ -143,22 +193,36 @@ int json_array_append(json_t *array, json_t *value) } static JSON_INLINE -int json_array_insert(json_t *array, unsigned int index, json_t *value) +int json_array_insert(json_t *array, size_t ind, json_t *value) { - return json_array_insert_new(array, index, json_incref(value)); + return json_array_insert_new(array, ind, json_incref(value)); } const char *json_string_value(const json_t *string); -int json_integer_value(const json_t *integer); +json_int_t json_integer_value(const json_t *integer); double json_real_value(const json_t *real); double json_number_value(const json_t *json); int json_string_set(json_t *string, const char *value); int json_string_set_nocheck(json_t *string, const char *value); -int json_integer_set(json_t *integer, int value); +int json_integer_set(json_t *integer, json_int_t value); int json_real_set(json_t *real, double value); +/* pack, unpack */ + +json_t *json_pack(const char *fmt, ...); +json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...); +json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap); + +#define JSON_VALIDATE_ONLY 0x1 +#define JSON_STRICT 0x2 + +int json_unpack(json_t *root, const char *fmt, ...); +int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...); +int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, va_list ap); + + /* equality */ int json_equal(json_t *value1, json_t *value2); @@ -167,31 +231,48 @@ int json_equal(json_t *value1, json_t *value2); /* copying */ json_t *json_copy(json_t *value); -json_t *json_deep_copy(json_t *value); +json_t *json_deep_copy(const json_t *value); -/* loading, printing */ +/* decoding */ -#define JSON_ERROR_TEXT_LENGTH 160 +#define JSON_REJECT_DUPLICATES 0x1 +#define JSON_DISABLE_EOF_CHECK 0x2 +#define JSON_DECODE_ANY 0x4 +#define JSON_DECODE_INT_AS_REAL 0x8 -typedef struct { - char text[JSON_ERROR_TEXT_LENGTH]; - int line; -} json_error_t; +typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data); + +json_t *json_loads(const char *input, size_t flags, json_error_t *error); +json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error); +json_t *json_loadf(FILE *input, size_t flags, json_error_t *error); +json_t *json_load_file(const char *path, size_t flags, json_error_t *error); +json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags, json_error_t *error); + + +/* encoding */ + +#define JSON_INDENT(n) (n & 0x1F) +#define JSON_COMPACT 0x20 +#define JSON_ENSURE_ASCII 0x40 +#define JSON_SORT_KEYS 0x80 +#define JSON_PRESERVE_ORDER 0x100 +#define JSON_ENCODE_ANY 0x200 +#define JSON_ESCAPE_SLASH 0x400 + +typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data); + +char *json_dumps(const json_t *json, size_t flags); +int json_dumpf(const json_t *json, FILE *output, size_t flags); +int json_dump_file(const json_t *json, const char *path, size_t flags); +int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags); -json_t *json_loads(const char *input, json_error_t *error); -json_t *json_loadf(FILE *input, json_error_t *error); -json_t *json_load_file(const char *path, json_error_t *error); +/* custom memory allocation */ -#define JSON_INDENT(n) (n & 0xFF) -#define JSON_COMPACT 0x100 -#define JSON_ENSURE_ASCII 0x200 -#define JSON_SORT_KEYS 0x400 -#define JSON_PRESERVE_ORDER 0x800 +typedef void *(*json_malloc_t)(size_t); +typedef void (*json_free_t)(void *); -char *json_dumps(const json_t *json, unsigned long flags); -int json_dumpf(const json_t *json, FILE *output, unsigned long flags); -int json_dump_file(const json_t *json, const char *path, unsigned long flags); +void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn); #ifdef __cplusplus } diff --git a/compat/jansson/jansson_config.h b/compat/jansson/jansson_config.h new file mode 100644 index 0000000..42421e8 --- /dev/null +++ b/compat/jansson/jansson_config.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010-2013 Petri Lehtinen + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + * + * + * This file specifies a part of the site-specific configuration for + * Jansson, namely those things that affect the public API in + * jansson.h. + * + * The configure script copies this file to jansson_config.h and + * replaces @var@ substitutions by values that fit your system. If you + * cannot run the configure script, you can do the value substitution + * by hand. + */ + +#ifndef JANSSON_CONFIG_H +#define JANSSON_CONFIG_H +/* If your compiler supports the inline keyword in C, JSON_INLINE is + defined to `inline', otherwise empty. In C++, the inline is always + supported. */ + +#ifdef _MSC_VER +#ifndef __cplusplus +#define inline __inline +#endif +#endif + +#ifdef __cplusplus +#define JSON_INLINE inline +#else +#define JSON_INLINE inline +#endif + +/* If your compiler supports the `long long` type and the strtoll() + library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, + otherwise to 0. */ +#define JSON_INTEGER_IS_LONG_LONG 1 + +/* If locale.h and localeconv() are available, define to 1, + otherwise to 0. */ +#define JSON_HAVE_LOCALECONV 1 + +#endif diff --git a/compat/jansson/jansson_private.h b/compat/jansson/jansson_private.h index 3a3ed75..b47d404 100644 --- a/compat/jansson/jansson_private.h +++ b/compat/jansson/jansson_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -8,23 +8,40 @@ #ifndef JANSSON_PRIVATE_H #define JANSSON_PRIVATE_H +#include #include "jansson.h" #include "hashtable.h" +#include "strbuffer.h" #define container_of(ptr_, type_, member_) \ - ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) + ((type_ *)((char *)ptr_ - offsetof(type_, member_))) + +/* On some platforms, max() may already be defined */ +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif + +/* va_copy is a C99 feature. In C89 implementations, it's sometimes + available as __va_copy. If not, memcpy() should do the trick. */ +#ifndef va_copy +#ifdef __va_copy +#define va_copy __va_copy +#else +#define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list)) +#endif +#endif typedef struct { json_t json; hashtable_t hashtable; - unsigned long serial; + size_t serial; int visited; } json_object_t; typedef struct { json_t json; - unsigned int size; - unsigned int entries; + size_t size; + size_t entries; json_t **table; int visited; } json_array_t; @@ -41,7 +58,7 @@ typedef struct { typedef struct { json_t json; - int value; + json_int_t value; } json_integer_t; #define json_to_object(json_) container_of(json_, json_object_t, json) @@ -50,11 +67,27 @@ typedef struct { #define json_to_real(json_) container_of(json_, json_real_t, json) #define json_to_integer(json_) container_of(json_, json_integer_t, json) -typedef struct { - unsigned long serial; - char key[]; -} object_key_t; +void jsonp_error_init(json_error_t *error, const char *source); +void jsonp_error_set_source(json_error_t *error, const char *source); +void jsonp_error_set(json_error_t *error, int line, int column, + size_t position, const char *msg, ...); +void jsonp_error_vset(json_error_t *error, int line, int column, + size_t position, const char *msg, va_list ap); + +/* Locale independent string<->double conversions */ +int jsonp_strtod(strbuffer_t *strbuffer, double *out); +int jsonp_dtostr(char *buffer, size_t size, double value); -const object_key_t *jsonp_object_iter_fullkey(void *iter); +/* Wrappers for custom memory functions */ +void* jsonp_malloc(size_t size); +void jsonp_free(void *ptr); +char *jsonp_strndup(const char *str, size_t length); +char *jsonp_strdup(const char *str); + +/* Windows compatibility */ +#ifdef _WIN32 +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#endif #endif diff --git a/compat/jansson/jansson_private_config.h b/compat/jansson/jansson_private_config.h new file mode 100644 index 0000000..2eb70a8 --- /dev/null +++ b/compat/jansson/jansson_private_config.h @@ -0,0 +1,140 @@ +/* jansson_private_config.h. Generated from jansson_private_config.h.in by configure. */ +/* jansson_private_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if gcc's __atomic builtins are available */ +/* #undef HAVE_ATOMIC_BUILTINS */ + +/* Define to 1 if you have the `close' function. */ +#define HAVE_CLOSE 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLFCN_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_ENDIAN_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `getpid' function. */ +#define HAVE_GETPID 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `localeconv' function. */ +#define HAVE_LOCALECONV 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if the system has the type `long long int'. */ +#define HAVE_LONG_LONG_INT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `open' function. */ +#define HAVE_OPEN 1 + +/* Define to 1 if you have the `read' function. */ +#define HAVE_READ 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SCHED_H 1 + +/* Define to 1 if you have the `sched_yield' function. */ +/* #undef HAVE_SCHED_YIELD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if gcc's __sync builtins are available */ +#define HAVE_SYNC_BUILTINS 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "jansson" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "petri@digip.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "jansson" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "jansson 2.6" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "jansson" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.6" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if /dev/urandom should be used for seeding the hash function */ +#define USE_URANDOM 1 + +/* Define to 1 if CryptGenRandom should be used for seeding the hash function + */ +#define USE_WINDOWS_CRYPTOAPI 1 + +/* Version number of package */ +#define VERSION "2.6" + +/* Define for Solaris 2.5.1 so the uint32_t typedef from , + , or is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +/* #undef _UINT32_T */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to the type of a signed integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +/* #undef int32_t */ + +/* Define to the type of an unsigned integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +/* #undef uint32_t */ diff --git a/compat/jansson/load.c b/compat/jansson/load.c index ee56fbe..45e21d0 100644 --- a/compat/jansson/load.c +++ b/compat/jansson/load.c @@ -1,25 +1,30 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE -#include +#endif + #include #include #include #include #include -#include #include -#include +#include "jansson.h" #include "jansson_private.h" #include "strbuffer.h" #include "utf.h" +#define STREAM_STATE_OK 0 +#define STREAM_STATE_EOF -1 +#define STREAM_STATE_ERROR -2 + #define TOKEN_INVALID -1 #define TOKEN_EOF 0 #define TOKEN_STRING 256 @@ -29,113 +34,136 @@ #define TOKEN_FALSE 260 #define TOKEN_NULL 261 -/* read one byte from stream, return EOF on end of file */ +/* Locale independent versions of isxxx() functions */ +#define l_isupper(c) ('A' <= (c) && (c) <= 'Z') +#define l_islower(c) ('a' <= (c) && (c) <= 'z') +#define l_isalpha(c) (l_isupper(c) || l_islower(c)) +#define l_isdigit(c) ('0' <= (c) && (c) <= '9') +#define l_isxdigit(c) \ + (l_isdigit(c) || ('A' <= (c) && (c) <= 'F') || ('a' <= (c) && (c) <= 'f')) + +/* Read one byte from stream, convert to unsigned char, then int, and + return. return EOF on end of file. This corresponds to the + behaviour of fgetc(). */ typedef int (*get_func)(void *data); -/* return non-zero if end of file has been reached */ -typedef int (*eof_func)(void *data); - typedef struct { get_func get; - eof_func eof; void *data; - int stream_pos; char buffer[5]; - int buffer_pos; + size_t buffer_pos; + int state; + int line; + int column, last_column; + size_t position; } stream_t; - typedef struct { stream_t stream; strbuffer_t saved_text; int token; - int line, column; union { char *string; - int integer; + json_int_t integer; double real; } value; } lex_t; +#define stream_to_lex(stream) container_of(stream, lex_t, stream) -/*** error reporting ***/ -static void error_init(json_error_t *error) -{ - if(error) - { - error->text[0] = '\0'; - error->line = -1; - } -} +/*** error reporting ***/ static void error_set(json_error_t *error, const lex_t *lex, const char *msg, ...) { va_list ap; - char text[JSON_ERROR_TEXT_LENGTH]; + char msg_text[JSON_ERROR_TEXT_LENGTH]; + char msg_with_context[JSON_ERROR_TEXT_LENGTH]; + + int line = -1, col = -1; + size_t pos = 0; + const char *result = msg_text; - if(!error || error->text[0] != '\0') { - /* error already set */ + if(!error) return; - } va_start(ap, msg); - vsnprintf(text, JSON_ERROR_TEXT_LENGTH, msg, ap); + vsnprintf(msg_text, JSON_ERROR_TEXT_LENGTH, msg, ap); + msg_text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; va_end(ap); if(lex) { const char *saved_text = strbuffer_value(&lex->saved_text); - error->line = lex->line; + + line = lex->stream.line; + col = lex->stream.column; + pos = lex->stream.position; + if(saved_text && saved_text[0]) { if(lex->saved_text.length <= 20) { - snprintf(error->text, JSON_ERROR_TEXT_LENGTH, - "%s near '%s'", text, saved_text); + snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, + "%s near '%s'", msg_text, saved_text); + msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; + result = msg_with_context; } - else - snprintf(error->text, JSON_ERROR_TEXT_LENGTH, "%s", text); } else { - snprintf(error->text, JSON_ERROR_TEXT_LENGTH, - "%s near end of file", text); + if(lex->stream.state == STREAM_STATE_ERROR) { + /* No context for UTF-8 decoding errors */ + result = msg_text; + } + else { + snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, + "%s near end of file", msg_text); + msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; + result = msg_with_context; + } } } - else - { - error->line = -1; - snprintf(error->text, JSON_ERROR_TEXT_LENGTH, "%s", text); - } + + jsonp_error_set(error, line, col, pos, "%s", result); } /*** lexical analyzer ***/ static void -stream_init(stream_t *stream, get_func get, eof_func eof, void *data) +stream_init(stream_t *stream, get_func get, void *data) { stream->get = get; - stream->eof = eof; stream->data = data; - stream->stream_pos = 0; stream->buffer[0] = '\0'; stream->buffer_pos = 0; + + stream->state = STREAM_STATE_OK; + stream->line = 1; + stream->column = 0; + stream->position = 0; } -static char stream_get(stream_t *stream, json_error_t *error) +static int stream_get(stream_t *stream, json_error_t *error) { - char c; + int c; + + if(stream->state != STREAM_STATE_OK) + return stream->state; if(!stream->buffer[stream->buffer_pos]) { - stream->buffer[0] = stream->get(stream->data); - stream->buffer_pos = 0; + c = stream->get(stream->data); + if(c == EOF) { + stream->state = STREAM_STATE_EOF; + return STREAM_STATE_EOF; + } - c = stream->buffer[0]; + stream->buffer[0] = c; + stream->buffer_pos = 0; - if((unsigned char)c >= 0x80 && c != (char)EOF) + if(0x80 <= c && c <= 0xFF) { /* multi-byte UTF-8 sequence */ int i, count; @@ -152,30 +180,47 @@ static char stream_get(stream_t *stream, json_error_t *error) if(!utf8_check_full(stream->buffer, count, NULL)) goto out; - stream->stream_pos += count; stream->buffer[count] = '\0'; } - else { + else stream->buffer[1] = '\0'; - stream->stream_pos++; - } } - return stream->buffer[stream->buffer_pos++]; + c = stream->buffer[stream->buffer_pos++]; -out: - error_set(error, NULL, "unable to decode byte 0x%x at position %d", - (unsigned char)c, stream->stream_pos); + stream->position++; + if(c == '\n') { + stream->line++; + stream->last_column = stream->column; + stream->column = 0; + } + else if(utf8_check_first(c)) { + /* track the Unicode character column, so increment only if + this is the first character of a UTF-8 sequence */ + stream->column++; + } - stream->buffer[0] = EOF; - stream->buffer[1] = '\0'; - stream->buffer_pos = 1; + return c; - return EOF; +out: + stream->state = STREAM_STATE_ERROR; + error_set(error, stream_to_lex(stream), "unable to decode byte 0x%x", c); + return STREAM_STATE_ERROR; } -static void stream_unget(stream_t *stream, char c) +static void stream_unget(stream_t *stream, int c) { + if(c == STREAM_STATE_EOF || c == STREAM_STATE_ERROR) + return; + + stream->position--; + if(c == '\n') { + stream->line--; + stream->column = stream->last_column; + } + else if(utf8_check_first(c)) + stream->column--; + assert(stream->buffer_pos > 0); stream->buffer_pos--; assert(stream->buffer[stream->buffer_pos] == c); @@ -187,29 +232,41 @@ static int lex_get(lex_t *lex, json_error_t *error) return stream_get(&lex->stream, error); } -static int lex_eof(lex_t *lex) -{ - return lex->stream.eof(lex->stream.data); -} - -static void lex_save(lex_t *lex, char c) +static void lex_save(lex_t *lex, int c) { strbuffer_append_byte(&lex->saved_text, c); } static int lex_get_save(lex_t *lex, json_error_t *error) { - char c = stream_get(&lex->stream, error); - lex_save(lex, c); + int c = stream_get(&lex->stream, error); + if(c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR) + lex_save(lex, c); return c; } -static void lex_unget_unsave(lex_t *lex, char c) +static void lex_unget(lex_t *lex, int c) { - char d; stream_unget(&lex->stream, c); - d = strbuffer_pop(&lex->saved_text); - assert(c == d); +} + +static void lex_unget_unsave(lex_t *lex, int c) +{ + if(c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR) { + /* Since we treat warnings as errors, when assertions are turned + * off the "d" variable would be set but never used. Which is + * treated as an error by GCC. + */ + #ifndef NDEBUG + char d; + #endif + stream_unget(&lex->stream, c); + #ifndef NDEBUG + d = + #endif + strbuffer_pop(&lex->saved_text); + assert(c == d); + } } static void lex_save_cached(lex_t *lex) @@ -218,6 +275,7 @@ static void lex_save_cached(lex_t *lex) { lex_save(lex, lex->stream.buffer[lex->stream.buffer_pos]); lex->stream.buffer_pos++; + lex->stream.position++; } } @@ -232,11 +290,11 @@ static int32_t decode_unicode_escape(const char *str) for(i = 1; i <= 4; i++) { char c = str[i]; value <<= 4; - if(isdigit(c)) + if(l_isdigit(c)) value += c - '0'; - else if(islower(c)) + else if(l_islower(c)) value += c - 'a' + 10; - else if(isupper(c)) + else if(l_isupper(c)) value += c - 'A' + 10; else assert(0); @@ -247,7 +305,7 @@ static int32_t decode_unicode_escape(const char *str) static void lex_scan_string(lex_t *lex, json_error_t *error) { - char c; + int c; const char *p; char *t; int i; @@ -258,14 +316,15 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) c = lex_get_save(lex, error); while(c != '"') { - if(c == (char)EOF) { - lex_unget_unsave(lex, c); - if(lex_eof(lex)) - error_set(error, lex, "premature end of input"); + if(c == STREAM_STATE_ERROR) + goto out; + + else if(c == STREAM_STATE_EOF) { + error_set(error, lex, "premature end of input"); goto out; } - else if((unsigned char)c <= 0x1F) { + else if(0 <= c && c <= 0x1F) { /* control character */ lex_unget_unsave(lex, c); if(c == '\n') @@ -280,8 +339,7 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) if(c == 'u') { c = lex_get_save(lex, error); for(i = 0; i < 4; i++) { - if(!isxdigit(c)) { - lex_unget_unsave(lex, c); + if(!l_isxdigit(c)) { error_set(error, lex, "invalid escape"); goto out; } @@ -292,7 +350,6 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) c == 'f' || c == 'n' || c == 'r' || c == 't') c = lex_get_save(lex, error); else { - lex_unget_unsave(lex, c); error_set(error, lex, "invalid escape"); goto out; } @@ -308,7 +365,7 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) - two \uXXXX escapes (length 12) forming an UTF-16 surrogate pair are converted to 4 bytes */ - lex->value.string = malloc(lex->saved_text.length + 1); + lex->value.string = jsonp_malloc(lex->saved_text.length + 1); if(!lex->value.string) { /* this is not very nice, since TOKEN_INVALID is returned */ goto out; @@ -398,10 +455,22 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) return; out: - free(lex->value.string); + jsonp_free(lex->value.string); } -static int lex_scan_number(lex_t *lex, char c, json_error_t *error) +#ifndef JANSSON_USING_CMAKE /* disabled if using cmake */ +#if JSON_INTEGER_IS_LONG_LONG +#ifdef _MSC_VER /* Microsoft Visual Studio */ +#define json_strtoint _strtoi64 +#else +#define json_strtoint strtoll +#endif +#else +#define json_strtoint strtol +#endif +#endif + +static int lex_scan_number(lex_t *lex, int c, json_error_t *error) { const char *saved_text; char *end; @@ -414,52 +483,55 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error) if(c == '0') { c = lex_get_save(lex, error); - if(isdigit(c)) { + if(l_isdigit(c)) { lex_unget_unsave(lex, c); goto out; } } - else if(isdigit(c)) { + else if(l_isdigit(c)) { c = lex_get_save(lex, error); - while(isdigit(c)) + while(l_isdigit(c)) c = lex_get_save(lex, error); } else { - lex_unget_unsave(lex, c); - goto out; + lex_unget_unsave(lex, c); + goto out; } if(c != '.' && c != 'E' && c != 'e') { - long value; + json_int_t value; lex_unget_unsave(lex, c); saved_text = strbuffer_value(&lex->saved_text); - value = strtol(saved_text, &end, 10); - assert(end == saved_text + lex->saved_text.length); - if((value == LONG_MAX && errno == ERANGE) || value > INT_MAX) { - error_set(error, lex, "too big integer"); - goto out; - } - else if((value == LONG_MIN && errno == ERANGE) || value < INT_MIN) { - error_set(error, lex, "too big negative integer"); + errno = 0; + value = json_strtoint(saved_text, &end, 10); + if(errno == ERANGE) { + if(value < 0) + error_set(error, lex, "too big negative integer"); + else + error_set(error, lex, "too big integer"); goto out; } + assert(end == saved_text + lex->saved_text.length); + lex->token = TOKEN_INTEGER; - lex->value.integer = (int)value; + lex->value.integer = value; return 0; } if(c == '.') { c = lex_get(lex, error); - if(!isdigit(c)) + if(!l_isdigit(c)) { + lex_unget(lex, c); goto out; + } lex_save(lex, c); c = lex_get_save(lex, error); - while(isdigit(c)) + while(l_isdigit(c)) c = lex_get_save(lex, error); } @@ -468,23 +540,19 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error) if(c == '+' || c == '-') c = lex_get_save(lex, error); - if(!isdigit(c)) { + if(!l_isdigit(c)) { lex_unget_unsave(lex, c); goto out; } c = lex_get_save(lex, error); - while(isdigit(c)) + while(l_isdigit(c)) c = lex_get_save(lex, error); } lex_unget_unsave(lex, c); - saved_text = strbuffer_value(&lex->saved_text); - value = strtod(saved_text, &end); - assert(end == saved_text + lex->saved_text.length); - - if(errno == ERANGE && value != 0) { + if(jsonp_strtod(&lex->saved_text, &value)) { error_set(error, lex, "real number overflow"); goto out; } @@ -499,29 +567,26 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error) static int lex_scan(lex_t *lex, json_error_t *error) { - char c; + int c; strbuffer_clear(&lex->saved_text); if(lex->token == TOKEN_STRING) { - free(lex->value.string); + jsonp_free(lex->value.string); lex->value.string = NULL; } c = lex_get(lex, error); while(c == ' ' || c == '\t' || c == '\n' || c == '\r') - { - if(c == '\n') - lex->line++; - c = lex_get(lex, error); + + if(c == STREAM_STATE_EOF) { + lex->token = TOKEN_EOF; + goto out; } - if(c == (char)EOF) { - if(lex_eof(lex)) - lex->token = TOKEN_EOF; - else - lex->token = TOKEN_INVALID; + if(c == STREAM_STATE_ERROR) { + lex->token = TOKEN_INVALID; goto out; } @@ -533,17 +598,17 @@ static int lex_scan(lex_t *lex, json_error_t *error) else if(c == '"') lex_scan_string(lex, error); - else if(isdigit(c) || c == '-') { + else if(l_isdigit(c) || c == '-') { if(lex_scan_number(lex, c, error)) goto out; } - else if(isupper(c) || islower(c)) { + else if(l_isalpha(c)) { /* eat up the whole identifier for clearer error messages */ const char *saved_text; c = lex_get_save(lex, error); - while(isupper(c) || islower(c)) + while(l_isalpha(c)) c = lex_get_save(lex, error); lex_unget_unsave(lex, c); @@ -581,31 +646,29 @@ static char *lex_steal_string(lex_t *lex) return result; } -static int lex_init(lex_t *lex, get_func get, eof_func eof, void *data) +static int lex_init(lex_t *lex, get_func get, void *data) { - stream_init(&lex->stream, get, eof, data); + stream_init(&lex->stream, get, data); if(strbuffer_init(&lex->saved_text)) return -1; lex->token = TOKEN_INVALID; - lex->line = 1; - return 0; } static void lex_close(lex_t *lex) { if(lex->token == TOKEN_STRING) - free(lex->value.string); + jsonp_free(lex->value.string); strbuffer_close(&lex->saved_text); } /*** parser ***/ -static json_t *parse_value(lex_t *lex, json_error_t *error); +static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error); -static json_t *parse_object(lex_t *lex, json_error_t *error) +static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) { json_t *object = json_object(); if(!object) @@ -628,28 +691,36 @@ static json_t *parse_object(lex_t *lex, json_error_t *error) if(!key) return NULL; + if(flags & JSON_REJECT_DUPLICATES) { + if(json_object_get(object, key)) { + jsonp_free(key); + error_set(error, lex, "duplicate object key"); + goto error; + } + } + lex_scan(lex, error); if(lex->token != ':') { - free(key); + jsonp_free(key); error_set(error, lex, "':' expected"); goto error; } lex_scan(lex, error); - value = parse_value(lex, error); + value = parse_value(lex, flags, error); if(!value) { - free(key); + jsonp_free(key); goto error; } if(json_object_set_nocheck(object, key, value)) { - free(key); + jsonp_free(key); json_decref(value); goto error; } json_decref(value); - free(key); + jsonp_free(key); lex_scan(lex, error); if(lex->token != ',') @@ -670,7 +741,7 @@ static json_t *parse_object(lex_t *lex, json_error_t *error) return NULL; } -static json_t *parse_array(lex_t *lex, json_error_t *error) +static json_t *parse_array(lex_t *lex, size_t flags, json_error_t *error) { json_t *array = json_array(); if(!array) @@ -681,7 +752,7 @@ static json_t *parse_array(lex_t *lex, json_error_t *error) return array; while(lex->token) { - json_t *elem = parse_value(lex, error); + json_t *elem = parse_value(lex, flags, error); if(!elem) goto error; @@ -710,9 +781,10 @@ static json_t *parse_array(lex_t *lex, json_error_t *error) return NULL; } -static json_t *parse_value(lex_t *lex, json_error_t *error) +static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) { json_t *json; + double value; switch(lex->token) { case TOKEN_STRING: { @@ -721,7 +793,15 @@ static json_t *parse_value(lex_t *lex, json_error_t *error) } case TOKEN_INTEGER: { - json = json_integer(lex->value.integer); + if (flags & JSON_DECODE_INT_AS_REAL) { + if(jsonp_strtod(&lex->saved_text, &value)) { + error_set(error, lex, "real number overflow"); + return NULL; + } + json = json_real(value); + } else { + json = json_integer(lex->value.integer); + } break; } @@ -743,11 +823,11 @@ static json_t *parse_value(lex_t *lex, json_error_t *error) break; case '{': - json = parse_object(lex, error); + json = parse_object(lex, flags, error); break; case '[': - json = parse_array(lex, error); + json = parse_array(lex, flags, error); break; case TOKEN_INVALID: @@ -765,17 +845,37 @@ static json_t *parse_value(lex_t *lex, json_error_t *error) return json; } -static json_t *parse_json(lex_t *lex, json_error_t *error) +static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error) { - error_init(error); + json_t *result; lex_scan(lex, error); - if(lex->token != '[' && lex->token != '{') { - error_set(error, lex, "'[' or '{' expected"); + if(!(flags & JSON_DECODE_ANY)) { + if(lex->token != '[' && lex->token != '{') { + error_set(error, lex, "'[' or '{' expected"); + return NULL; + } + } + + result = parse_value(lex, flags, error); + if(!result) return NULL; + + if(!(flags & JSON_DISABLE_EOF_CHECK)) { + lex_scan(lex, error); + if(lex->token != TOKEN_EOF) { + error_set(error, lex, "end of file expected"); + json_decref(result); + return NULL; + } + } + + if(error) { + /* Save the position even though there was no error */ + error->position = lex->stream.position; } - return parse_value(lex, error); + return result; } typedef struct @@ -794,77 +894,120 @@ static int string_get(void *data) else { stream->pos++; - return c; + return (unsigned char)c; } } -static int string_eof(void *data) +json_t *json_loads(const char *string, size_t flags, json_error_t *error) { - string_data_t *stream = (string_data_t *)data; - return (stream->data[stream->pos] == '\0'); + lex_t lex; + json_t *result; + string_data_t stream_data; + + jsonp_error_init(error, ""); + + if (string == NULL) { + error_set(error, NULL, "wrong arguments"); + return NULL; + } + + stream_data.data = string; + stream_data.pos = 0; + + if(lex_init(&lex, string_get, (void *)&stream_data)) + return NULL; + + result = parse_json(&lex, flags, error); + + lex_close(&lex); + return result; +} + +typedef struct +{ + const char *data; + size_t len; + size_t pos; +} buffer_data_t; + +static int buffer_get(void *data) +{ + char c; + buffer_data_t *stream = data; + if(stream->pos >= stream->len) + return EOF; + + c = stream->data[stream->pos]; + stream->pos++; + return (unsigned char)c; } -json_t *json_loads(const char *string, json_error_t *error) +json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error) { lex_t lex; json_t *result; + buffer_data_t stream_data; - string_data_t stream_data = { - string, - 0 - }; + jsonp_error_init(error, ""); - if(lex_init(&lex, string_get, string_eof, (void *)&stream_data)) + if (buffer == NULL) { + error_set(error, NULL, "wrong arguments"); return NULL; + } - result = parse_json(&lex, error); - if(!result) - goto out; + stream_data.data = buffer; + stream_data.pos = 0; + stream_data.len = buflen; - lex_scan(&lex, error); - if(lex.token != TOKEN_EOF) { - error_set(error, &lex, "end of file expected"); - json_decref(result); - result = NULL; - } + if(lex_init(&lex, buffer_get, (void *)&stream_data)) + return NULL; + + result = parse_json(&lex, flags, error); -out: lex_close(&lex); return result; } -json_t *json_loadf(FILE *input, json_error_t *error) +json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) { lex_t lex; + const char *source; json_t *result; - if(lex_init(&lex, (get_func)fgetc, (eof_func)feof, input)) - return NULL; + if(input == stdin) + source = ""; + else + source = ""; - result = parse_json(&lex, error); - if(!result) - goto out; + jsonp_error_init(error, source); - lex_scan(&lex, error); - if(lex.token != TOKEN_EOF) { - error_set(error, &lex, "end of file expected"); - json_decref(result); - result = NULL; + if (input == NULL) { + error_set(error, NULL, "wrong arguments"); + return NULL; } -out: + if(lex_init(&lex, (get_func)fgetc, input)) + return NULL; + + result = parse_json(&lex, flags, error); + lex_close(&lex); return result; } -json_t *json_load_file(const char *path, json_error_t *error) +json_t *json_load_file(const char *path, size_t flags, json_error_t *error) { json_t *result; FILE *fp; - error_init(error); + jsonp_error_init(error, path); + + if (path == NULL) { + error_set(error, NULL, "wrong arguments"); + return NULL; + } - fp = fopen(path, "r"); + fp = fopen(path, "rb"); if(!fp) { error_set(error, NULL, "unable to open %s: %s", @@ -872,8 +1015,63 @@ json_t *json_load_file(const char *path, json_error_t *error) return NULL; } - result = json_loadf(fp, error); + result = json_loadf(fp, flags, error); fclose(fp); return result; } + +#define MAX_BUF_LEN 1024 + +typedef struct +{ + char data[MAX_BUF_LEN]; + size_t len; + size_t pos; + json_load_callback_t callback; + void *arg; +} callback_data_t; + +static int callback_get(void *data) +{ + char c; + callback_data_t *stream = data; + + if(stream->pos >= stream->len) { + stream->pos = 0; + stream->len = stream->callback(stream->data, MAX_BUF_LEN, stream->arg); + if(stream->len == 0 || stream->len == (size_t)-1) + return EOF; + } + + c = stream->data[stream->pos]; + stream->pos++; + return (unsigned char)c; +} + +json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags, json_error_t *error) +{ + lex_t lex; + json_t *result; + + callback_data_t stream_data; + + memset(&stream_data, 0, sizeof(stream_data)); + stream_data.callback = callback; + stream_data.arg = arg; + + jsonp_error_init(error, ""); + + if (callback == NULL) { + error_set(error, NULL, "wrong arguments"); + return NULL; + } + + if(lex_init(&lex, (get_func)callback_get, &stream_data)) + return NULL; + + result = parse_json(&lex, flags, error); + + lex_close(&lex); + return result; +} diff --git a/compat/jansson/memory.c b/compat/jansson/memory.c new file mode 100644 index 0000000..eb6cec5 --- /dev/null +++ b/compat/jansson/memory.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009-2013 Petri Lehtinen + * Copyright (c) 2011-2012 Basile Starynkevitch + * + * Jansson is free software; you can redistribute it and/or modify it + * under the terms of the MIT license. See LICENSE for details. + */ + +#include +#include + +#include "jansson.h" +#include "jansson_private.h" + +/* memory function pointers */ +static json_malloc_t do_malloc = malloc; +static json_free_t do_free = free; + +void *jsonp_malloc(size_t size) +{ + if(!size) + return NULL; + + return (*do_malloc)(size); +} + +void jsonp_free(void *ptr) +{ + if(!ptr) + return; + + (*do_free)(ptr); +} + +char *jsonp_strdup(const char *str) +{ + char *new_str; + size_t len; + + len = strlen(str); + if(len == (size_t)-1) + return NULL; + + new_str = jsonp_malloc(len + 1); + if(!new_str) + return NULL; + + memcpy(new_str, str, len + 1); + return new_str; +} + +void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) +{ + do_malloc = malloc_fn; + do_free = free_fn; +} diff --git a/compat/jansson/pack_unpack.c b/compat/jansson/pack_unpack.c new file mode 100644 index 0000000..0d932f7 --- /dev/null +++ b/compat/jansson/pack_unpack.c @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2009-2013 Petri Lehtinen + * Copyright (c) 2011-2012 Graeme Smecher + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include +#include "jansson.h" +#include "jansson_private.h" +#include "utf.h" + +typedef struct { + int line; + int column; + size_t pos; + char token; +} token_t; + +typedef struct { + const char *start; + const char *fmt; + token_t prev_token; + token_t token; + token_t next_token; + json_error_t *error; + size_t flags; + int line; + int column; + size_t pos; +} scanner_t; + +#define token(scanner) ((scanner)->token.token) + +static const char * const type_names[] = { + "object", + "array", + "string", + "integer", + "real", + "true", + "false", + "null" +}; + +#define type_name(x) type_names[json_typeof(x)] + +static const char unpack_value_starters[] = "{[siIbfFOon"; + + +static void scanner_init(scanner_t *s, json_error_t *error, + size_t flags, const char *fmt) +{ + s->error = error; + s->flags = flags; + s->fmt = s->start = fmt; + memset(&s->prev_token, 0, sizeof(token_t)); + memset(&s->token, 0, sizeof(token_t)); + memset(&s->next_token, 0, sizeof(token_t)); + s->line = 1; + s->column = 0; + s->pos = 0; +} + +static void next_token(scanner_t *s) +{ + const char *t; + s->prev_token = s->token; + + if(s->next_token.line) { + s->token = s->next_token; + s->next_token.line = 0; + return; + } + + t = s->fmt; + s->column++; + s->pos++; + + /* skip space and ignored chars */ + while(*t == ' ' || *t == '\t' || *t == '\n' || *t == ',' || *t == ':') { + if(*t == '\n') { + s->line++; + s->column = 1; + } + else + s->column++; + + s->pos++; + t++; + } + + s->token.token = *t; + s->token.line = s->line; + s->token.column = s->column; + s->token.pos = s->pos; + + t++; + s->fmt = t; +} + +static void prev_token(scanner_t *s) +{ + s->next_token = s->token; + s->token = s->prev_token; +} + +static void set_error(scanner_t *s, const char *source, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + jsonp_error_vset(s->error, s->token.line, s->token.column, s->token.pos, + fmt, ap); + + jsonp_error_set_source(s->error, source); + + va_end(ap); +} + +static json_t *pack(scanner_t *s, va_list *ap); + + +/* ours will be set to 1 if jsonp_free() must be called for the result + afterwards */ +static char *read_string(scanner_t *s, va_list *ap, + const char *purpose, int *ours) +{ + char t; + strbuffer_t strbuff; + const char *str; + size_t length; + char *result; + + next_token(s); + t = token(s); + prev_token(s); + + if(t != '#' && t != '+') { + /* Optimize the simple case */ + str = va_arg(*ap, const char *); + + if(!str) { + set_error(s, "", "NULL string argument"); + return NULL; + } + + if(!utf8_check_string(str, -1)) { + set_error(s, "", "Invalid UTF-8 %s", purpose); + return NULL; + } + + *ours = 0; + return (char *)str; + } + + strbuffer_init(&strbuff); + + while(1) { + str = va_arg(*ap, const char *); + if(!str) { + set_error(s, "", "NULL string argument"); + strbuffer_close(&strbuff); + return NULL; + } + + next_token(s); + + if(token(s) == '#') { + length = va_arg(*ap, int); + } + else { + prev_token(s); + length = strlen(str); + } + + if(strbuffer_append_bytes(&strbuff, str, length) == -1) { + set_error(s, "", "Out of memory"); + strbuffer_close(&strbuff); + return NULL; + } + + next_token(s); + if(token(s) != '+') { + prev_token(s); + break; + } + } + + result = strbuffer_steal_value(&strbuff); + + if(!utf8_check_string(result, -1)) { + set_error(s, "", "Invalid UTF-8 %s", purpose); + return NULL; + } + + *ours = 1; + return result; +} + +static json_t *pack_object(scanner_t *s, va_list *ap) +{ + json_t *object = json_object(); + next_token(s); + + while(token(s) != '}') { + char *key; + int ours; + json_t *value; + + if(!token(s)) { + set_error(s, "", "Unexpected end of format string"); + goto error; + } + + if(token(s) != 's') { + set_error(s, "", "Expected format 's', got '%c'", token(s)); + goto error; + } + + key = read_string(s, ap, "object key", &ours); + if(!key) + goto error; + + next_token(s); + + value = pack(s, ap); + if(!value) + goto error; + + if(json_object_set_new_nocheck(object, key, value)) { + if(ours) + jsonp_free(key); + + set_error(s, "", "Unable to add key \"%s\"", key); + goto error; + } + + if(ours) + jsonp_free(key); + + next_token(s); + } + + return object; + +error: + json_decref(object); + return NULL; +} + +static json_t *pack_array(scanner_t *s, va_list *ap) +{ + json_t *array = json_array(); + next_token(s); + + while(token(s) != ']') { + json_t *value; + + if(!token(s)) { + set_error(s, "", "Unexpected end of format string"); + goto error; + } + + value = pack(s, ap); + if(!value) + goto error; + + if(json_array_append_new(array, value)) { + set_error(s, "", "Unable to append to array"); + goto error; + } + + next_token(s); + } + return array; + +error: + json_decref(array); + return NULL; +} + +static json_t *pack(scanner_t *s, va_list *ap) +{ + switch(token(s)) { + case '{': + return pack_object(s, ap); + + case '[': + return pack_array(s, ap); + + case 's': { /* string */ + char *str; + int ours; + json_t *result; + + str = read_string(s, ap, "string", &ours); + if(!str) + return NULL; + + result = json_string_nocheck(str); + if(ours) + jsonp_free(str); + + return result; + } + + case 'n': /* null */ + return json_null(); + + case 'b': /* boolean */ + return va_arg(*ap, int) ? json_true() : json_false(); + + case 'i': /* integer from int */ + return json_integer(va_arg(*ap, int)); + + case 'I': /* integer from json_int_t */ + return json_integer(va_arg(*ap, json_int_t)); + + case 'f': /* real */ + return json_real(va_arg(*ap, double)); + + case 'O': /* a json_t object; increments refcount */ + return json_incref(va_arg(*ap, json_t *)); + + case 'o': /* a json_t object; doesn't increment refcount */ + return va_arg(*ap, json_t *); + + default: + set_error(s, "", "Unexpected format character '%c'", + token(s)); + return NULL; + } +} + +static int unpack(scanner_t *s, json_t *root, va_list *ap); + +static int unpack_object(scanner_t *s, json_t *root, va_list *ap) +{ + int ret = -1; + int strict = 0; + + /* Use a set (emulated by a hashtable) to check that all object + keys are accessed. Checking that the correct number of keys + were accessed is not enough, as the same key can be unpacked + multiple times. + */ + hashtable_t key_set; + + if(hashtable_init(&key_set)) { + set_error(s, "", "Out of memory"); + return -1; + } + + if(root && !json_is_object(root)) { + set_error(s, "", "Expected object, got %s", + type_name(root)); + goto out; + } + next_token(s); + + while(token(s) != '}') { + const char *key; + json_t *value; + int opt = 0; + + if(strict != 0) { + set_error(s, "", "Expected '}' after '%c', got '%c'", + (strict == 1 ? '!' : '*'), token(s)); + goto out; + } + + if(!token(s)) { + set_error(s, "", "Unexpected end of format string"); + goto out; + } + + if(token(s) == '!' || token(s) == '*') { + strict = (token(s) == '!' ? 1 : -1); + next_token(s); + continue; + } + + if(token(s) != 's') { + set_error(s, "", "Expected format 's', got '%c'", token(s)); + goto out; + } + + key = va_arg(*ap, const char *); + if(!key) { + set_error(s, "", "NULL object key"); + goto out; + } + + next_token(s); + + if(token(s) == '?') { + opt = 1; + next_token(s); + } + + if(!root) { + /* skipping */ + value = NULL; + } + else { + value = json_object_get(root, key); + if(!value && !opt) { + set_error(s, "", "Object item not found: %s", key); + goto out; + } + } + + if(unpack(s, value, ap)) + goto out; + + hashtable_set(&key_set, key, 0, json_null()); + next_token(s); + } + + if(strict == 0 && (s->flags & JSON_STRICT)) + strict = 1; + + if(root && strict == 1 && key_set.size != json_object_size(root)) { + long diff = (long)json_object_size(root) - (long)key_set.size; + set_error(s, "", "%li object item(s) left unpacked", diff); + goto out; + } + + ret = 0; + +out: + hashtable_close(&key_set); + return ret; +} + +static int unpack_array(scanner_t *s, json_t *root, va_list *ap) +{ + size_t i = 0; + int strict = 0; + + if(root && !json_is_array(root)) { + set_error(s, "", "Expected array, got %s", type_name(root)); + return -1; + } + next_token(s); + + while(token(s) != ']') { + json_t *value; + + if(strict != 0) { + set_error(s, "", "Expected ']' after '%c', got '%c'", + (strict == 1 ? '!' : '*'), + token(s)); + return -1; + } + + if(!token(s)) { + set_error(s, "", "Unexpected end of format string"); + return -1; + } + + if(token(s) == '!' || token(s) == '*') { + strict = (token(s) == '!' ? 1 : -1); + next_token(s); + continue; + } + + if(!strchr(unpack_value_starters, token(s))) { + set_error(s, "", "Unexpected format character '%c'", + token(s)); + return -1; + } + + if(!root) { + /* skipping */ + value = NULL; + } + else { + value = json_array_get(root, i); + if(!value) { + set_error(s, "", "Array index %lu out of range", + (unsigned long)i); + return -1; + } + } + + if(unpack(s, value, ap)) + return -1; + + next_token(s); + i++; + } + + if(strict == 0 && (s->flags & JSON_STRICT)) + strict = 1; + + if(root && strict == 1 && i != json_array_size(root)) { + long diff = (long)json_array_size(root) - (long)i; + set_error(s, "", "%li array item(s) left unpacked", diff); + return -1; + } + + return 0; +} + +static int unpack(scanner_t *s, json_t *root, va_list *ap) +{ + switch(token(s)) + { + case '{': + return unpack_object(s, root, ap); + + case '[': + return unpack_array(s, root, ap); + + case 's': + if(root && !json_is_string(root)) { + set_error(s, "", "Expected string, got %s", + type_name(root)); + return -1; + } + + if(!(s->flags & JSON_VALIDATE_ONLY)) { + const char **target; + + target = va_arg(*ap, const char **); + if(!target) { + set_error(s, "", "NULL string argument"); + return -1; + } + + if(root) + *target = json_string_value(root); + } + return 0; + + case 'i': + if(root && !json_is_integer(root)) { + set_error(s, "", "Expected integer, got %s", + type_name(root)); + return -1; + } + + if(!(s->flags & JSON_VALIDATE_ONLY)) { + int *target = va_arg(*ap, int*); + if(root) + *target = (int)json_integer_value(root); + } + + return 0; + + case 'I': + if(root && !json_is_integer(root)) { + set_error(s, "", "Expected integer, got %s", + type_name(root)); + return -1; + } + + if(!(s->flags & JSON_VALIDATE_ONLY)) { + json_int_t *target = va_arg(*ap, json_int_t*); + if(root) + *target = json_integer_value(root); + } + + return 0; + + case 'b': + if(root && !json_is_boolean(root)) { + set_error(s, "", "Expected true or false, got %s", + type_name(root)); + return -1; + } + + if(!(s->flags & JSON_VALIDATE_ONLY)) { + int *target = va_arg(*ap, int*); + if(root) + *target = json_is_true(root); + } + + return 0; + + case 'f': + if(root && !json_is_real(root)) { + set_error(s, "", "Expected real, got %s", + type_name(root)); + return -1; + } + + if(!(s->flags & JSON_VALIDATE_ONLY)) { + double *target = va_arg(*ap, double*); + if(root) + *target = json_real_value(root); + } + + return 0; + + case 'F': + if(root && !json_is_number(root)) { + set_error(s, "", "Expected real or integer, got %s", + type_name(root)); + return -1; + } + + if(!(s->flags & JSON_VALIDATE_ONLY)) { + double *target = va_arg(*ap, double*); + if(root) + *target = json_number_value(root); + } + + return 0; + + case 'O': + if(root && !(s->flags & JSON_VALIDATE_ONLY)) + json_incref(root); + /* Fall through */ + + case 'o': + if(!(s->flags & JSON_VALIDATE_ONLY)) { + json_t **target = va_arg(*ap, json_t**); + if(root) + *target = root; + } + + return 0; + + case 'n': + /* Never assign, just validate */ + if(root && !json_is_null(root)) { + set_error(s, "", "Expected null, got %s", + type_name(root)); + return -1; + } + return 0; + + default: + set_error(s, "", "Unexpected format character '%c'", + token(s)); + return -1; + } +} + +json_t *json_vpack_ex(json_error_t *error, size_t flags, + const char *fmt, va_list ap) +{ + scanner_t s; + va_list ap_copy; + json_t *value; + + if(!fmt || !*fmt) { + jsonp_error_init(error, ""); + jsonp_error_set(error, -1, -1, 0, "NULL or empty format string"); + return NULL; + } + jsonp_error_init(error, NULL); + + scanner_init(&s, error, flags, fmt); + next_token(&s); + + va_copy(ap_copy, ap); + value = pack(&s, &ap_copy); + va_end(ap_copy); + + if(!value) + return NULL; + + next_token(&s); + if(token(&s)) { + json_decref(value); + set_error(&s, "", "Garbage after format string"); + return NULL; + } + + return value; +} + +json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...) +{ + json_t *value; + va_list ap; + + va_start(ap, fmt); + value = json_vpack_ex(error, flags, fmt, ap); + va_end(ap); + + return value; +} + +json_t *json_pack(const char *fmt, ...) +{ + json_t *value; + va_list ap; + + va_start(ap, fmt); + value = json_vpack_ex(NULL, 0, fmt, ap); + va_end(ap); + + return value; +} + +int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, + const char *fmt, va_list ap) +{ + scanner_t s; + va_list ap_copy; + + if(!root) { + jsonp_error_init(error, ""); + jsonp_error_set(error, -1, -1, 0, "NULL root value"); + return -1; + } + + if(!fmt || !*fmt) { + jsonp_error_init(error, ""); + jsonp_error_set(error, -1, -1, 0, "NULL or empty format string"); + return -1; + } + jsonp_error_init(error, NULL); + + scanner_init(&s, error, flags, fmt); + next_token(&s); + + va_copy(ap_copy, ap); + if(unpack(&s, root, &ap_copy)) { + va_end(ap_copy); + return -1; + } + va_end(ap_copy); + + next_token(&s); + if(token(&s)) { + set_error(&s, "", "Garbage after format string"); + return -1; + } + + return 0; +} + +int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = json_vunpack_ex(root, error, flags, fmt, ap); + va_end(ap); + + return ret; +} + +int json_unpack(json_t *root, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = json_vunpack_ex(root, NULL, 0, fmt, ap); + va_end(ap); + + return ret; +} diff --git a/compat/jansson/strbuffer.c b/compat/jansson/strbuffer.c index 0019645..2d6ff31 100644 --- a/compat/jansson/strbuffer.c +++ b/compat/jansson/strbuffer.c @@ -1,95 +1,116 @@ -/* - * Copyright (c) 2009, 2010 Petri Lehtinen - * - * Jansson is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See LICENSE for details. - */ - -#define _GNU_SOURCE -#include -#include -#include "strbuffer.h" -#include "util.h" - -#define STRBUFFER_MIN_SIZE 16 -#define STRBUFFER_FACTOR 2 - -int strbuffer_init(strbuffer_t *strbuff) -{ - strbuff->size = STRBUFFER_MIN_SIZE; - strbuff->length = 0; - - strbuff->value = malloc(strbuff->size); - if(!strbuff->value) - return -1; - - /* initialize to empty */ - strbuff->value[0] = '\0'; - return 0; -} - -void strbuffer_close(strbuffer_t *strbuff) -{ - free(strbuff->value); - strbuff->size = 0; - strbuff->length = 0; - strbuff->value = NULL; -} - -void strbuffer_clear(strbuffer_t *strbuff) -{ - strbuff->length = 0; - strbuff->value[0] = '\0'; -} - -const char *strbuffer_value(const strbuffer_t *strbuff) -{ - return strbuff->value; -} - -char *strbuffer_steal_value(strbuffer_t *strbuff) -{ - char *result = strbuff->value; - strbuffer_init(strbuff); - return result; -} - -int strbuffer_append(strbuffer_t *strbuff, const char *string) -{ - return strbuffer_append_bytes(strbuff, string, strlen(string)); -} - -int strbuffer_append_byte(strbuffer_t *strbuff, char byte) -{ - return strbuffer_append_bytes(strbuff, &byte, 1); -} - -int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size) -{ - if(strbuff->length + size >= strbuff->size) - { - strbuff->size = max(strbuff->size * STRBUFFER_FACTOR, - strbuff->length + size + 1); - - strbuff->value = realloc(strbuff->value, strbuff->size); - if(!strbuff->value) - return -1; - } - - memcpy(strbuff->value + strbuff->length, data, size); - strbuff->length += size; - strbuff->value[strbuff->length] = '\0'; - - return 0; -} - -char strbuffer_pop(strbuffer_t *strbuff) -{ - if(strbuff->length > 0) { - char c = strbuff->value[--strbuff->length]; - strbuff->value[strbuff->length] = '\0'; - return c; - } - else - return '\0'; -} +/* + * Copyright (c) 2009-2013 Petri Lehtinen + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include "jansson_private.h" +#include "strbuffer.h" + +#define STRBUFFER_MIN_SIZE 16 +#define STRBUFFER_FACTOR 2 +#define STRBUFFER_SIZE_MAX ((size_t)-1) + +int strbuffer_init(strbuffer_t *strbuff) +{ + strbuff->size = STRBUFFER_MIN_SIZE; + strbuff->length = 0; + + strbuff->value = jsonp_malloc(strbuff->size); + if(!strbuff->value) + return -1; + + /* initialize to empty */ + strbuff->value[0] = '\0'; + return 0; +} + +void strbuffer_close(strbuffer_t *strbuff) +{ + if(strbuff->value) + jsonp_free(strbuff->value); + + strbuff->size = 0; + strbuff->length = 0; + strbuff->value = NULL; +} + +void strbuffer_clear(strbuffer_t *strbuff) +{ + strbuff->length = 0; + strbuff->value[0] = '\0'; +} + +const char *strbuffer_value(const strbuffer_t *strbuff) +{ + return strbuff->value; +} + +char *strbuffer_steal_value(strbuffer_t *strbuff) +{ + char *result = strbuff->value; + strbuff->value = NULL; + return result; +} + +int strbuffer_append(strbuffer_t *strbuff, const char *string) +{ + return strbuffer_append_bytes(strbuff, string, strlen(string)); +} + +int strbuffer_append_byte(strbuffer_t *strbuff, char byte) +{ + return strbuffer_append_bytes(strbuff, &byte, 1); +} + +int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) +{ + if(size >= strbuff->size - strbuff->length) + { + size_t new_size; + char *new_value; + + /* avoid integer overflow */ + if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR + || size > STRBUFFER_SIZE_MAX - 1 + || strbuff->length > STRBUFFER_SIZE_MAX - 1 - size) + return -1; + + new_size = max(strbuff->size * STRBUFFER_FACTOR, + strbuff->length + size + 1); + + new_value = jsonp_malloc(new_size); + if(!new_value) + return -1; + + memcpy(new_value, strbuff->value, strbuff->length); + + jsonp_free(strbuff->value); + strbuff->value = new_value; + strbuff->size = new_size; + } + + memcpy(strbuff->value + strbuff->length, data, size); + strbuff->length += size; + strbuff->value[strbuff->length] = '\0'; + + return 0; +} + +char strbuffer_pop(strbuffer_t *strbuff) +{ + if(strbuff->length > 0) { + char c = strbuff->value[--strbuff->length]; + strbuff->value[strbuff->length] = '\0'; + return c; + } + else + return '\0'; +} diff --git a/compat/jansson/strbuffer.h b/compat/jansson/strbuffer.h index 816594a..b17ea2b 100644 --- a/compat/jansson/strbuffer.h +++ b/compat/jansson/strbuffer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -10,8 +10,8 @@ typedef struct { char *value; - int length; /* bytes used */ - int size; /* bytes allocated */ + size_t length; /* bytes used */ + size_t size; /* bytes allocated */ } strbuffer_t; int strbuffer_init(strbuffer_t *strbuff); @@ -20,11 +20,13 @@ void strbuffer_close(strbuffer_t *strbuff); void strbuffer_clear(strbuffer_t *strbuff); const char *strbuffer_value(const strbuffer_t *strbuff); + +/* Steal the value and close the strbuffer */ char *strbuffer_steal_value(strbuffer_t *strbuff); int strbuffer_append(strbuffer_t *strbuff, const char *string); int strbuffer_append_byte(strbuffer_t *strbuff, char byte); -int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size); +int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size); char strbuffer_pop(strbuffer_t *strbuff); diff --git a/compat/jansson/strconv.c b/compat/jansson/strconv.c new file mode 100644 index 0000000..1c2472e --- /dev/null +++ b/compat/jansson/strconv.c @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include "jansson_private.h" +#include "strbuffer.h" + +/* need jansson_private_config.h to get the correct snprintf */ +#ifdef HAVE_CONFIG_H +#include "jansson_private_config.h" +#endif + +#if JSON_HAVE_LOCALECONV +#include + +/* + - This code assumes that the decimal separator is exactly one + character. + + - If setlocale() is called by another thread between the call to + localeconv() and the call to sprintf() or strtod(), the result may + be wrong. setlocale() is not thread-safe and should not be used + this way. Multi-threaded programs should use uselocale() instead. +*/ + +static void to_locale(strbuffer_t *strbuffer) +{ + const char *point; + char *pos; + + point = localeconv()->decimal_point; + if(*point == '.') { + /* No conversion needed */ + return; + } + + pos = strchr(strbuffer->value, '.'); + if(pos) + *pos = *point; +} + +static void from_locale(char *buffer) +{ + const char *point; + char *pos; + + point = localeconv()->decimal_point; + if(*point == '.') { + /* No conversion needed */ + return; + } + + pos = strchr(buffer, *point); + if(pos) + *pos = '.'; +} +#endif + +int jsonp_strtod(strbuffer_t *strbuffer, double *out) +{ + double value; + char *end; + +#if JSON_HAVE_LOCALECONV + to_locale(strbuffer); +#endif + + errno = 0; + value = strtod(strbuffer->value, &end); + assert(end == strbuffer->value + strbuffer->length); + + if(errno == ERANGE && value != 0) { + /* Overflow */ + return -1; + } + + *out = value; + return 0; +} + +int jsonp_dtostr(char *buffer, size_t size, double value) +{ + int ret; + char *start, *end; + size_t length; + + ret = snprintf(buffer, size, "%.17g", value); + if(ret < 0) + return -1; + + length = (size_t)ret; + if(length >= size) + return -1; + +#if JSON_HAVE_LOCALECONV + from_locale(buffer); +#endif + + /* Make sure there's a dot or 'e' in the output. Otherwise + a real is converted to an integer when decoding */ + if(strchr(buffer, '.') == NULL && + strchr(buffer, 'e') == NULL) + { + if(length + 3 >= size) { + /* No space to append ".0" */ + return -1; + } + buffer[length] = '.'; + buffer[length + 1] = '0'; + buffer[length + 2] = '\0'; + length += 2; + } + + /* Remove leading '+' from positive exponent. Also remove leading + zeros from exponents (added by some printf() implementations) */ + start = strchr(buffer, 'e'); + if(start) { + start++; + end = start + 1; + + if(*start == '-') + start++; + + while(*end == '0') + end++; + + if(end != start) { + memmove(start, end, length - (size_t)(end - buffer)); + length -= (size_t)(end - start); + } + } + + return (int)length; +} diff --git a/compat/jansson/utf.c b/compat/jansson/utf.c index 2b64450..65b849b 100644 --- a/compat/jansson/utf.c +++ b/compat/jansson/utf.c @@ -1,190 +1,190 @@ -/* - * Copyright (c) 2009, 2010 Petri Lehtinen - * - * Jansson is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See LICENSE for details. - */ - -#include -#include "utf.h" - -int utf8_encode(int32_t codepoint, char *buffer, int *size) -{ - if(codepoint < 0) - return -1; - else if(codepoint < 0x80) - { - buffer[0] = (char)codepoint; - *size = 1; - } - else if(codepoint < 0x800) - { - buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); - buffer[1] = 0x80 + ((codepoint & 0x03F)); - *size = 2; - } - else if(codepoint < 0x10000) - { - buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); - buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); - buffer[2] = 0x80 + ((codepoint & 0x003F)); - *size = 3; - } - else if(codepoint <= 0x10FFFF) - { - buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); - buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); - buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); - buffer[3] = 0x80 + ((codepoint & 0x00003F)); - *size = 4; - } - else - return -1; - - return 0; -} - -int utf8_check_first(char byte) -{ - unsigned char u = (unsigned char)byte; - - if(u < 0x80) - return 1; - - if(0x80 <= u && u <= 0xBF) { - /* second, third or fourth byte of a multi-byte - sequence, i.e. a "continuation byte" */ - return 0; - } - else if(u == 0xC0 || u == 0xC1) { - /* overlong encoding of an ASCII byte */ - return 0; - } - else if(0xC2 <= u && u <= 0xDF) { - /* 2-byte sequence */ - return 2; - } - - else if(0xE0 <= u && u <= 0xEF) { - /* 3-byte sequence */ - return 3; - } - else if(0xF0 <= u && u <= 0xF4) { - /* 4-byte sequence */ - return 4; - } - else { /* u >= 0xF5 */ - /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid - UTF-8 */ - return 0; - } -} - -int utf8_check_full(const char *buffer, int size, int32_t *codepoint) -{ - int i; - int32_t value = 0; - unsigned char u = (unsigned char)buffer[0]; - - if(size == 2) - { - value = u & 0x1F; - } - else if(size == 3) - { - value = u & 0xF; - } - else if(size == 4) - { - value = u & 0x7; - } - else - return 0; - - for(i = 1; i < size; i++) - { - u = (unsigned char)buffer[i]; - - if(u < 0x80 || u > 0xBF) { - /* not a continuation byte */ - return 0; - } - - value = (value << 6) + (u & 0x3F); - } - - if(value > 0x10FFFF) { - /* not in Unicode range */ - return 0; - } - - else if(0xD800 <= value && value <= 0xDFFF) { - /* invalid code point (UTF-16 surrogate halves) */ - return 0; - } - - else if((size == 2 && value < 0x80) || - (size == 3 && value < 0x800) || - (size == 4 && value < 0x10000)) { - /* overlong encoding */ - return 0; - } - - if(codepoint) - *codepoint = value; - - return 1; -} - -const char *utf8_iterate(const char *buffer, int32_t *codepoint) -{ - int count; - int32_t value; - - if(!*buffer) - return buffer; - - count = utf8_check_first(buffer[0]); - if(count <= 0) - return NULL; - - if(count == 1) - value = (unsigned char)buffer[0]; - else - { - if(!utf8_check_full(buffer, count, &value)) - return NULL; - } - - if(codepoint) - *codepoint = value; - - return buffer + count; -} - -int utf8_check_string(const char *string, int length) -{ - int i; - - if(length == -1) - length = strlen(string); - - for(i = 0; i < length; i++) - { - int count = utf8_check_first(string[i]); - if(count == 0) - return 0; - else if(count > 1) - { - if(i + count > length) - return 0; - - if(!utf8_check_full(&string[i], count, NULL)) - return 0; - - i += count - 1; - } - } - - return 1; -} +/* + * Copyright (c) 2009-2013 Petri Lehtinen + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include +#include "utf.h" + +int utf8_encode(int32_t codepoint, char *buffer, int *size) +{ + if(codepoint < 0) + return -1; + else if(codepoint < 0x80) + { + buffer[0] = (char)codepoint; + *size = 1; + } + else if(codepoint < 0x800) + { + buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); + buffer[1] = 0x80 + ((codepoint & 0x03F)); + *size = 2; + } + else if(codepoint < 0x10000) + { + buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); + buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); + buffer[2] = 0x80 + ((codepoint & 0x003F)); + *size = 3; + } + else if(codepoint <= 0x10FFFF) + { + buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); + buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); + buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); + buffer[3] = 0x80 + ((codepoint & 0x00003F)); + *size = 4; + } + else + return -1; + + return 0; +} + +int utf8_check_first(char byte) +{ + unsigned char u = (unsigned char)byte; + + if(u < 0x80) + return 1; + + if(0x80 <= u && u <= 0xBF) { + /* second, third or fourth byte of a multi-byte + sequence, i.e. a "continuation byte" */ + return 0; + } + else if(u == 0xC0 || u == 0xC1) { + /* overlong encoding of an ASCII byte */ + return 0; + } + else if(0xC2 <= u && u <= 0xDF) { + /* 2-byte sequence */ + return 2; + } + + else if(0xE0 <= u && u <= 0xEF) { + /* 3-byte sequence */ + return 3; + } + else if(0xF0 <= u && u <= 0xF4) { + /* 4-byte sequence */ + return 4; + } + else { /* u >= 0xF5 */ + /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid + UTF-8 */ + return 0; + } +} + +int utf8_check_full(const char *buffer, int size, int32_t *codepoint) +{ + int i; + int32_t value = 0; + unsigned char u = (unsigned char)buffer[0]; + + if(size == 2) + { + value = u & 0x1F; + } + else if(size == 3) + { + value = u & 0xF; + } + else if(size == 4) + { + value = u & 0x7; + } + else + return 0; + + for(i = 1; i < size; i++) + { + u = (unsigned char)buffer[i]; + + if(u < 0x80 || u > 0xBF) { + /* not a continuation byte */ + return 0; + } + + value = (value << 6) + (u & 0x3F); + } + + if(value > 0x10FFFF) { + /* not in Unicode range */ + return 0; + } + + else if(0xD800 <= value && value <= 0xDFFF) { + /* invalid code point (UTF-16 surrogate halves) */ + return 0; + } + + else if((size == 2 && value < 0x80) || + (size == 3 && value < 0x800) || + (size == 4 && value < 0x10000)) { + /* overlong encoding */ + return 0; + } + + if(codepoint) + *codepoint = value; + + return 1; +} + +const char *utf8_iterate(const char *buffer, int32_t *codepoint) +{ + int count; + int32_t value; + + if(!*buffer) + return buffer; + + count = utf8_check_first(buffer[0]); + if(count <= 0) + return NULL; + + if(count == 1) + value = (unsigned char)buffer[0]; + else + { + if(!utf8_check_full(buffer, count, &value)) + return NULL; + } + + if(codepoint) + *codepoint = value; + + return buffer + count; +} + +int utf8_check_string(const char *string, int length) +{ + int i; + + if(length == -1) + length = strlen(string); + + for(i = 0; i < length; i++) + { + int count = utf8_check_first(string[i]); + if(count == 0) + return 0; + else if(count > 1) + { + if(i + count > length) + return 0; + + if(!utf8_check_full(&string[i], count, NULL)) + return 0; + + i += count - 1; + } + } + + return 1; +} diff --git a/compat/jansson/utf.h b/compat/jansson/utf.h index 8e95296..4c8fc57 100644 --- a/compat/jansson/utf.h +++ b/compat/jansson/utf.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -8,14 +8,25 @@ #ifndef UTF_H #define UTF_H -#include +#ifdef HAVE_CONFIG_H +#include "jansson_private_config.h" #ifdef HAVE_INTTYPES_H /* inttypes.h includes stdint.h in a standard environment, so there's no need to include stdint.h separately. If inttypes.h doesn't define int32_t, it's defined in config.h. */ #include -#endif +#endif /* HAVE_INTTYPES_H */ + +#else /* !HAVE_CONFIG_H */ +#ifdef _WIN32 +typedef int int32_t; +#else /* !_WIN32 */ +/* Assume a standard environment */ +#include +#endif /* _WIN32 */ + +#endif /* HAVE_CONFIG_H */ int utf8_encode(int codepoint, char *buffer, int *size); diff --git a/compat/jansson/value.c b/compat/jansson/value.c index 591b89e..1e7697c 100644 --- a/compat/jansson/value.c +++ b/compat/jansson/value.c @@ -1,25 +1,33 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen + * Copyright (c) 2009-2013 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif -#include - +#include #include #include +#include -#include +#include "jansson.h" #include "hashtable.h" #include "jansson_private.h" #include "utf.h" -#include "util.h" +/* Work around nonstandard isnan() and isinf() implementations */ +#ifndef isnan +static JSON_INLINE int isnan(double x) { return x != x; } +#endif +#ifndef isinf +static JSON_INLINE int isinf(double x) { return !isnan(x) && isnan(x - x); } +#endif -static inline void json_init(json_t *json, json_type type) +static JSON_INLINE void json_init(json_t *json, json_type type) { json->type = type; json->refcount = 1; @@ -28,50 +36,16 @@ static inline void json_init(json_t *json, json_type type) /*** object ***/ -/* This macro just returns a pointer that's a few bytes backwards from - string. This makes it possible to pass a pointer to object_key_t - when only the string inside it is used, without actually creating - an object_key_t instance. */ -#define string_to_key(string) container_of(string, object_key_t, key) - -static unsigned int hash_key(const void *ptr) -{ - const char *str = ((const object_key_t *)ptr)->key; - - unsigned int hash = 5381; - unsigned int c; - - while((c = (unsigned int)*str)) - { - hash = ((hash << 5) + hash) + c; - str++; - } - - return hash; -} - -static int key_equal(const void *ptr1, const void *ptr2) -{ - return strcmp(((const object_key_t *)ptr1)->key, - ((const object_key_t *)ptr2)->key) == 0; -} - -static void value_decref(void *value) -{ - json_decref((json_t *)value); -} - json_t *json_object(void) { - json_object_t *object = malloc(sizeof(json_object_t)); + json_object_t *object = jsonp_malloc(sizeof(json_object_t)); if(!object) return NULL; json_init(&object->json, JSON_OBJECT); - if(hashtable_init(&object->hashtable, hash_key, key_equal, - free, value_decref)) + if(hashtable_init(&object->hashtable)) { - free(object); + jsonp_free(object); return NULL; } @@ -84,15 +58,15 @@ json_t *json_object(void) static void json_delete_object(json_object_t *object) { hashtable_close(&object->hashtable); - free(object); + jsonp_free(object); } -unsigned int json_object_size(const json_t *json) +size_t json_object_size(const json_t *json) { json_object_t *object; if(!json_is_object(json)) - return -1; + return 0; object = json_to_object(json); return object->hashtable.size; @@ -106,32 +80,24 @@ json_t *json_object_get(const json_t *json, const char *key) return NULL; object = json_to_object(json); - return hashtable_get(&object->hashtable, string_to_key(key)); + return hashtable_get(&object->hashtable, key); } int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value) { json_object_t *object; - object_key_t *k; - if(!key || !value) + if(!value) return -1; - if(!json_is_object(json) || json == value) + if(!key || !json_is_object(json) || json == value) { json_decref(value); return -1; } object = json_to_object(json); - k = malloc(sizeof(object_key_t) + strlen(key) + 1); - if(!k) - return -1; - - k->serial = object->serial++; - strcpy(k->key, key); - - if(hashtable_set(&object->hashtable, k, value)) + if(hashtable_set(&object->hashtable, key, object->serial++, value)) { json_decref(value); return -1; @@ -159,7 +125,7 @@ int json_object_del(json_t *json, const char *key) return -1; object = json_to_object(json); - return hashtable_del(&object->hashtable, string_to_key(key)); + return hashtable_del(&object->hashtable, key); } int json_object_clear(json_t *json) @@ -170,30 +136,56 @@ int json_object_clear(json_t *json) return -1; object = json_to_object(json); + hashtable_clear(&object->hashtable); + object->serial = 0; return 0; } int json_object_update(json_t *object, json_t *other) { - void *iter; + const char *key; + json_t *value; if(!json_is_object(object) || !json_is_object(other)) return -1; - iter = json_object_iter(other); - while(iter) { - const char *key; - json_t *value; - - key = json_object_iter_key(iter); - value = json_object_iter_value(iter); - + json_object_foreach(other, key, value) { if(json_object_set_nocheck(object, key, value)) return -1; + } + + return 0; +} + +int json_object_update_existing(json_t *object, json_t *other) +{ + const char *key; + json_t *value; + + if(!json_is_object(object) || !json_is_object(other)) + return -1; + + json_object_foreach(other, key, value) { + if(json_object_get(object, key)) + json_object_set_nocheck(object, key, value); + } + + return 0; +} + +int json_object_update_missing(json_t *object, json_t *other) +{ + const char *key; + json_t *value; + + if(!json_is_object(object) || !json_is_object(other)) + return -1; - iter = json_object_iter_next(other, iter); + json_object_foreach(other, key, value) { + if(!json_object_get(object, key)) + json_object_set_nocheck(object, key, value); } return 0; @@ -218,7 +210,7 @@ void *json_object_iter_at(json_t *json, const char *key) return NULL; object = json_to_object(json); - return hashtable_iter_at(&object->hashtable, string_to_key(key)); + return hashtable_iter_at(&object->hashtable, key); } void *json_object_iter_next(json_t *json, void *iter) @@ -232,20 +224,12 @@ void *json_object_iter_next(json_t *json, void *iter) return hashtable_iter_next(&object->hashtable, iter); } -const object_key_t *jsonp_object_iter_fullkey(void *iter) -{ - if(!iter) - return NULL; - - return hashtable_iter_key(iter); -} - const char *json_object_iter_key(void *iter) { if(!iter) return NULL; - return jsonp_object_iter_fullkey(iter)->key; + return hashtable_iter_key(iter); } json_t *json_object_iter_value(void *iter) @@ -258,38 +242,34 @@ json_t *json_object_iter_value(void *iter) int json_object_iter_set_new(json_t *json, void *iter, json_t *value) { - json_object_t *object; - if(!json_is_object(json) || !iter || !value) return -1; - object = json_to_object(json); - hashtable_iter_set(&object->hashtable, iter, value); - + hashtable_iter_set(iter, value); return 0; } +void *json_object_key_to_iter(const char *key) +{ + if(!key) + return NULL; + + return hashtable_key_to_iter(key); +} + static int json_object_equal(json_t *object1, json_t *object2) { - void *iter; + const char *key; + json_t *value1, *value2; if(json_object_size(object1) != json_object_size(object2)) return 0; - iter = json_object_iter(object1); - while(iter) - { - const char *key; - json_t *value1, *value2; - - key = json_object_iter_key(iter); - value1 = json_object_iter_value(iter); + json_object_foreach(object1, key, value1) { value2 = json_object_get(object2, key); if(!json_equal(value1, value2)) return 0; - - iter = json_object_iter_next(object1, iter); } return 1; @@ -298,29 +278,21 @@ static int json_object_equal(json_t *object1, json_t *object2) static json_t *json_object_copy(json_t *object) { json_t *result; - void *iter; + + const char *key; + json_t *value; result = json_object(); if(!result) return NULL; - iter = json_object_iter(object); - while(iter) - { - const char *key; - json_t *value; - - key = json_object_iter_key(iter); - value = json_object_iter_value(iter); + json_object_foreach(object, key, value) json_object_set_nocheck(result, key, value); - iter = json_object_iter_next(object, iter); - } - return result; } -static json_t *json_object_deep_copy(json_t *object) +static json_t *json_object_deep_copy(const json_t *object) { json_t *result; void *iter; @@ -329,17 +301,17 @@ static json_t *json_object_deep_copy(json_t *object) if(!result) return NULL; - iter = json_object_iter(object); - while(iter) - { + /* Cannot use json_object_foreach because object has to be cast + non-const */ + iter = json_object_iter((json_t *)object); + while(iter) { const char *key; - json_t *value; - + const json_t *value; key = json_object_iter_key(iter); value = json_object_iter_value(iter); - json_object_set_new_nocheck(result, key, json_deep_copy(value)); - iter = json_object_iter_next(object, iter); + json_object_set_new_nocheck(result, key, json_deep_copy(value)); + iter = json_object_iter_next((json_t *)object, iter); } return result; @@ -350,7 +322,7 @@ static json_t *json_object_deep_copy(json_t *object) json_t *json_array(void) { - json_array_t *array = malloc(sizeof(json_array_t)); + json_array_t *array = jsonp_malloc(sizeof(json_array_t)); if(!array) return NULL; json_init(&array->json, JSON_ARRAY); @@ -358,9 +330,9 @@ json_t *json_array(void) array->entries = 0; array->size = 8; - array->table = malloc(array->size * sizeof(json_t *)); + array->table = jsonp_malloc(array->size * sizeof(json_t *)); if(!array->table) { - free(array); + jsonp_free(array); return NULL; } @@ -371,16 +343,16 @@ json_t *json_array(void) static void json_delete_array(json_array_t *array) { - unsigned int i; + size_t i; for(i = 0; i < array->entries; i++) json_decref(array->table[i]); - free(array->table); - free(array); + jsonp_free(array->table); + jsonp_free(array); } -unsigned int json_array_size(const json_t *json) +size_t json_array_size(const json_t *json) { if(!json_is_array(json)) return 0; @@ -388,7 +360,7 @@ unsigned int json_array_size(const json_t *json) return json_to_array(json)->entries; } -json_t *json_array_get(const json_t *json, unsigned int index) +json_t *json_array_get(const json_t *json, size_t index) { json_array_t *array; if(!json_is_array(json)) @@ -401,7 +373,7 @@ json_t *json_array_get(const json_t *json, unsigned int index) return array->table[index]; } -int json_array_set_new(json_t *json, unsigned int index, json_t *value) +int json_array_set_new(json_t *json, size_t index, json_t *value) { json_array_t *array; @@ -427,24 +399,24 @@ int json_array_set_new(json_t *json, unsigned int index, json_t *value) return 0; } -static void array_move(json_array_t *array, unsigned int dest, - unsigned int src, unsigned int count) +static void array_move(json_array_t *array, size_t dest, + size_t src, size_t count) { memmove(&array->table[dest], &array->table[src], count * sizeof(json_t *)); } -static void array_copy(json_t **dest, unsigned int dpos, - json_t **src, unsigned int spos, - unsigned int count) +static void array_copy(json_t **dest, size_t dpos, + json_t **src, size_t spos, + size_t count) { memcpy(&dest[dpos], &src[spos], count * sizeof(json_t *)); } static json_t **json_array_grow(json_array_t *array, - unsigned int amount, + size_t amount, int copy) { - unsigned int new_size; + size_t new_size; json_t **old_table, **new_table; if(array->entries + amount <= array->size) @@ -453,7 +425,7 @@ static json_t **json_array_grow(json_array_t *array, old_table = array->table; new_size = max(array->size + amount, array->size * 2); - new_table = malloc(new_size * sizeof(json_t *)); + new_table = jsonp_malloc(new_size * sizeof(json_t *)); if(!new_table) return NULL; @@ -462,7 +434,7 @@ static json_t **json_array_grow(json_array_t *array, if(copy) { array_copy(array->table, 0, old_table, 0, array->entries); - free(old_table); + jsonp_free(old_table); return array->table; } @@ -494,7 +466,7 @@ int json_array_append_new(json_t *json, json_t *value) return 0; } -int json_array_insert_new(json_t *json, unsigned int index, json_t *value) +int json_array_insert_new(json_t *json, size_t index, json_t *value) { json_array_t *array; json_t **old_table; @@ -523,7 +495,7 @@ int json_array_insert_new(json_t *json, unsigned int index, json_t *value) array_copy(array->table, 0, old_table, 0, index); array_copy(array->table, index + 1, old_table, index, array->entries - index); - free(old_table); + jsonp_free(old_table); } else array_move(array, index + 1, index, array->entries - index); @@ -534,7 +506,7 @@ int json_array_insert_new(json_t *json, unsigned int index, json_t *value) return 0; } -int json_array_remove(json_t *json, unsigned int index) +int json_array_remove(json_t *json, size_t index) { json_array_t *array; @@ -547,7 +519,10 @@ int json_array_remove(json_t *json, unsigned int index) json_decref(array->table[index]); - array_move(array, index, index + 1, array->entries - index); + /* If we're removing the last element, nothing has to be moved */ + if(index < array->entries - 1) + array_move(array, index, index + 1, array->entries - index - 1); + array->entries--; return 0; @@ -556,7 +531,7 @@ int json_array_remove(json_t *json, unsigned int index) int json_array_clear(json_t *json) { json_array_t *array; - unsigned int i; + size_t i; if(!json_is_array(json)) return -1; @@ -572,7 +547,7 @@ int json_array_clear(json_t *json) int json_array_extend(json_t *json, json_t *other_json) { json_array_t *array, *other; - unsigned int i; + size_t i; if(!json_is_array(json) || !json_is_array(other_json)) return -1; @@ -593,7 +568,7 @@ int json_array_extend(json_t *json, json_t *other_json) static int json_array_equal(json_t *array1, json_t *array2) { - unsigned int i, size; + size_t i, size; size = json_array_size(array1); if(size != json_array_size(array2)) @@ -616,7 +591,7 @@ static int json_array_equal(json_t *array1, json_t *array2) static json_t *json_array_copy(json_t *array) { json_t *result; - unsigned int i; + size_t i; result = json_array(); if(!result) @@ -628,10 +603,10 @@ static json_t *json_array_copy(json_t *array) return result; } -static json_t *json_array_deep_copy(json_t *array) +static json_t *json_array_deep_copy(const json_t *array) { json_t *result; - unsigned int i; + size_t i; result = json_array(); if(!result) @@ -652,14 +627,14 @@ json_t *json_string_nocheck(const char *value) if(!value) return NULL; - string = malloc(sizeof(json_string_t)); + string = jsonp_malloc(sizeof(json_string_t)); if(!string) return NULL; json_init(&string->json, JSON_STRING); - string->value = strdup(value); + string->value = jsonp_strdup(value); if(!string->value) { - free(string); + jsonp_free(string); return NULL; } @@ -687,12 +662,15 @@ int json_string_set_nocheck(json_t *json, const char *value) char *dup; json_string_t *string; - dup = strdup(value); + if(!json_is_string(json) || !value) + return -1; + + dup = jsonp_strdup(value); if(!dup) return -1; string = json_to_string(json); - free(string->value); + jsonp_free(string->value); string->value = dup; return 0; @@ -708,8 +686,8 @@ int json_string_set(json_t *json, const char *value) static void json_delete_string(json_string_t *string) { - free(string->value); - free(string); + jsonp_free(string->value); + jsonp_free(string); } static int json_string_equal(json_t *string1, json_t *string2) @@ -717,7 +695,7 @@ static int json_string_equal(json_t *string1, json_t *string2) return strcmp(json_string_value(string1), json_string_value(string2)) == 0; } -static json_t *json_string_copy(json_t *string) +static json_t *json_string_copy(const json_t *string) { return json_string_nocheck(json_string_value(string)); } @@ -725,9 +703,9 @@ static json_t *json_string_copy(json_t *string) /*** integer ***/ -json_t *json_integer(int value) +json_t *json_integer(json_int_t value) { - json_integer_t *integer = malloc(sizeof(json_integer_t)); + json_integer_t *integer = jsonp_malloc(sizeof(json_integer_t)); if(!integer) return NULL; json_init(&integer->json, JSON_INTEGER); @@ -736,7 +714,7 @@ json_t *json_integer(int value) return &integer->json; } -int json_integer_value(const json_t *json) +json_int_t json_integer_value(const json_t *json) { if(!json_is_integer(json)) return 0; @@ -744,7 +722,7 @@ int json_integer_value(const json_t *json) return json_to_integer(json)->value; } -int json_integer_set(json_t *json, int value) +int json_integer_set(json_t *json, json_int_t value) { if(!json_is_integer(json)) return -1; @@ -756,7 +734,7 @@ int json_integer_set(json_t *json, int value) static void json_delete_integer(json_integer_t *integer) { - free(integer); + jsonp_free(integer); } static int json_integer_equal(json_t *integer1, json_t *integer2) @@ -764,7 +742,7 @@ static int json_integer_equal(json_t *integer1, json_t *integer2) return json_integer_value(integer1) == json_integer_value(integer2); } -static json_t *json_integer_copy(json_t *integer) +static json_t *json_integer_copy(const json_t *integer) { return json_integer(json_integer_value(integer)); } @@ -774,7 +752,12 @@ static json_t *json_integer_copy(json_t *integer) json_t *json_real(double value) { - json_real_t *real = malloc(sizeof(json_real_t)); + json_real_t *real; + + if(isnan(value) || isinf(value)) + return NULL; + + real = jsonp_malloc(sizeof(json_real_t)); if(!real) return NULL; json_init(&real->json, JSON_REAL); @@ -793,8 +776,8 @@ double json_real_value(const json_t *json) int json_real_set(json_t *json, double value) { - if(!json_is_real(json)) - return 0; + if(!json_is_real(json) || isnan(value) || isinf(value)) + return -1; json_to_real(json)->value = value; @@ -803,7 +786,7 @@ int json_real_set(json_t *json, double value) static void json_delete_real(json_real_t *real) { - free(real); + jsonp_free(real); } static int json_real_equal(json_t *real1, json_t *real2) @@ -811,7 +794,7 @@ static int json_real_equal(json_t *real1, json_t *real2) return json_real_value(real1) == json_real_value(real2); } -static json_t *json_real_copy(json_t *real) +static json_t *json_real_copy(const json_t *real) { return json_real(json_real_value(real)); } @@ -822,7 +805,7 @@ static json_t *json_real_copy(json_t *real) double json_number_value(const json_t *json) { if(json_is_integer(json)) - return json_integer_value(json); + return (double)json_integer_value(json); else if(json_is_real(json)) return json_real_value(json); else @@ -834,30 +817,21 @@ double json_number_value(const json_t *json) json_t *json_true(void) { - static json_t the_true = { - JSON_TRUE, - (unsigned int)-1 - }; + static json_t the_true = {JSON_TRUE, (size_t)-1}; return &the_true; } json_t *json_false(void) { - static json_t the_false = { - JSON_FALSE, - (unsigned int)-1 - }; + static json_t the_false = {JSON_FALSE, (size_t)-1}; return &the_false; } json_t *json_null(void) { - static json_t the_null = { - JSON_NULL, - (unsigned int)-1 - }; + static json_t the_null = {JSON_NULL, (size_t)-1}; return &the_null; } @@ -946,7 +920,7 @@ json_t *json_copy(json_t *json) return NULL; } -json_t *json_deep_copy(json_t *json) +json_t *json_deep_copy(const json_t *json) { if(!json) return NULL; @@ -970,7 +944,7 @@ json_t *json_deep_copy(json_t *json) return json_real_copy(json); if(json_is_true(json) || json_is_false(json) || json_is_null(json)) - return json; + return (json_t *)json; return NULL; } diff --git a/compat/libs/x64/libcrypto.lib b/compat/libs/x64/libcrypto.lib new file mode 100644 index 0000000..a364a4d Binary files /dev/null and b/compat/libs/x64/libcrypto.lib differ diff --git a/compat/libs/x64/libcurl.lib b/compat/libs/x64/libcurl.lib new file mode 100644 index 0000000..ded35f1 Binary files /dev/null and b/compat/libs/x64/libcurl.lib differ diff --git a/compat/libs/x64/pthreadVC2.lib b/compat/libs/x64/pthreadVC2.lib new file mode 100644 index 0000000..3e26e4a Binary files /dev/null and b/compat/libs/x64/pthreadVC2.lib differ diff --git a/compat/libs/x64/zlibstat.lib b/compat/libs/x64/zlibstat.lib new file mode 100644 index 0000000..5078caf Binary files /dev/null and b/compat/libs/x64/zlibstat.lib differ diff --git a/compat/libs/x86/libcrypto.lib b/compat/libs/x86/libcrypto.lib new file mode 100644 index 0000000..6a7068f Binary files /dev/null and b/compat/libs/x86/libcrypto.lib differ diff --git a/compat/libs/x86/libcurl.lib b/compat/libs/x86/libcurl.lib new file mode 100644 index 0000000..e227cfd Binary files /dev/null and b/compat/libs/x86/libcurl.lib differ diff --git a/compat/libs/x86/pthreadVC2.lib b/compat/libs/x86/pthreadVC2.lib new file mode 100644 index 0000000..5880478 Binary files /dev/null and b/compat/libs/x86/pthreadVC2.lib differ diff --git a/compat/libs/x86/zlibstat.lib b/compat/libs/x86/zlibstat.lib new file mode 100644 index 0000000..387e902 Binary files /dev/null and b/compat/libs/x86/zlibstat.lib differ diff --git a/compat/thrust/CHANGELOG b/compat/thrust/CHANGELOG deleted file mode 100644 index 110c668..0000000 --- a/compat/thrust/CHANGELOG +++ /dev/null @@ -1,662 +0,0 @@ -####################################### -# Thrust v1.7.0 # -####################################### - -Summary - Thrust 1.7.0 introduces a new interface for controlling algorithm execution as - well as several new algorithms and performance improvements. With this new - interface, users may directly control how algorithms execute as well as details - such as the allocation of temporary storage. Key/value versions of thrust::merge - and the set operation algorithms have been added, as well stencil versions of - partitioning algorithms. thrust::tabulate has been introduced to tabulate the - values of functions taking integers. For 32b types, new CUDA merge and set - operations provide 2-15x faster performance while a new CUDA comparison sort - provides 1.3-4x faster performance. Finally, a new TBB reduce_by_key implementation - provides 80% faster performance. - -Breaking API Changes - Dispatch - Custom user backend systems' tag types must now inherit from the corresponding system's execution_policy template (e.g. thrust::cuda::execution_policy) instead - of the tag struct (e.g. thrust::cuda::tag). Otherwise, algorithm specializations will silently go unfound during dispatch. - See examples/minimal_custom_backend.cu and examples/cuda/fallback_allocator.cu for usage examples. - - thrust::advance and thrust::distance are no longer dispatched based on iterator system type and thus may no longer be customized. - - Iterators - iterator_facade and iterator_adaptor's Pointer template parameters have been eliminated. - iterator_adaptor has been moved into the thrust namespace (previously thrust::experimental::iterator_adaptor). - iterator_facade has been moved into the thrust namespace (previously thrust::experimental::iterator_facade). - iterator_core_access has been moved into the thrust namespace (previously thrust::experimental::iterator_core_access). - All iterators' nested pointer typedef (the type of the result of operator->) is now void instead of a pointer type to indicate that such expressions are currently impossible. - Floating point counting_iterators' nested difference_type typedef is now a signed integral type instead of a floating point type. - - Other - normal_distribution has been moved into the thrust::random namespace (previously thrust::random::experimental::normal_distribution). - Placeholder expressions may no longer include the comma operator. - -New Features - Execution Policies - Users may directly control the dispatch of algorithm invocations with optional execution policy arguments. - For example, instead of wrapping raw pointers allocated by cudaMalloc with thrust::device_ptr, the thrust::device execution_policy may be passed as an argument to an algorithm invocation to enable CUDA execution. - The following execution policies are supported in this version: - - thrust::host - thrust::device - thrust::cpp::par - thrust::cuda::par - thrust::omp::par - thrust::tbb::par - - Algorithms - free - get_temporary_buffer - malloc - merge_by_key - partition with stencil - partition_copy with stencil - return_temporary_buffer - set_difference_by_key - set_intersection_by_key - set_symmetric_difference_by_key - set_union_by_key - stable_partition with stencil - stable_partition_copy with stencil - tabulate - -New Examples - uninitialized_vector demonstrates how to use a custom allocator to avoid the automatic initialization of elements in thrust::device_vector. - -Other Enhancements - Authors of custom backend systems may manipulate arbitrary state during algorithm dispatch by incorporating it into their execution_policy parameter. - Users may control the allocation of temporary storage during algorithm execution by passing standard allocators as parameters via execution policies such as thrust::device. - THRUST_DEVICE_SYSTEM_CPP has been added as a compile-time target for the device backend. - CUDA merge performance is 2-15x faster. - CUDA comparison sort performance is 1.3-4x faster. - CUDA set operation performance is 1.5-15x faster. - TBB reduce_by_key performance is 80% faster. - Several algorithms have been parallelized with TBB. - Support for user allocators in vectors has been improved. - The sparse_vector example is now implemented with merge_by_key instead of sort_by_key. - Warnings have been eliminated in various contexts. - Warnings about __host__ or __device__-only functions called from __host__ __device__ functions have been eliminated in various contexts. - Documentation about algorithm requirements have been improved. - Simplified the minimal_custom_backend example. - Simplified the cuda/custom_temporary_allocation example. - Simplified the cuda/fallback_allocator example. - -Bug Fixes - #248 fix broken counting_iterator behavior with OpenMP - #231, #209 fix set operation failures with CUDA - #187 fix incorrect occupancy calculation with CUDA - #153 fix broken multigpu behavior with CUDA - #142 eliminate warning produced by thrust::random::taus88 and MSVC 2010 - #208 correctly initialize elements in temporary storage when necessary - #16 fix compilation error when sorting bool with CUDA - #10 fix ambiguous overloads of reinterpret_tag - -Known Issues - g++ versions 4.3 and lower may fail to dispatch thrust::get_temporary_buffer correctly causing infinite recursion in examples such as cuda/custom_temporary_allocation. - -Acknowledgments - Thanks to Sean Baxter, Bryan Catanzaro, and Manjunath Kudlur for contributing a faster merge implementation for CUDA. - Thanks to Sean Baxter for contributing a faster set operation implementation for CUDA. - Thanks to Cliff Woolley for contributing a correct occupancy calculation algorithm. - -####################################### -# Thrust v1.6.0 # -####################################### - -Summary - Thrust v1.6.0 provides an interface for customization and extension and a new - backend system based on the Threading Building Blocks library. With this - new interface, programmers may customize the behavior of specific algorithms - as well as control the allocation of temporary storage or invent entirely new - backends. These enhancements also allow multiple different backend systems - such as CUDA and OpenMP to coexist within a single program. Support for TBB - allows Thrust programs to integrate more naturally into applications which - may already employ the TBB task scheduler. - -Breaking API Changes - The header has been moved to - thrust::experimental::cuda::pinned_allocator has been moved to thrust::cuda::experimental::pinned_allocator - The macro THRUST_DEVICE_BACKEND has been renamed THRUST_DEVICE_SYSTEM - The macro THRUST_DEVICE_BACKEND_CUDA has been renamed THRUST_DEVICE_SYSTEM_CUDA - The macro THRUST_DEVICE_BACKEND_OMP has been renamed THRUST_DEVICE_SYSTEM_OMP - thrust::host_space_tag has been renamed thrust::host_system_tag - thrust::device_space_tag has been renamed thrust::device_system_tag - thrust::any_space_tag has been renamed thrust::any_system_tag - thrust::iterator_space has been renamed thrust::iterator_system - - -New Features - Backend Systems - Threading Building Blocks (TBB) is now supported - Functions - for_each_n - raw_reference_cast - Types - pointer - reference - -New Examples - cuda/custom_temporary_allocation - cuda/fallback_allocator - device_ptr - expand - minimal_custom_backend - raw_reference_cast - set_operations - -Other Enhancements - thrust::for_each now returns the end of the input range similar to most other algorithms - thrust::pair and thrust::tuple have swap functionality - all CUDA algorithms now support large data types - iterators may be dereferenced in user __device__ or __global__ functions - the safe use of different backend systems is now possible within a single binary - -Bug Fixes - #469 min_element and max_element algorithms no longer require a const comparison operator - -Known Issues - cudafe++.exe may crash when parsing TBB headers on Windows. - -####################################### -# Thrust v1.5.3 # -####################################### - -Summary - Small bug fixes - -Bug Fixes - Avoid warnings about potential race due to __shared__ non-POD variable - -####################################### -# Thrust v1.5.2 # -####################################### - -Summary - Small bug fixes - -Bug Fixes - Fixed warning about C-style initialization of structures - -####################################### -# Thrust v1.5.1 # -####################################### - -Summary - Small bug fixes - -Bug Fixes - Sorting data referenced by permutation_iterators on CUDA produces invalid results - -####################################### -# Thrust v1.5.0 # -####################################### - -Summary - Thrust v1.5.0 provides introduces new programmer productivity and performance - enhancements. New functionality for creating anonymous "lambda" functions has - been added. A faster host sort provides 2-10x faster performance for sorting - arithmetic types on (single-threaded) CPUs. A new OpenMP sort provides - 2.5x-3.0x speedup over the host sort using a quad-core CPU. When sorting - arithmetic types with the OpenMP backend the combined performance improvement - is 5.9x for 32-bit integers and ranges from 3.0x (64-bit types) to 14.2x - (8-bit types). A new CUDA reduce_by_key implementation provides 2-3x faster - performance. - -Breaking API Changes - device_ptr no longer unsafely converts to device_ptr without an - explicit cast. Use the expression - device_pointer_cast(static_cast(void_ptr.get())) - to convert, for example, device_ptr to device_ptr. - -New Features - Functions - stencil-less transform_if - - Types - lambda placeholders - -New Examples - lambda - -Other Enhancements - host sort is 2-10x faster for arithmetic types - OMP sort provides speedup over host sort - reduce_by_key is 2-3x faster - reduce_by_key no longer requires O(N) temporary storage - CUDA scan algorithms are 10-40% faster - host_vector and device_vector are now documented - out-of-memory exceptions now provide detailed information from CUDART - improved histogram example - device_reference now has a specialized swap - reduce_by_key and scan algorithms are compatible with discard_iterator - -Removed Functionality - -Bug Fixes - #44 allow host_vector to compile when value_type uses __align__ - #198 allow adjacent_difference to permit safe in-situ operation - #303 make thrust thread-safe - #313 avoid race conditions in device_vector::insert - #314 avoid unintended adl invocation when dispatching copy - #365 fix merge and set operation failures - -Known Issues - None - -Acknowledgments - Thanks to Manjunath Kudlur for contributing his Carbon library, from which the lambda functionality is derived. - Thanks to Jean-Francois Bastien for suggesting a fix for issue 303. - -####################################### -# Thrust v1.4.0 # -####################################### - -Summary - Thrust v1.4.0 provides support for CUDA 4.0 in addition to many feature - and performance improvements. New set theoretic algorithms operating on - sorted sequences have been added. Additionally, a new fancy iterator - allows discarding redundant or otherwise unnecessary output from - algorithms, conserving memory storage and bandwidth. - -Breaking API Changes - Eliminations - thrust/is_sorted.h - thrust/utility.h - thrust/set_intersection.h - thrust/experimental/cuda/ogl_interop_allocator.h and the functionality therein - thrust::deprecated::copy_when - thrust::deprecated::absolute_value - -New Features - Functions - copy_n - merge - set_difference - set_symmetric_difference - set_union - - Types - discard_iterator - - Device support - Compute Capability 2.1 GPUs - -New Examples - run_length_decoding - -Other Enhancements - Compilation warnings are substantially reduced in various contexts. - The compilation time of thrust::sort, thrust::stable_sort, thrust::sort_by_key, - and thrust::stable_sort_by_key are substantially reduced. - A fast sort implementation is used when sorting primitive types with thrust::greater. - The performance of thrust::set_intersection is improved. - The performance of thrust::fill is improved on SM 1.x devices. - A code example is now provided in each algorithm's documentation. - thrust::reverse now operates in-place - -Removed Functionality - thrust::deprecated::copy_when - thrust::deprecated::absolute_value - thrust::experimental::cuda::ogl_interop_allocator - thrust::gather and thrust::scatter from host to device and vice versa are no longer supported. - Operations which modify the elements of a thrust::device_vector are no longer - available from source code compiled without nvcc when the device backend is CUDA. - Instead, use the idiom from the cpp_interop example. - -Bug Fixes - #212 set_intersection works correctly for large input sizes. - #275 counting_iterator and constant_iterator work correctly with OpenMP as the - backend when compiling with optimization - #256 min and max correctly return their first argument as a tie-breaker - #248 NDEBUG is interpreted correctly - -Known Issues - nvcc may generate code containing warnings when compiling some Thrust algorithms. - When compiling with -arch=sm_1x, some Thrust algorithms may cause nvcc to issue - benign pointer advisories. - When compiling with -arch=sm_1x and -G, some Thrust algorithms may fail to execute correctly. - thrust::inclusive_scan, thrust::exclusive_scan, thrust::inclusive_scan_by_key, - and thrust::exclusive_scan_by_key are currently incompatible with thrust::discard_iterator. - -Acknowledgments - Thanks to David Tarjan for improving the performance of set_intersection. - Thanks to Duane Merrill for continued help with sort. - Thanks to Nathan Whitehead for help with CUDA Toolkit integration. - -####################################### -# Thrust v1.3.0 # -####################################### - -Summary - Thrust v1.3.0 provides support for CUDA 3.2 in addition to many feature - and performance enhancements. - - Performance of the sort and sort_by_key algorithms is improved by as much - as 3x in certain situations. The performance of stream compaction algorithms, - such as copy_if, is improved by as much as 2x. Reduction performance is - also improved, particularly for small input sizes. - - CUDA errors are now converted to runtime exceptions using the system_error - interface. Combined with a debug mode, also new in v1.3, runtime errors - can be located with greater precision. - - Lastly, a few header files have been consolidated or renamed for clarity. - See the deprecations section below for additional details. - - -Breaking API Changes - Promotions - thrust::experimental::inclusive_segmented_scan has been renamed thrust::inclusive_scan_by_key and exposes a different interface - thrust::experimental::exclusive_segmented_scan has been renamed thrust::exclusive_scan_by_key and exposes a different interface - thrust::experimental::partition_copy has been renamed thrust::partition_copy and exposes a different interface - thrust::next::gather has been renamed thrust::gather - thrust::next::gather_if has been renamed thrust::gather_if - thrust::unique_copy_by_key has been renamed thrust::unique_by_key_copy - Deprecations - thrust::copy_when has been renamed thrust::deprecated::copy_when - thrust::absolute_value has been renamed thrust::deprecated::absolute_value - The header thrust/set_intersection.h is now deprecated; use thrust/set_operations.h instead - The header thrust/utility.h is now deprecated; use thrust/swap.h instead - The header thrust/swap_ranges.h is now deprecated; use thrust/swap.h instead - Eliminations - thrust::deprecated::gather - thrust::deprecated::gather_if - thrust/experimental/arch.h and the functions therein - thrust/sorting/merge_sort.h - thrust/sorting/radix_sort.h - -New Features - Functions - exclusive_scan_by_key - find - find_if - find_if_not - inclusive_scan_by_key - is_partitioned - is_sorted_until - mismatch - partition_point - reverse - reverse_copy - stable_partition_copy - - Types - system_error and related types - experimental::cuda::ogl_interop_allocator - bit_and, bit_or, and bit_xor - - Device support - gf104-based GPUs - -New Examples - opengl_interop.cu - repeated_range.cu - simple_moving_average.cu - sparse_vector.cu - strided_range.cu - -Other Enhancements - Performance of thrust::sort and thrust::sort_by_key is substantially improved for primitive key types - Performance of thrust::copy_if is substantially improved - Performance of thrust::reduce and related reductions is improved - THRUST_DEBUG mode added - Callers of Thrust functions may detect error conditions by catching thrust::system_error, which derives from std::runtime_error - The number of compiler warnings generated by Thrust has been substantially reduced - Comparison sort now works correctly for input sizes > 32M - min & max usage no longer collides with definitions - Compiling against the OpenMP backend no longer requires nvcc - Performance of device_vector initialized in .cpp files is substantially improved in common cases - Performance of thrust::sort_by_key on the host is substantially improved - -Removed Functionality - nvcc 2.3 is no longer supported - -Bug Fixes - Debug device code now compiles correctly - thrust::uninitialized_copy and thrust::unintialized_fill now dispatch constructors on the device rather than the host - -Known Issues - #212 set_intersection is known to fail for large input sizes - partition_point is known to fail for 64b types with nvcc 3.2 - -Acknowledgments - Thanks to Duane Merrill for contributing a fast CUDA radix sort implementation - Thanks to Erich Elsen for contributing an implementation of find_if - Thanks to Andrew Corrigan for contributing changes which allow the OpenMP backend to compile in the absence of nvcc - Thanks to Andrew Corrigan, Cliff Wooley, David Coeurjolly, Janick Martinez Esturo, John Bowers, Maxim Naumov, Michael Garland, and Ryuta Suzuki for bug reports - Thanks to Cliff Woolley for help with testing - -####################################### -# Thrust v1.2.1 # -####################################### - -Summary - Small fixes for compatibility with CUDA 3.1 - -Known Issues - inclusive_scan & exclusive_scan may fail with very large types - the Microsoft compiler may fail to compile code using both sort and binary search algorithms - uninitialized_fill & uninitialized_copy dispatch constructors on the host rather than the device - # 109 some algorithms may exhibit poor performance with the OpenMP backend with large numbers (>= 6) of CPU threads - default_random_engine::discard is not accelerated with nvcc 2.3 - nvcc 3.1 may fail to compile code using types derived from thrust::subtract_with_carry_engine, such as thrust::ranlux24 & thrust::ranlux48. - -####################################### -# Thrust v1.2.0 # -####################################### - -Summary - Thrust v1.2 introduces support for compilation to multicore CPUs - and the Ocelot virtual machine, and several new facilities for - pseudo-random number generation. New algorithms such as set - intersection and segmented reduction have also been added. Lastly, - improvements to the robustness of the CUDA backend ensure - correctness across a broad set of (uncommon) use cases. - -Breaking API Changes - thrust::gather's interface was incorrect and has been removed. - The old interface is deprecated but will be preserved for Thrust - version 1.2 at thrust::deprecated::gather & - thrust::deprecated::gather_if. The new interface is provided at - thrust::next::gather & thrust::next::gather_if. The new interface - will be promoted to thrust:: in Thrust version 1.3. For more details, - please refer to this thread: - http://groups.google.com/group/thrust-users/browse_thread/thread/f5f0583cb97b51fd - - The thrust::sorting namespace has been deprecated in favor of the - top-level sorting functions, such as thrust::sort() and - thrust::sort_by_key(). - -New Features - Functions - reduce_by_key - set_intersection - tie - unique_copy - unique_by_key - unique_copy_by_key - - Types - Random Number Generation - discard_block_engine - default_random_engine - linear_congruential_engine - linear_feedback_shift_engine - minstd_rand - minstd_rand0 - normal_distribution (experimental) - ranlux24 - ranlux48 - ranlux24_base - ranlux48_base - subtract_with_carry_engine - taus88 - uniform_int_distribution - uniform_real_distribution - xor_combine_engine - Functionals - project1st - project2nd - - Fancy Iterators - permutation_iterator - reverse_iterator - - Device support - Add support for multicore CPUs via OpenMP - Add support for Fermi-class GPUs - Add support for Ocelot virtual machine - -New Examples - cpp_integration - histogram - mode - monte_carlo - monte_carlo_disjoint_sequences - padded_grid_reduction - permutation_iterator - row_sum - run_length_encoding - segmented_scan - stream_compaction - summary_statistics - transform_iterator - word_count - -Other Enhancements - vector functions operator!=, rbegin, crbegin, rend, crend, data, & shrink_to_fit - integer sorting performance is improved when max is large but (max - min) is small and when min is negative - performance of inclusive_scan() and exclusive_scan() is improved by 20-25% for primitive types - support for nvcc 3.0 - -Removed Functionality - removed support for equal between host & device sequences - removed support for gather() and scatter() between host & device sequences - -Bug Fixes - # 8 cause a compiler error if the required compiler is not found rather than a mysterious error at link time - # 42 device_ptr & device_reference are classes rather than structs, eliminating warnings on certain platforms - # 46 gather & scatter handle any space iterators correctly - # 51 thrust::experimental::arch functions gracefully handle unrecognized GPUs - # 52 avoid collisions with common user macros such as BLOCK_SIZE - # 62 provide better documentation for device_reference - # 68 allow built-in CUDA vector types to work with device_vector in pure C++ mode - # 102 eliminated a race condition in device_vector::erase - various compilation warnings eliminated - -Known Issues - inclusive_scan & exclusive_scan may fail with very large types - the Microsoft compiler may fail to compile code using both sort and binary search algorithms - uninitialized_fill & uninitialized_copy dispatch constructors on the host rather than the device - # 109 some algorithms may exhibit poor performance with the OpenMP backend with large numbers (>= 6) of CPU threads - default_random_engine::discard is not accelerated with nvcc 2.3 - -Acknowledgments - Thanks to Gregory Diamos for contributing a CUDA implementation of set_intersection - Thanks to Ryuta Suzuki & Gregory Diamos for rigorously testing Thrust's unit tests and examples against Ocelot - Thanks to Tom Bradley for contributing an implementation of normal_distribution - Thanks to Joseph Rhoads for contributing the example summary_statistics - -####################################### -# Thrust v1.1.1 # -####################################### - -Summary - Small fixes for compatibility with CUDA 2.3a and Mac OSX Snow Leopard. - -####################################### -# Thrust v1.1.0 # -####################################### - -Summary - Thrust v1.1 introduces fancy iterators, binary search functions, and - several specialized reduction functions. Experimental support for - segmented scan has also been added. - -Breaking API Changes - counting_iterator has been moved into the thrust namespace (previously thrust::experimental) - -New Features - Functions - copy_if - lower_bound - upper_bound - vectorized lower_bound - vectorized upper_bound - equal_range - binary_search - vectorized binary_search - all_of - any_of - none_of - minmax_element - advance - inclusive_segmented_scan (experimental) - exclusive_segmented_scan (experimental) - - Types - pair - tuple - device_malloc_allocator - - Fancy Iterators - constant_iterator - counting_iterator - transform_iterator - zip_iterator - -New Examples - computing the maximum absolute difference between vectors - computing the bounding box of a two-dimensional point set - sorting multiple arrays together (lexicographical sorting) - constructing a summed area table - using zip_iterator to mimic an array of structs - using constant_iterator to increment array values - -Other Enhancements - added pinned memory allocator (experimental) - added more methods to host_vector & device_vector (issue #4) - added variant of remove_if with a stencil argument (issue #29) - scan and reduce use cudaFuncGetAttributes to determine grid size - exceptions are reported when temporary device arrays cannot be allocated - -Bug Fixes - #5 make vector work for larger data types - #9 stable_partition_copy doesn't respect OutputIterator concept semantics - #10 scans should return OutputIterator - #16 make algorithms work for larger data types - #27 dispatch radix_sort even when comp=less is explicitly provided - -Known Issues - Using functors with Thrust entry points may not compile on Mac OSX with gcc-4.0.1 - uninitialized_copy & uninitialized_fill dispatch constructors on the host rather than the device. - inclusive_scan, inclusive_scan_by_key, exclusive_scan, and exclusive_scan_by_key may fail when used with large types with the CUDA 3.1 driver - - -####################################### -# Thrust v1.0.0 # -####################################### - -Breaking API changes - Rename top level namespace komrade to thrust. - Move partition_copy() & stable_partition_copy() into thrust::experimental namespace until we can easily provide the standard interface. - Rename range() to sequence() to avoid collision with Boost.Range. - Rename copy_if() to copy_when() due to semantic differences with C++0x copy_if(). - -New Features - Add C++0x style cbegin() & cend() methods to host_vector & device_vector. - Add transform_if function. - Add stencil versions of replace_if() & replace_copy_if(). - Allow counting_iterator to work with for_each(). - Allow types with constructors in comparison sort & reduce. - -Other Enhancements - merge_sort and stable_merge_sort are now 2 to 5x faster when executed on the parallel device. - -Bug fixes - Workaround an issue where an incremented iterator causes nvcc to crash. (Komrade issue #6) - Fix an issue where const_iterators could not be passed to transform. (Komrade issue #7) - diff --git a/compat/thrust/adjacent_difference.h b/compat/thrust/adjacent_difference.h deleted file mode 100644 index 772b5f9..0000000 --- a/compat/thrust/adjacent_difference.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file adjacent_difference.h - * \brief Compute difference between consecutive elements of a range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup transformations Transformations - * \{ - */ - - -/*! \p adjacent_difference calculates the differences of adjacent elements in the - * range [first, last). That is, \*first is assigned to - * \*result, and, for each iterator \p i in the range - * [first + 1, last), the difference of \*i and *(i - 1) - * is assigned to \*(result + (i - first)). - * - * This version of \p adjacent_difference uses operator- to calculate - * differences. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \return The iterator result + (last - first) - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \c x and \c y are objects of \p InputIterator's \c value_type, then \c x - \c is defined, - * and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, - * and the return type of x - y is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \remark Note that \p result is permitted to be the same iterator as \p first. This is - * useful for computing differences "in place". - * - * The following code snippet demonstrates how to use \p adjacent_difference to compute - * the difference between adjacent elements of a range using the \p thrust::device execution policy: - * - * \code - * #include - * #include - * #include - * ... - * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; - * thrust::device_vector d_data(h_data, h_data + 8); - * thrust::device_vector d_result(8); - * - * thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin()); - * - * // d_result is now [1, 1, -1, 1, -1, 1, -1, 1] - * \endcode - * - * \see http://www.sgi.com/tech/stl/adjacent_difference.html - * \see inclusive_scan - */ -template -OutputIterator adjacent_difference(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result); - -/*! \p adjacent_difference calculates the differences of adjacent elements in the - * range [first, last). That is, *first is assigned to - * \*result, and, for each iterator \p i in the range - * [first + 1, last), binary_op(\*i, \*(i - 1)) is assigned to - * \*(result + (i - first)). - * - * This version of \p adjacent_difference uses the binary function \p binary_op to - * calculate differences. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \param binary_op The binary function used to compute differences. - * \return The iterator result + (last - first) - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p BinaryFunction's \c first_argument_type and \c second_argument_type, - * and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam BinaryFunction's \c result_type is convertible to a type in \p OutputIterator's set of \c value_types. - * - * \remark Note that \p result is permitted to be the same iterator as \p first. This is - * useful for computing differences "in place". - * - * The following code snippet demonstrates how to use \p adjacent_difference to compute - * the sum between adjacent elements of a range using the \p thrust::device execution policy: - * - * \code - * #include - * #include - * #include - * #include - * ... - * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; - * thrust::device_vector d_data(h_data, h_data + 8); - * thrust::device_vector d_result(8); - * - * thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin(), thrust::plus()); - * - * // d_data is now [1, 3, 3, 3, 3, 3, 3, 3] - * \endcode - * - * \see http://www.sgi.com/tech/stl/adjacent_difference.html - * \see inclusive_scan - */ -template -OutputIterator adjacent_difference(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op); - -/*! \p adjacent_difference calculates the differences of adjacent elements in the - * range [first, last). That is, \*first is assigned to - * \*result, and, for each iterator \p i in the range - * [first + 1, last), the difference of \*i and *(i - 1) - * is assigned to \*(result + (i - first)). - * - * This version of \p adjacent_difference uses operator- to calculate - * differences. - * - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \return The iterator result + (last - first) - * - * \tparam InputIterator is a model of Input Iterator, - * and \c x and \c y are objects of \p InputIterator's \c value_type, then \c x - \c is defined, - * and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, - * and the return type of x - y is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \remark Note that \p result is permitted to be the same iterator as \p first. This is - * useful for computing differences "in place". - * - * The following code snippet demonstrates how to use \p adjacent_difference to compute - * the difference between adjacent elements of a range. - * - * \code - * #include - * #include - * ... - * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; - * thrust::device_vector d_data(h_data, h_data + 8); - * thrust::device_vector d_result(8); - * - * thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin()); - * - * // d_result is now [1, 1, -1, 1, -1, 1, -1, 1] - * \endcode - * - * \see http://www.sgi.com/tech/stl/adjacent_difference.html - * \see inclusive_scan - */ -template -OutputIterator adjacent_difference(InputIterator first, InputIterator last, - OutputIterator result); - -/*! \p adjacent_difference calculates the differences of adjacent elements in the - * range [first, last). That is, *first is assigned to - * \*result, and, for each iterator \p i in the range - * [first + 1, last), binary_op(\*i, \*(i - 1)) is assigned to - * \*(result + (i - first)). - * - * This version of \p adjacent_difference uses the binary function \p binary_op to - * calculate differences. - * - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \param binary_op The binary function used to compute differences. - * \return The iterator result + (last - first) - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p BinaryFunction's \c first_argument_type and \c second_argument_type, - * and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam BinaryFunction's \c result_type is convertible to a type in \p OutputIterator's set of \c value_types. - * - * \remark Note that \p result is permitted to be the same iterator as \p first. This is - * useful for computing differences "in place". - * - * The following code snippet demonstrates how to use \p adjacent_difference to compute - * the sum between adjacent elements of a range. - * - * \code - * #include - * #include - * #include - * ... - * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; - * thrust::device_vector d_data(h_data, h_data + 8); - * thrust::device_vector d_result(8); - * - * thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin(), thrust::plus()); - * - * // d_data is now [1, 3, 3, 3, 3, 3, 3, 3] - * \endcode - * - * \see http://www.sgi.com/tech/stl/adjacent_difference.html - * \see inclusive_scan - */ -template -OutputIterator adjacent_difference(InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op); - -/*! \} - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/advance.h b/compat/thrust/advance.h deleted file mode 100644 index e7f60b0..0000000 --- a/compat/thrust/advance.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file advance.h - * \brief Advance an iterator by a given distance. - */ - -#pragma once - -#include - -namespace thrust -{ - - -/*! \addtogroup iterators - * \{ - */ - -/*! \p advance(i, n) increments the iterator \p i by the distance \p n. - * If n > 0 it is equivalent to executing ++i \p n - * times, and if n < 0 it is equivalent to executing --i - * \p n times. If n == 0, the call has no effect. - * - * \param i The iterator to be advanced. - * \param n The distance by which to advance the iterator. - * - * \tparam InputIterator is a model of Input Iterator. - * \tparam Distance is an integral type that is convertible to \p InputIterator's distance type. - * - * \pre \p n shall be negative only for bidirectional and random access iterators. - * - * The following code snippet demonstrates how to use \p advance to increment - * an iterator a given number of times. - * - * \code - * #include - * #include - * ... - * thrust::device_vector vec(13); - * thrust::device_vector::iterator iter = vec.begin(); - * - * thrust::advance(iter, 7); - * - * // iter - vec.begin() == 7 - * \endcode - * - * \see http://www.sgi.com/tech/stl/advance.html - */ -template -void advance(InputIterator& i, Distance n); - -/*! \} // end iterators - */ - -} // end thrust - -#include - diff --git a/compat/thrust/binary_search.h b/compat/thrust/binary_search.h deleted file mode 100644 index d2ac5a6..0000000 --- a/compat/thrust/binary_search.h +++ /dev/null @@ -1,1888 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file binary_search.h - * \brief Search for values in sorted ranges. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - - -/*! \addtogroup searching - * \ingroup algorithms - * \{ - */ - - -/*! \addtogroup binary_search Binary Search - * \ingroup searching - * \{ - */ - - -////////////////////// -// Scalar Functions // -////////////////////// - - -/*! \p lower_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the first position where value could be - * inserted without violating the ordering. This version of - * \p lower_bound uses operator< for comparison and returns - * the furthermost iterator \c i in [first, last) such that, - * for every iterator \c j in [first, i), *j < value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return The furthermost iterator \c i, such that *i < value. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::lower_bound(thrust::device, input.begin(), input.end(), 0); // returns input.begin() - * thrust::lower_bound(thrust::device, input.begin(), input.end(), 1); // returns input.begin() + 1 - * thrust::lower_bound(thrust::device, input.begin(), input.end(), 2); // returns input.begin() + 1 - * thrust::lower_bound(thrust::device, input.begin(), input.end(), 3); // returns input.begin() + 2 - * thrust::lower_bound(thrust::device, input.begin(), input.end(), 8); // returns input.begin() + 4 - * thrust::lower_bound(thrust::device, input.begin(), input.end(), 9); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value); - - -/*! \p lower_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the first position where value could be - * inserted without violating the ordering. This version of - * \p lower_bound uses operator< for comparison and returns - * the furthermost iterator \c i in [first, last) such that, - * for every iterator \c j in [first, i), *j < value. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return The furthermost iterator \c i, such that *i < value. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::lower_bound(input.begin(), input.end(), 0); // returns input.begin() - * thrust::lower_bound(input.begin(), input.end(), 1); // returns input.begin() + 1 - * thrust::lower_bound(input.begin(), input.end(), 2); // returns input.begin() + 1 - * thrust::lower_bound(input.begin(), input.end(), 3); // returns input.begin() + 2 - * thrust::lower_bound(input.begin(), input.end(), 8); // returns input.begin() + 4 - * thrust::lower_bound(input.begin(), input.end(), 9); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator lower_bound(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value); - - -/*! \p lower_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the first position where value could be - * inserted without violating the ordering. This version of - * \p lower_bound uses function object \c comp for comparison - * and returns the furthermost iterator \c i in [first, last) - * such that, for every iterator \c j in [first, i), - * comp(*j, value) is \c true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return The furthermost iterator \c i, such that comp(*i, value) is \c true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::lower_bound(input.begin(), input.end(), 0, thrust::less()); // returns input.begin() - * thrust::lower_bound(input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 - * thrust::lower_bound(input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 1 - * thrust::lower_bound(input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 - * thrust::lower_bound(input.begin(), input.end(), 8, thrust::less()); // returns input.begin() + 4 - * thrust::lower_bound(input.begin(), input.end(), 9, thrust::less()); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value, - StrictWeakOrdering comp); - - -/*! \p lower_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the first position where value could be - * inserted without violating the ordering. This version of - * \p lower_bound uses function object \c comp for comparison - * and returns the furthermost iterator \c i in [first, last) - * such that, for every iterator \c j in [first, i), - * comp(*j, value) is \c true. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return The furthermost iterator \c i, such that comp(*i, value) is \c true. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::lower_bound(input.begin(), input.end(), 0, thrust::less()); // returns input.begin() - * thrust::lower_bound(input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 - * thrust::lower_bound(input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 1 - * thrust::lower_bound(input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 - * thrust::lower_bound(input.begin(), input.end(), 8, thrust::less()); // returns input.begin() + 4 - * thrust::lower_bound(input.begin(), input.end(), 9, thrust::less()); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator lower_bound(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp); - - -/*! \p upper_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the last position where value could be - * inserted without violating the ordering. This version of - * \p upper_bound uses operator< for comparison and returns - * the furthermost iterator \c i in [first, last) such that, - * for every iterator \c j in [first, i), value < *j - * is \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return The furthermost iterator \c i, such that value < *i is \c false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p upper_bound - * to search for values in a ordered range using the \p thrust::device execution policy for parallelism: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 0); // returns input.begin() + 1 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 1); // returns input.begin() + 1 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 2); // returns input.begin() + 2 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 3); // returns input.begin() + 2 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 8); // returns input.end() - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 9); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p lower_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value); - - -/*! \p upper_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the last position where value could be - * inserted without violating the ordering. This version of - * \p upper_bound uses operator< for comparison and returns - * the furthermost iterator \c i in [first, last) such that, - * for every iterator \c j in [first, i), value < *j - * is \c false. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return The furthermost iterator \c i, such that value < *i is \c false. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p upper_bound - * to search for values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::upper_bound(input.begin(), input.end(), 0); // returns input.begin() + 1 - * thrust::upper_bound(input.begin(), input.end(), 1); // returns input.begin() + 1 - * thrust::upper_bound(input.begin(), input.end(), 2); // returns input.begin() + 2 - * thrust::upper_bound(input.begin(), input.end(), 3); // returns input.begin() + 2 - * thrust::upper_bound(input.begin(), input.end(), 8); // returns input.end() - * thrust::upper_bound(input.begin(), input.end(), 9); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p lower_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator upper_bound(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value); - - -/*! \p upper_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the last position where value could be - * inserted without violating the ordering. This version of - * \p upper_bound uses function object \c comp for comparison and returns - * the furthermost iterator \c i in [first, last) such that, - * for every iterator \c j in [first, i), comp(value, *j) - * is \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return The furthermost iterator \c i, such that comp(value, *i) is \c false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p upper_bound - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 0, thrust::less()); // returns input.begin() + 1 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 2 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 8, thrust::less()); // returns input.end() - * thrust::upper_bound(thrust::device, input.begin(), input.end(), 9, thrust::less()); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p lower_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value, - StrictWeakOrdering comp); - -/*! \p upper_bound is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * Specifically, it returns the last position where value could be - * inserted without violating the ordering. This version of - * \p upper_bound uses function object \c comp for comparison and returns - * the furthermost iterator \c i in [first, last) such that, - * for every iterator \c j in [first, i), comp(value, *j) - * is \c false. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return The furthermost iterator \c i, such that comp(value, *i) is \c false. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p upper_bound - * to search for values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::upper_bound(input.begin(), input.end(), 0, thrust::less()); // returns input.begin() + 1 - * thrust::upper_bound(input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 - * thrust::upper_bound(input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 2 - * thrust::upper_bound(input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 - * thrust::upper_bound(input.begin(), input.end(), 8, thrust::less()); // returns input.end() - * thrust::upper_bound(input.begin(), input.end(), 9, thrust::less()); // returns input.end() - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p lower_bound - * \see \p equal_range - * \see \p binary_search - */ -template -ForwardIterator upper_bound(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp); - - -/*! \p binary_search is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. Specifically, this version returns \c true if and only if - * there exists an iterator \c i in [first, last) such that - * *i < value and value < *i are both \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return \c true if an equivalent element exists in [first, last), otherwise \c false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::binary_search(thrust::device, input.begin(), input.end(), 0); // returns true - * thrust::binary_search(thrust::device, input.begin(), input.end(), 1); // returns false - * thrust::binary_search(thrust::device, input.begin(), input.end(), 2); // returns true - * thrust::binary_search(thrust::device, input.begin(), input.end(), 3); // returns false - * thrust::binary_search(thrust::device, input.begin(), input.end(), 8); // returns true - * thrust::binary_search(thrust::device, input.begin(), input.end(), 9); // returns false - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -bool binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value); - - -/*! \p binary_search is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. Specifically, this version returns \c true if and only if - * there exists an iterator \c i in [first, last) such that - * *i < value and value < *i are both \c false. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return \c true if an equivalent element exists in [first, last), otherwise \c false. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::binary_search(input.begin(), input.end(), 0); // returns true - * thrust::binary_search(input.begin(), input.end(), 1); // returns false - * thrust::binary_search(input.begin(), input.end(), 2); // returns true - * thrust::binary_search(input.begin(), input.end(), 3); // returns false - * thrust::binary_search(input.begin(), input.end(), 8); // returns true - * thrust::binary_search(input.begin(), input.end(), 9); // returns false - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -bool binary_search(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value); - - -/*! \p binary_search is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. Specifically, this version returns \c true if and only if - * there exists an iterator \c i in [first, last) such that - * comp(*i, value) and comp(value, *i) are both \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return \c true if an equivalent element exists in [first, last), otherwise \c false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::binary_search(thrust::device, input.begin(), input.end(), 0, thrust::less()); // returns true - * thrust::binary_search(thrust::device, input.begin(), input.end(), 1, thrust::less()); // returns false - * thrust::binary_search(thrust::device, input.begin(), input.end(), 2, thrust::less()); // returns true - * thrust::binary_search(thrust::device, input.begin(), input.end(), 3, thrust::less()); // returns false - * thrust::binary_search(thrust::device, input.begin(), input.end(), 8, thrust::less()); // returns true - * thrust::binary_search(thrust::device, input.begin(), input.end(), 9, thrust::less()); // returns false - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -bool binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp); - - -/*! \p binary_search is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. Specifically, this version returns \c true if and only if - * there exists an iterator \c i in [first, last) such that - * comp(*i, value) and comp(value, *i) are both \c false. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return \c true if an equivalent element exists in [first, last), otherwise \c false. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::binary_search(input.begin(), input.end(), 0, thrust::less()); // returns true - * thrust::binary_search(input.begin(), input.end(), 1, thrust::less()); // returns false - * thrust::binary_search(input.begin(), input.end(), 2, thrust::less()); // returns true - * thrust::binary_search(input.begin(), input.end(), 3, thrust::less()); // returns false - * thrust::binary_search(input.begin(), input.end(), 8, thrust::less()); // returns true - * thrust::binary_search(input.begin(), input.end(), 9, thrust::less()); // returns false - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -bool binary_search(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp); - - -/*! \p equal_range is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). The - * value returned by \p equal_range is essentially a combination of - * the values returned by \p lower_bound and \p upper_bound: it returns - * a \p pair of iterators \c i and \c j such that \c i is the first - * position where value could be inserted without violating the - * ordering and \c j is the last position where value could be inserted - * without violating the ordering. It follows that every element in the - * range [i, j) is equivalent to value, and that - * [i, j) is the largest subrange of [first, last) that - * has this property. - * - * This version of \p equal_range returns a \p pair of iterators - * [i, j), where \c i is the furthermost iterator in - * [first, last) such that, for every iterator \c k in - * [first, i), *k < value. \c j is the furthermost - * iterator in [first, last) such that, for every iterator - * \c k in [first, j), value < *k is \c false. - * For every iterator \c k in [i, j), neither - * value < *k nor *k < value is \c true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return A \p pair of iterators [i, j) that define the range of equivalent elements. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p equal_range - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::equal_range(thrust::device, input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + 1) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + 2) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + 2) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 9); // returns [input.end(), input.end) - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal_range.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p binary_search - */ -template -thrust::pair -equal_range(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value); - - -/*! \p equal_range is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). The - * value returned by \p equal_range is essentially a combination of - * the values returned by \p lower_bound and \p upper_bound: it returns - * a \p pair of iterators \c i and \c j such that \c i is the first - * position where value could be inserted without violating the - * ordering and \c j is the last position where value could be inserted - * without violating the ordering. It follows that every element in the - * range [i, j) is equivalent to value, and that - * [i, j) is the largest subrange of [first, last) that - * has this property. - * - * This version of \p equal_range returns a \p pair of iterators - * [i, j), where \c i is the furthermost iterator in - * [first, last) such that, for every iterator \c k in - * [first, i), *k < value. \c j is the furthermost - * iterator in [first, last) such that, for every iterator - * \c k in [first, j), value < *k is \c false. - * For every iterator \c k in [i, j), neither - * value < *k nor *k < value is \c true. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \return A \p pair of iterators [i, j) that define the range of equivalent elements. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam LessThanComparable is a model of LessThanComparable. - * - * The following code snippet demonstrates how to use \p equal_range - * to search for values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::equal_range(input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1) - * thrust::equal_range(input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + 1) - * thrust::equal_range(input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + 2) - * thrust::equal_range(input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + 2) - * thrust::equal_range(input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end) - * thrust::equal_range(input.begin(), input.end(), 9); // returns [input.end(), input.end) - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal_range.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p binary_search - */ -template -thrust::pair -equal_range(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value); - - -/*! \p equal_range is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). The - * value returned by \p equal_range is essentially a combination of - * the values returned by \p lower_bound and \p upper_bound: it returns - * a \p pair of iterators \c i and \c j such that \c i is the first - * position where value could be inserted without violating the - * ordering and \c j is the last position where value could be inserted - * without violating the ordering. It follows that every element in the - * range [i, j) is equivalent to value, and that - * [i, j) is the largest subrange of [first, last) that - * has this property. - * - * This version of \p equal_range returns a \p pair of iterators - * [i, j). \c i is the furthermost iterator in - * [first, last) such that, for every iterator \c k in - * [first, i), comp(*k, value) is \c true. - * \c j is the furthermost iterator in [first, last) such - * that, for every iterator \c k in [first, last), - * comp(value, *k) is \c false. For every iterator \c k - * in [i, j), neither comp(value, *k) nor - * comp(*k, value) is \c true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return A \p pair of iterators [i, j) that define the range of equivalent elements. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p equal_range - * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::equal_range(thrust::device, input.begin(), input.end(), 0, thrust::less()); // returns [input.begin(), input.begin() + 1) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 1, thrust::less()); // returns [input.begin() + 1, input.begin() + 1) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 2, thrust::less()); // returns [input.begin() + 1, input.begin() + 2) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 3, thrust::less()); // returns [input.begin() + 2, input.begin() + 2) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 8, thrust::less()); // returns [input.begin() + 4, input.end) - * thrust::equal_range(thrust::device, input.begin(), input.end(), 9, thrust::less()); // returns [input.end(), input.end) - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal_range.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p binary_search - */ -template -thrust::pair -equal_range(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp); - - -/*! \p equal_range is a version of binary search: it attempts to find - * the element value in an ordered range [first, last). The - * value returned by \p equal_range is essentially a combination of - * the values returned by \p lower_bound and \p upper_bound: it returns - * a \p pair of iterators \c i and \c j such that \c i is the first - * position where value could be inserted without violating the - * ordering and \c j is the last position where value could be inserted - * without violating the ordering. It follows that every element in the - * range [i, j) is equivalent to value, and that - * [i, j) is the largest subrange of [first, last) that - * has this property. - * - * This version of \p equal_range returns a \p pair of iterators - * [i, j). \c i is the furthermost iterator in - * [first, last) such that, for every iterator \c k in - * [first, i), comp(*k, value) is \c true. - * \c j is the furthermost iterator in [first, last) such - * that, for every iterator \c k in [first, last), - * comp(value, *k) is \c false. For every iterator \c k - * in [i, j), neither comp(value, *k) nor - * comp(*k, value) is \c true. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param value The value to be searched. - * \param comp The comparison operator. - * \return A \p pair of iterators [i, j) that define the range of equivalent elements. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam T is comparable to \p ForwardIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p equal_range - * to search for values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::equal_range(input.begin(), input.end(), 0, thrust::less()); // returns [input.begin(), input.begin() + 1) - * thrust::equal_range(input.begin(), input.end(), 1, thrust::less()); // returns [input.begin() + 1, input.begin() + 1) - * thrust::equal_range(input.begin(), input.end(), 2, thrust::less()); // returns [input.begin() + 1, input.begin() + 2) - * thrust::equal_range(input.begin(), input.end(), 3, thrust::less()); // returns [input.begin() + 2, input.begin() + 2) - * thrust::equal_range(input.begin(), input.end(), 8, thrust::less()); // returns [input.begin() + 4, input.end) - * thrust::equal_range(input.begin(), input.end(), 9, thrust::less()); // returns [input.end(), input.end) - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal_range.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p binary_search - */ -template -thrust::pair -equal_range(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp); - - -/*! \addtogroup vectorized_binary_search Vectorized Searches - * \ingroup binary_search - * \{ - */ - - -////////////////////// -// Vector Functions // -////////////////////// - - -/*! \p lower_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of first position where value could - * be inserted without violating the ordering. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::lower_bound(thrust::device, - * input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin()); - * - * // output is now [0, 1, 1, 2, 4, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result); - - -/*! \p lower_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of first position where value could - * be inserted without violating the ordering. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::lower_bound(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin()); - * - * // output is now [0, 1, 1, 2, 4, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator lower_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result); - - -/*! \p lower_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of first position where value could - * be inserted without violating the ordering. This version of - * \p lower_bound uses function object \c comp for comparison. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * \param comp The comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::lower_bound(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin(), - * thrust::less()); - * - * // output is now [0, 1, 1, 2, 4, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result, - StrictWeakOrdering comp); - - -/*! \p lower_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of first position where value could - * be inserted without violating the ordering. This version of - * \p lower_bound uses function object \c comp for comparison. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * \param comp The comparison operator. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::lower_bound(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin(), - * thrust::less()); - * - * // output is now [0, 1, 1, 2, 4, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/lower_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator lower_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result, - StrictWeakOrdering comp); - - -/*! \p upper_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of last position where value could - * be inserted without violating the ordering. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::upper_bound(thrust::device, - * input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin()); - * - * // output is now [1, 1, 2, 2, 5, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result); - - -/*! \p upper_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of last position where value could - * be inserted without violating the ordering. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::upper_bound(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin()); - * - * // output is now [1, 1, 2, 2, 5, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p upper_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator upper_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result); - - -/*! \p upper_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of first position where value could - * be inserted without violating the ordering. This version of - * \p upper_bound uses function object \c comp for comparison. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * \param comp The comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::upper_bound(thrust::device, - * input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin(), - * thrust::less()); - * - * // output is now [1, 1, 2, 2, 5, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p lower_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result, - StrictWeakOrdering comp); - - -/*! \p upper_bound is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * Specifically, it returns the index of first position where value could - * be inserted without violating the ordering. This version of - * \p upper_bound uses function object \c comp for comparison. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * \param comp The comparison operator. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator. - * and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p lower_bound - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::upper_bound(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin(), - * thrust::less()); - * - * // output is now [1, 1, 2, 2, 5, 5] - * \endcode - * - * \see http://www.sgi.com/tech/stl/upper_bound.html - * \see \p lower_bound - * \see \p equal_range - * \see \p binary_search - */ -template -OutputIterator upper_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result, - StrictWeakOrdering comp); - - -/*! \p binary_search is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and bool is convertible to \c OutputIterator's \c value_type. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for multiple values in a ordered range using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::binary_search(thrust::device, - * input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin()); - * - * // output is now [true, false, true, false, true, false] - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -OutputIterator binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result); - - -/*! \p binary_search is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and bool is convertible to \c OutputIterator's \c value_type. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::binary_search(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin()); - * - * // output is now [true, false, true, false, true, false] - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -OutputIterator binary_search(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result); - - -/*! \p binary_search is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. This version of \p binary_search uses function object - * \c comp for comparison. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * \param comp The comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and bool is convertible to \c OutputIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for multiple values in a ordered range using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::binary_search(thrust::device, - * input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin(), - * thrust::less()); - * - * // output is now [true, false, true, false, true, false] - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -OutputIterator binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result, - StrictWeakOrdering comp); - - -/*! \p binary_search is a vectorized version of binary search: for each - * iterator \c v in [values_first, values_last) it attempts to - * find the value *v in an ordered range [first, last). - * It returns \c true if an element that is equivalent to \c value - * is present in [first, last) and \c false if no such element - * exists. This version of \p binary_search uses function object - * \c comp for comparison. - * - * \param first The beginning of the ordered sequence. - * \param last The end of the ordered sequence. - * \param values_first The beginning of the search values sequence. - * \param values_last The end of the search values sequence. - * \param result The beginning of the output sequence. - * \param comp The comparison operator. - * - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam InputIterator is a model of Input Iterator. - * and \c InputIterator's \c value_type is LessThanComparable. - * \tparam OutputIterator is a model of Output Iterator. - * and bool is convertible to \c OutputIterator's \c value_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p binary_search - * to search for multiple values in a ordered range. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(5); - * - * input[0] = 0; - * input[1] = 2; - * input[2] = 5; - * input[3] = 7; - * input[4] = 8; - * - * thrust::device_vector values(6); - * values[0] = 0; - * values[1] = 1; - * values[2] = 2; - * values[3] = 3; - * values[4] = 8; - * values[5] = 9; - * - * thrust::device_vector output(6); - * - * thrust::binary_search(input.begin(), input.end(), - * values.begin(), values.end(), - * output.begin(), - * thrust::less()); - * - * // output is now [true, false, true, false, true, false] - * \endcode - * - * \see http://www.sgi.com/tech/stl/binary_search.html - * \see \p lower_bound - * \see \p upper_bound - * \see \p equal_range - */ -template -OutputIterator binary_search(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator result, - StrictWeakOrdering comp); - - -/*! \} // end vectorized_binary_search - */ - - -/*! \} // end binary_search - */ - - -/*! \} // end searching - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/copy.h b/compat/thrust/copy.h deleted file mode 100644 index eaa9719..0000000 --- a/compat/thrust/copy.h +++ /dev/null @@ -1,505 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file copy.h - * \brief Copies elements from one range to another - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -/*! \addtogroup algorithms - */ - -/*! \addtogroup copying - * \ingroup algorithms - * \{ - */ - - -/*! \p copy copies elements from the range [\p first, \p last) to the range - * [\p result, \p result + (\p last - \p first)). That is, it performs - * the assignments *\p result = *\p first, *(\p result + \c 1) = *(\p first + \c 1), - * and so on. Generally, for every integer \c n from \c 0 to \p last - \p first, \p copy - * performs the assignment *(\p result + \c n) = *(\p first + \c n). Unlike - * \c std::copy, \p copy offers no guarantee on order of operation. As a result, - * calling \p copy with overlapping source and destination ranges has undefined - * behavior. - * - * The return value is \p result + (\p last - \p first). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to copy. - * \param last The end of the sequence to copy. - * \param result The destination sequence. - * \return The end of the destination sequence. - * \see http://www.sgi.com/tech/stl/copy.html - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre \p result may be equal to \p first, but \p result shall not be in the range [first, last) otherwise. - * - * The following code snippet demonstrates how to use \p copy - * to copy from one range to another using the \p thrust::device parallelization policy: - * - * \code - * #include - * #include - * #include - * ... - * - * thrust::device_vector vec0(100); - * thrust::device_vector vec1(100); - * ... - * - * thrust::copy(thrust::device, vec0.begin(), vec0.end(), vec1.begin()); - * - * // vec1 is now a copy of vec0 - * \endcode - */ -template - OutputIterator copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p copy_n copies elements from the range [first, first + n) to the range - * [result, result + n). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), - * and so on. Generally, for every integer \c i from \c 0 to \c n, \p copy - * performs the assignment *(\p result + \c i) = *(\p first + \c i). Unlike - * \c std::copy_n, \p copy_n offers no guarantee on order of operation. As a result, - * calling \p copy_n with overlapping source and destination ranges has undefined - * behavior. - * - * The return value is \p result + \p n. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range to copy. - * \param n The number of elements to copy. - * \param result The beginning destination range. - * \return The end of the destination range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam Size is an integral type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre \p result may be equal to \p first, but \p result shall not be in the range [first, first + n) otherwise. - * - * The following code snippet demonstrates how to use \p copy - * to copy from one range to another using the \p thrust::device parallelization policy: - * - * \code - * #include - * #include - * #include - * ... - * size_t n = 100; - * thrust::device_vector vec0(n); - * thrust::device_vector vec1(n); - * ... - * thrust::copy_n(thrust::device, vec0.begin(), n, vec1.begin()); - * - * // vec1 is now a copy of vec0 - * \endcode - * - * \see http://www.sgi.com/tech/stl/copy_n.html - * \see thrust::copy - */ -template - OutputIterator copy_n(const thrust::detail::execution_policy_base &exec, - InputIterator first, - Size n, - OutputIterator result); - - - -/*! \p copy copies elements from the range [\p first, \p last) to the range - * [\p result, \p result + (\p last - \p first)). That is, it performs - * the assignments *\p result = *\p first, *(\p result + \c 1) = *(\p first + \c 1), - * and so on. Generally, for every integer \c n from \c 0 to \p last - \p first, \p copy - * performs the assignment *(\p result + \c n) = *(\p first + \c n). Unlike - * \c std::copy, \p copy offers no guarantee on order of operation. As a result, - * calling \p copy with overlapping source and destination ranges has undefined - * behavior. - * - * The return value is \p result + (\p last - \p first). - * - * \param first The beginning of the sequence to copy. - * \param last The end of the sequence to copy. - * \param result The destination sequence. - * \return The end of the destination sequence. - * \see http://www.sgi.com/tech/stl/copy.html - * - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre \p result may be equal to \p first, but \p result shall not be in the range [first, last) otherwise. - * - * The following code snippet demonstrates how to use \p copy - * to copy from one range to another. - * - * \code - * #include - * #include - * ... - * - * thrust::device_vector vec0(100); - * thrust::device_vector vec1(100); - * ... - * - * thrust::copy(vec0.begin(), vec0.end(), - * vec1.begin()); - * - * // vec1 is now a copy of vec0 - * \endcode - */ -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result); - -/*! \p copy_n copies elements from the range [first, first + n) to the range - * [result, result + n). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), - * and so on. Generally, for every integer \c i from \c 0 to \c n, \p copy - * performs the assignment *(\p result + \c i) = *(\p first + \c i). Unlike - * \c std::copy_n, \p copy_n offers no guarantee on order of operation. As a result, - * calling \p copy_n with overlapping source and destination ranges has undefined - * behavior. - * - * The return value is \p result + \p n. - * - * \param first The beginning of the range to copy. - * \param n The number of elements to copy. - * \param result The beginning destination range. - * \return The end of the destination range. - * - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam Size is an integral type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre \p result may be equal to \p first, but \p result shall not be in the range [first, first + n) otherwise. - * - * The following code snippet demonstrates how to use \p copy - * to copy from one range to another. - * - * \code - * #include - * #include - * ... - * size_t n = 100; - * thrust::device_vector vec0(n); - * thrust::device_vector vec1(n); - * ... - * thrust::copy_n(vec0.begin(), n, vec1.begin()); - * - * // vec1 is now a copy of vec0 - * \endcode - * - * \see http://www.sgi.com/tech/stl/copy_n.html - * \see thrust::copy - */ -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result); - -/*! \} // end copying - */ - -/*! \addtogroup stream_compaction - * \{ - */ - - -/*! This version of \p copy_if copies elements from the range [first,last) - * to a range beginning at \ presult, except that any element which causes \p pred - * to be \p pred to be \c false is not copied. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p copy_if performs the assignment *result = *(first+n) and \p result - * is advanced one position if pred(*(first+n)). Otherwise, no assignment - * occurs and \p result is not advanced. - * - * The algorithm's execution is parallelized as determined by \p system. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence from which to copy. - * \param last The end of the sequence from which to copy. - * \param result The beginning of the sequence into which to copy. - * \param pred The predicate to test on every value of the range [first, last). - * \return result + n, where \c n is equal to the number of times \p pred - * evaluated to \c true in the range [first, last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The ranges [first, last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p copy_if to perform stream compaction - * to copy even numbers to an output range using the \p thrust::host parallelization policy: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int result[4]; - * - * thrust::copy_if(thrust::host, V, V + N, result, is_even()); - * - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-2, 0, 0, 2} - * \endcode - * - * \see \c remove_copy_if - */ -template - OutputIterator copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - - -/*! This version of \p copy_if copies elements from the range [first,last) - * to a range beginning at \ presult, except that any element which causes \p pred - * to be \p pred to be \c false is not copied. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p copy_if performs the assignment *result = *(first+n) and \p result - * is advanced one position if pred(*(first+n)). Otherwise, no assignment - * occurs and \p result is not advanced. - * - * \param first The beginning of the sequence from which to copy. - * \param last The end of the sequence from which to copy. - * \param result The beginning of the sequence into which to copy. - * \param pred The predicate to test on every value of the range [first, last). - * \return result + n, where \c n is equal to the number of times \p pred - * evaluated to \c true in the range [first, last). - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The ranges [first, last) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p copy_if to perform stream compaction - * to copy even numbers to an output range. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int result[4]; - * - * thrust::copy_if(V, V + N, result, is_even()); - * - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-2, 0, 0, 2} - * \endcode - * - * \see \c remove_copy_if - */ -template - OutputIterator copy_if(InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - -/*! This version of \p copy_if copies elements from the range [first,last) - * to a range beginning at \p result, except that any element whose corresponding stencil - * element causes \p pred to be \c false is not copied. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p copy_if performs the assignment *result = *(first+n) and \p result - * is advanced one position if pred(*(stencil+n)). Otherwise, no assignment - * occurs and \p result is not advanced. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence from which to copy. - * \param last The end of the sequence from which to copy. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the sequence into which to copy. - * \param pred The predicate to test on every value of the range [stencil, stencil + (last-first)). - * \return result + n, where \c n is equal to the number of times \p pred - * evaluated to \c true in the range [stencil, stencil + (last-first)). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The ranges [first, last) and [result, result + (last - first)) shall not overlap. - * \pre The ranges [stencil, stencil + (last - first)) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p copy_if to perform stream compaction - * to copy numbers to an output range when corresponding stencil elements are even using the \p thrust::host execution policy: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int N = 6; - * int data[N] = { 0, 1, 2, 3, 4, 5}; - * int stencil[N] = {-2, 0, -1, 0, 1, 2}; - * int result[4]; - * - * thrust::copy_if(thrust::host, data, data + N, stencil, result, is_even()); - * - * // data remains = { 0, 1, 2, 3, 4, 5}; - * // stencil remains = {-2, 0, -1, 0, 1, 2}; - * // result is now { 0, 1, 3, 5} - * \endcode - * - * \see \c remove_copy_if - */ -template - OutputIterator copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -/*! This version of \p copy_if copies elements from the range [first,last) - * to a range beginning at \p result, except that any element whose corresponding stencil - * element causes \p pred to be \c false is not copied. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p copy_if performs the assignment *result = *(first+n) and \p result - * is advanced one position if pred(*(stencil+n)). Otherwise, no assignment - * occurs and \p result is not advanced. - * - * \param first The beginning of the sequence from which to copy. - * \param last The end of the sequence from which to copy. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the sequence into which to copy. - * \param pred The predicate to test on every value of the range [stencil, stencil + (last-first)). - * \return result + n, where \c n is equal to the number of times \p pred - * evaluated to \c true in the range [stencil, stencil + (last-first)). - * - * \tparam InputIterator1 is a model of Input Iterator. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The ranges [first, last) and [result, result + (last - first)) shall not overlap. - * \pre The ranges [stencil, stencil + (last - first)) and [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p copy_if to perform stream compaction - * to copy numbers to an output range when corresponding stencil elements are even: - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int N = 6; - * int data[N] = { 0, 1, 2, 3, 4, 5}; - * int stencil[N] = {-2, 0, -1, 0, 1, 2}; - * int result[4]; - * - * thrust::copy_if(data, data + N, stencil, result, is_even()); - * - * // data remains = { 0, 1, 2, 3, 4, 5}; - * // stencil remains = {-2, 0, -1, 0, 1, 2}; - * // result is now { 0, 1, 3, 5} - * \endcode - * - * \see \c remove_copy_if - */ -template - OutputIterator copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - -/*! \} // end stream_compaction - */ - -} // end namespace thrust - -#include -#include - diff --git a/compat/thrust/count.h b/compat/thrust/count.h deleted file mode 100644 index cddd1dd..0000000 --- a/compat/thrust/count.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file count.h - * \brief Counting elements in a range - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - -/*! \addtogroup reductions - * \ingroup algorithms - * \{ - */ - -/*! \addtogroup counting - * \ingroup reductions - * \{ - */ - - -/*! \p count finds the number of elements in [first,last) that are equal - * to \p value. More precisely, \p count returns the number of iterators \c i in - * [first, last) such that *i == value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param value The value to be counted. - * \return The number of elements equal to \p value. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be a model of must be a model of Equality Comparable. - * \tparam EqualityComparable must be a model of Equality Comparable and can be compared for equality with \c InputIterator's \c value_type - * - * The following code snippet demonstrates how to use \p count to - * count the number of instances in a range of a value of interest using the \p thrust::device execution policy: - * - * \code - * #include - * #include - * #include - * ... - * // put 3 1s in a device_vector - * thrust::device_vector vec(5,0); - * vec[1] = 1; - * vec[3] = 1; - * vec[4] = 1; - * - * // count the 1s - * int result = thrust::count(thrust::device, vec.begin(), vec.end(), 1); - * // result == 3 - * \endcode - * - * \see http://www.sgi.com/tech/stl/count.html - */ -template - typename thrust::iterator_traits::difference_type - count(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, const EqualityComparable& value); - - - -/*! \p count finds the number of elements in [first,last) that are equal - * to \p value. More precisely, \p count returns the number of iterators \c i in - * [first, last) such that *i == value. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param value The value to be counted. - * \return The number of elements equal to \p value. - * - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be a model of must be a model of Equality Comparable. - * \tparam EqualityComparable must be a model of Equality Comparable and can be compared for equality with \c InputIterator's \c value_type - * - * The following code snippet demonstrates how to use \p count to - * count the number of instances in a range of a value of interest. - * \code - * #include - * #include - * ... - * // put 3 1s in a device_vector - * thrust::device_vector vec(5,0); - * vec[1] = 1; - * vec[3] = 1; - * vec[4] = 1; - * - * // count the 1s - * int result = thrust::count(vec.begin(), vec.end(), 1); - * // result == 3 - * \endcode - * - * \see http://www.sgi.com/tech/stl/count.html - */ -template - typename thrust::iterator_traits::difference_type - count(InputIterator first, InputIterator last, const EqualityComparable& value); - - -/*! \p count_if finds the number of elements in [first,last) for which - * a predicate is \c true. More precisely, \p count_if returns the number of iterators - * \c i in [first, last) such that pred(*i) == true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred The predicate. - * \return The number of elements where \p pred is \c true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c Predicate's \c argument_type. - * \tparam Predicate must be a model of Predicate. - * - * The following code snippet demonstrates how to use \p count to - * count the number of odd numbers in a range using the \p thrust::device execution policy: - * - * \code - * #include - * #include - * #include - * ... - * struct is_odd - * { - * __host__ __device__ - * bool operator()(int &x) - * { - * return x & 1; - * } - * }; - * ... - * // fill a device_vector with even & odd numbers - * thrust::device_vector vec(5); - * vec[0] = 0; - * vec[1] = 1; - * vec[2] = 2; - * vec[3] = 3; - * vec[4] = 4; - * - * // count the odd elements in vec - * int result = thrust::count_if(thrust::device, vec.begin(), vec.end(), is_odd()); - * // result == 2 - * \endcode - * - * \see http://www.sgi.com/tech/stl/count.html - */ -template - typename thrust::iterator_traits::difference_type - count_if(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred); - - -/*! \p count_if finds the number of elements in [first,last) for which - * a predicate is \c true. More precisely, \p count_if returns the number of iterators - * \c i in [first, last) such that pred(*i) == true. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred The predicate. - * \return The number of elements where \p pred is \c true. - * - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c Predicate's \c argument_type. - * \tparam Predicate must be a model of Predicate. - * - * The following code snippet demonstrates how to use \p count to - * count the number of odd numbers in a range. - * \code - * #include - * #include - * ... - * struct is_odd - * { - * __host__ __device__ - * bool operator()(int &x) - * { - * return x & 1; - * } - * }; - * ... - * // fill a device_vector with even & odd numbers - * thrust::device_vector vec(5); - * vec[0] = 0; - * vec[1] = 1; - * vec[2] = 2; - * vec[3] = 3; - * vec[4] = 4; - * - * // count the odd elements in vec - * int result = thrust::count_if(vec.begin(), vec.end(), is_odd()); - * // result == 2 - * \endcode - * - * \see http://www.sgi.com/tech/stl/count.html - */ -template - typename thrust::iterator_traits::difference_type - count_if(InputIterator first, InputIterator last, Predicate pred); - -/*! \} // end counting - * \} // end reductions - */ - -} // end thrust - -#include - diff --git a/compat/thrust/detail/adjacent_difference.inl b/compat/thrust/detail/adjacent_difference.inl deleted file mode 100644 index 6590f9d..0000000 --- a/compat/thrust/detail/adjacent_difference.inl +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file adjacent_difference.inl - * \brief Inline file for adjacent_difference.h - */ - -#include -#include -#include -#include - -namespace thrust -{ - - -template -OutputIterator adjacent_difference(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::adjacent_difference; - - return adjacent_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result); -} // end adjacent_difference() - - -template -OutputIterator adjacent_difference(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::adjacent_difference; - - return adjacent_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, binary_op); -} // end adjacent_difference() - - -template -OutputIterator adjacent_difference(InputIterator first, InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::adjacent_difference(select_system(system1, system2), first, last, result); -} // end adjacent_difference() - - -template -OutputIterator adjacent_difference(InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::adjacent_difference(select_system(system1, system2), first, last, result, binary_op); -} // end adjacent_difference() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/advance.inl b/compat/thrust/detail/advance.inl deleted file mode 100644 index 2907be7..0000000 --- a/compat/thrust/detail/advance.inl +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file advance.inl - * \brief Inline file for advance.h - */ - -#include -#include -#include - -namespace thrust -{ - - -template -void advance(InputIterator& i, Distance n) -{ - thrust::system::detail::generic::advance(i, n); -} // end advance() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/allocator/allocator_traits.h b/compat/thrust/detail/allocator/allocator_traits.h deleted file mode 100644 index 6ee99b4..0000000 --- a/compat/thrust/detail/allocator/allocator_traits.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace allocator_traits_detail -{ - -__THRUST_DEFINE_HAS_NESTED_TYPE(has_pointer, pointer) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_const_pointer, const_pointer) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_reference, reference) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_const_reference, const_reference) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_void_pointer, void_pointer) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_const_void_pointer, const_void_pointer) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_difference_type, difference_type) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_size_type, size_type) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_propagate_on_container_move_assignment, propagate_on_container_move_assignment) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_propagate_on_container_swap, propagate_on_container_swap) -__THRUST_DEFINE_HAS_NESTED_TYPE(has_system_type, system_type) - -template - struct nested_pointer -{ - typedef typename T::pointer type; -}; - -template - struct nested_const_pointer -{ - typedef typename T::const_pointer type; -}; - -template - struct nested_reference -{ - typedef typename T::reference type; -}; - -template - struct nested_const_reference -{ - typedef typename T::const_reference type; -}; - -template - struct nested_void_pointer -{ - typedef typename T::void_pointer type; -}; - -template - struct nested_const_void_pointer -{ - typedef typename T::const_void_pointer type; -}; - -template - struct nested_difference_type -{ - typedef typename T::difference_type type; -}; - -template - struct nested_size_type -{ - typedef typename T::size_type type; -}; - -template - struct nested_propagate_on_container_copy_assignment -{ - typedef typename T::propagate_on_container_copy_assignment type; -}; - -template - struct nested_propagate_on_container_move_assignment -{ - typedef typename T::propagate_on_container_move_assignment type; -}; - -template - struct nested_propagate_on_container_swap -{ - typedef typename T::propagate_on_container_swap type; -}; - -template - struct nested_system_type -{ - typedef typename T::system_type type; -}; - -} // end allocator_traits_detail - - -template - struct allocator_traits -{ - typedef Alloc allocator_type; - - typedef typename allocator_type::value_type value_type; - - typedef typename eval_if< - allocator_traits_detail::has_pointer::value, - allocator_traits_detail::nested_pointer, - identity_ - >::type pointer; - - private: - template - struct rebind_pointer - { - typedef typename pointer_traits::template rebind::other type; - }; - - public: - - typedef typename eval_if< - allocator_traits_detail::has_const_pointer::value, - allocator_traits_detail::nested_const_pointer, - rebind_pointer - >::type const_pointer; - - typedef typename eval_if< - allocator_traits_detail::has_void_pointer::value, - allocator_traits_detail::nested_void_pointer, - rebind_pointer - >::type void_pointer; - - typedef typename eval_if< - allocator_traits_detail::has_const_void_pointer::value, - allocator_traits_detail::nested_const_void_pointer, - rebind_pointer - >::type const_void_pointer; - - typedef typename eval_if< - allocator_traits_detail::has_difference_type::value, - allocator_traits_detail::nested_difference_type, - pointer_difference - >::type difference_type; - - typedef typename eval_if< - allocator_traits_detail::has_size_type::value, - allocator_traits_detail::nested_size_type, - make_unsigned - >::type size_type; - - typedef typename eval_if< - allocator_traits_detail::has_propagate_on_container_copy_assignment::value, - allocator_traits_detail::nested_propagate_on_container_copy_assignment, - identity_ - >::type propagate_on_container_copy_assignment; - - typedef typename eval_if< - allocator_traits_detail::has_propagate_on_container_move_assignment::value, - allocator_traits_detail::nested_propagate_on_container_move_assignment, - identity_ - >::type propagate_on_container_move_assignment; - - typedef typename eval_if< - allocator_traits_detail::has_propagate_on_container_swap::value, - allocator_traits_detail::nested_propagate_on_container_swap, - identity_ - >::type propagate_on_container_swap; - - typedef typename eval_if< - allocator_traits_detail::has_system_type::value, - allocator_traits_detail::nested_system_type, - thrust::iterator_system - >::type system_type; - - // XXX rebind and rebind_traits are alias templates - // and so are omitted while c++11 is unavailable - - inline static pointer allocate(allocator_type &a, size_type n); - - inline static pointer allocate(allocator_type &a, size_type n, const_void_pointer hint); - - inline static void deallocate(allocator_type &a, pointer p, size_type n); - - // XXX should probably change T* to pointer below and then relax later - - template - inline __host__ __device__ static void construct(allocator_type &a, T *p); - - template - inline __host__ __device__ static void construct(allocator_type &a, T *p, const Arg1 &arg1); - - template - inline __host__ __device__ static void destroy(allocator_type &a, T *p); - - inline static size_type max_size(const allocator_type &a); -}; // end allocator_traits - - -// XXX consider moving this non-standard functionality inside allocator_traits -template - struct allocator_system -{ - // the type of the allocator's system - typedef typename eval_if< - allocator_traits_detail::has_system_type::value, - allocator_traits_detail::nested_system_type, - thrust::iterator_system< - typename allocator_traits::pointer - > - >::type type; - - inline static type &get(Alloc &a); -}; - - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/allocator_traits.inl b/compat/thrust/detail/allocator/allocator_traits.inl deleted file mode 100644 index 8319335..0000000 --- a/compat/thrust/detail/allocator/allocator_traits.inl +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace allocator_traits_detail -{ - -__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_allocate_with_hint_impl, allocate) - -template - class has_member_allocate_with_hint -{ - typedef typename allocator_traits::pointer pointer; - typedef typename allocator_traits::size_type size_type; - typedef typename allocator_traits::const_void_pointer const_void_pointer; - - public: - typedef typename has_member_allocate_with_hint_impl::type type; - static const bool value = type::value; -}; - -template - typename enable_if< - has_member_allocate_with_hint::value, - typename allocator_traits::pointer - >::type - allocate(Alloc &a, typename allocator_traits::size_type n, typename allocator_traits::const_void_pointer hint) -{ - return a.allocate(n,hint); -} - -template - typename disable_if< - has_member_allocate_with_hint::value, - typename allocator_traits::pointer - >::type - allocate(Alloc &a, typename allocator_traits::size_type n, typename allocator_traits::const_void_pointer) -{ - return a.allocate(n); -} - - -__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_construct1_impl, construct) - -template - struct has_member_construct1 - : has_member_construct1_impl -{}; - -template - inline __host__ __device__ - typename enable_if< - has_member_construct1::value - >::type - construct(Alloc &a, T *p) -{ - a.construct(p); -} - -template - inline __host__ __device__ - typename disable_if< - has_member_construct1::value - >::type - construct(Alloc &a, T *p) -{ - ::new(static_cast(p)) T(); -} - - -__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_construct2_impl, construct) - -template - struct has_member_construct2 - : has_member_construct2_impl -{}; - -template - inline __host__ __device__ - typename enable_if< - has_member_construct2::value - >::type - construct(Alloc &a, T *p, const Arg1 &arg1) -{ - a.construct(p,arg1); -} - -template - inline __host__ __device__ - typename disable_if< - has_member_construct2::value - >::type - construct(Alloc &, T *p, const Arg1 &arg1) -{ - ::new(static_cast(p)) T(arg1); -} - - -__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_destroy_impl, destroy) - -template - struct has_member_destroy - : has_member_destroy_impl -{}; - -template - inline __host__ __device__ - typename enable_if< - has_member_destroy::value - >::type - destroy(Alloc &a, T *p) -{ - a.destroy(p); -} - -template - inline __host__ __device__ - typename disable_if< - has_member_destroy::value - >::type - destroy(Alloc &, T *p) -{ - p->~T(); -} - - -__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_max_size_impl, max_size) - -template - class has_member_max_size -{ - typedef typename allocator_traits::size_type size_type; - - public: - typedef typename has_member_max_size_impl::type type; - static const bool value = type::value; -}; - -template - typename enable_if< - has_member_max_size::value, - typename allocator_traits::size_type - >::type - max_size(const Alloc &a) -{ - return a.max_size(); -} - -template - typename disable_if< - has_member_max_size::value, - typename allocator_traits::size_type - >::type - max_size(const Alloc &a) -{ - typedef typename allocator_traits::size_type size_type; - return std::numeric_limits::max(); -} - -__THRUST_DEFINE_HAS_MEMBER_FUNCTION(has_member_system_impl, system) - -template - class has_member_system -{ - typedef typename allocator_system::type system_type; - - public: - typedef typename has_member_system_impl::type type; - static const bool value = type::value; -}; - -template - typename enable_if< - has_member_system::value, - typename allocator_system::type & - >::type - system(Alloc &a) -{ - return a.system(); -} - -template - typename disable_if< - has_member_system::value, - typename allocator_system::type & - >::type - system(Alloc &a) -{ - // assumes the system is default-constructible - static typename allocator_system::type state; - return state; -} - - -} // end allocator_traits_detail - - -template - typename allocator_traits::pointer - allocator_traits - ::allocate(Alloc &a, typename allocator_traits::size_type n) -{ - return a.allocate(n); -} - -template - typename allocator_traits::pointer - allocator_traits - ::allocate(Alloc &a, typename allocator_traits::size_type n, typename allocator_traits::const_void_pointer hint) -{ - return allocator_traits_detail::allocate(a, n, hint); -} - -template - void allocator_traits - ::deallocate(Alloc &a, typename allocator_traits::pointer p, typename allocator_traits::size_type n) -{ - return a.deallocate(p,n); -} - -template - template - void allocator_traits - ::construct(allocator_type &a, T *p) -{ - return allocator_traits_detail::construct(a,p); -} - -template - template - void allocator_traits - ::construct(allocator_type &a, T *p, const Arg1 &arg1) -{ - return allocator_traits_detail::construct(a,p,arg1); -} - -template - template - void allocator_traits - ::destroy(allocator_type &a, T *p) -{ - return allocator_traits_detail::destroy(a,p); -} - -template - typename allocator_traits::size_type - allocator_traits - ::max_size(const allocator_type &a) -{ - return allocator_traits_detail::max_size(a); -} - -template - typename allocator_system::type & - allocator_system - ::get(Alloc &a) -{ - return allocator_traits_detail::system(a); -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/copy_construct_range.h b/compat/thrust/detail/allocator/copy_construct_range.h deleted file mode 100644 index 5d99e1f..0000000 --- a/compat/thrust/detail/allocator/copy_construct_range.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace detail -{ - -template - Pointer copy_construct_range(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - InputIterator last, - Pointer result); - -template - Pointer copy_construct_range_n(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - Size n, - Pointer result); - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/copy_construct_range.inl b/compat/thrust/detail/allocator/copy_construct_range.inl deleted file mode 100644 index 7c5478b..0000000 --- a/compat/thrust/detail/allocator/copy_construct_range.inl +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace allocator_traits_detail -{ - - -template - struct copy_construct_with_allocator -{ - Allocator &a; - - copy_construct_with_allocator(Allocator &a) - : a(a) - {} - - template - inline __host__ __device__ - void operator()(Tuple t) - { - const InputType &in = thrust::get<0>(t); - OutputType &out = thrust::get<1>(t); - - allocator_traits::construct(a, &out, in); - } -}; - - -template - struct needs_copy_construct_via_allocator - : has_member_construct2< - Allocator, - T, - T - > -{}; - - -// we know that std::allocator::construct's only effect is to call T's -// copy constructor, so we needn't use it for copy construction -template - struct needs_copy_construct_via_allocator, T> - : thrust::detail::false_type -{}; - - -// XXX it's regrettable that this implementation is copied almost -// exactly from system::detail::generic::uninitialized_copy -// perhaps generic::uninitialized_copy could call this routine -// with a default allocator -template - typename enable_if_convertible< - FromSystem, - ToSystem, - Pointer - >::type - uninitialized_copy_with_allocator(Allocator &a, - thrust::execution_policy &from_system, - thrust::execution_policy &to_system, - InputIterator first, - InputIterator last, - Pointer result) -{ - // zip up the iterators - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first,result)); - ZipIterator end = begin; - - // get a zip_iterator pointing to the end - const typename thrust::iterator_difference::type n = thrust::distance(first,last); - thrust::advance(end,n); - - // create a functor - typedef typename iterator_traits::value_type InputType; - typedef typename iterator_traits::value_type OutputType; - - // do the for_each - // note we use to_system to dispatch the for_each - thrust::for_each(to_system, begin, end, copy_construct_with_allocator(a)); - - // return the end of the output range - return thrust::get<1>(end.get_iterator_tuple()); -} - - -// XXX it's regrettable that this implementation is copied almost -// exactly from system::detail::generic::uninitialized_copy_n -// perhaps generic::uninitialized_copy_n could call this routine -// with a default allocator -template - typename enable_if_convertible< - FromSystem, - ToSystem, - Pointer - >::type - uninitialized_copy_with_allocator_n(Allocator &a, - thrust::execution_policy &from_system, - thrust::execution_policy &to_system, - InputIterator first, - Size n, - Pointer result) -{ - // zip up the iterators - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first,result)); - - // create a functor - typedef typename iterator_traits::value_type InputType; - typedef typename iterator_traits::value_type OutputType; - - // do the for_each_n - // note we use to_system to dispatch the for_each_n - ZipIterator end = thrust::for_each_n(to_system, begin, n, copy_construct_with_allocator(a)); - - // return the end of the output range - return thrust::get<1>(end.get_iterator_tuple()); -} - - -template - typename disable_if_convertible< - FromSystem, - ToSystem, - Pointer - >::type - uninitialized_copy_with_allocator(Allocator &, - thrust::execution_policy &from_system, - thrust::execution_policy &to_system, - InputIterator first, - InputIterator last, - Pointer result) -{ - // the systems aren't trivially interoperable - // just call two_system_copy and hope for the best - return thrust::detail::two_system_copy(from_system, to_system, first, last, result); -} // end uninitialized_copy_with_allocator() - - -template - typename disable_if_convertible< - FromSystem, - ToSystem, - Pointer - >::type - uninitialized_copy_with_allocator_n(Allocator &, - thrust::execution_policy &from_system, - thrust::execution_policy &to_system, - InputIterator first, - Size n, - Pointer result) -{ - // the systems aren't trivially interoperable - // just call two_system_copy_n and hope for the best - return thrust::detail::two_system_copy_n(from_system, to_system, first, n, result); -} // end uninitialized_copy_with_allocator_n() - - -template - typename disable_if< - needs_copy_construct_via_allocator< - Allocator, - typename pointer_element::type - >::value, - Pointer - >::type - copy_construct_range(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - InputIterator last, - Pointer result) -{ - typename allocator_system::type &to_system = allocator_system::get(a); - - // just call two_system_copy - return thrust::detail::two_system_copy(from_system, to_system, first, last, result); -} - - -template - typename disable_if< - needs_copy_construct_via_allocator< - Allocator, - typename pointer_element::type - >::value, - Pointer - >::type - copy_construct_range_n(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - Size n, - Pointer result) -{ - typename allocator_system::type &to_system = allocator_system::get(a); - - // just call two_system_copy_n - return thrust::detail::two_system_copy_n(from_system, to_system, first, n, result); -} - - -template - typename enable_if< - needs_copy_construct_via_allocator< - Allocator, - typename pointer_element::type - >::value, - Pointer - >::type - copy_construct_range(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - InputIterator last, - Pointer result) -{ - typename allocator_system::type &to_system = allocator_system::get(a); - return uninitialized_copy_with_allocator(a, from_system, to_system, first, last, result); -} - - -template - typename enable_if< - needs_copy_construct_via_allocator< - Allocator, - typename pointer_element::type - >::value, - Pointer - >::type - copy_construct_range_n(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - Size n, - Pointer result) -{ - typename allocator_system::type &to_system = allocator_system::get(a); - return uninitialized_copy_with_allocator_n(a, from_system, to_system, first, n, result); -} - - -} // end allocator_traits_detail - - -template - Pointer copy_construct_range(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - InputIterator last, - Pointer result) -{ - return allocator_traits_detail::copy_construct_range(from_system, a, first, last, result); -} - - -template - Pointer copy_construct_range_n(thrust::execution_policy &from_system, - Allocator &a, - InputIterator first, - Size n, - Pointer result) -{ - return allocator_traits_detail::copy_construct_range_n(from_system, a, first, n, result); -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/default_construct_range.h b/compat/thrust/detail/allocator/default_construct_range.h deleted file mode 100644 index d83cb31..0000000 --- a/compat/thrust/detail/allocator/default_construct_range.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - - -template -inline void default_construct_range(Allocator &a, Pointer p, Size n); - - -} // end detail -} // end thrust - -#include - - diff --git a/compat/thrust/detail/allocator/default_construct_range.inl b/compat/thrust/detail/allocator/default_construct_range.inl deleted file mode 100644 index 45fe9c6..0000000 --- a/compat/thrust/detail/allocator/default_construct_range.inl +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace allocator_traits_detail -{ - - -template - struct construct1_via_allocator -{ - Allocator &a; - - construct1_via_allocator(Allocator &a) - : a(a) - {} - - template - inline __host__ __device__ - void operator()(T &x) - { - allocator_traits::construct(a, &x); - } -}; - - -template - struct needs_default_construct_via_allocator - : has_member_construct1< - Allocator, - T - > -{}; - - -// we know that std::allocator::construct's only effect is to call T's -// default constructor, so we needn't use it for default construction -template - struct needs_default_construct_via_allocator, T> - : thrust::detail::false_type -{}; - - -template - typename enable_if< - needs_default_construct_via_allocator< - Allocator, - typename pointer_element::type - >::value - >::type - default_construct_range(Allocator &a, Pointer p, Size n) -{ - thrust::for_each_n(allocator_system::get(a), p, n, construct1_via_allocator(a)); -} - - -template - typename disable_if< - needs_default_construct_via_allocator< - Allocator, - typename pointer_element::type - >::value - >::type - default_construct_range(Allocator &a, Pointer p, Size n) -{ - thrust::uninitialized_fill_n(allocator_system::get(a), p, n, typename pointer_element::type()); -} - - -} // end allocator_traits_detail - - -template - void default_construct_range(Allocator &a, Pointer p, Size n) -{ - return allocator_traits_detail::default_construct_range(a,p,n); -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/destroy_range.h b/compat/thrust/detail/allocator/destroy_range.h deleted file mode 100644 index d690a60..0000000 --- a/compat/thrust/detail/allocator/destroy_range.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - -template - inline void destroy_range(Allocator &a, Pointer p, Size n); - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/destroy_range.inl b/compat/thrust/detail/allocator/destroy_range.inl deleted file mode 100644 index ace2223..0000000 --- a/compat/thrust/detail/allocator/destroy_range.inl +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace allocator_traits_detail -{ - - -// destroy_range has three cases: -// if Allocator has an effectful member function destroy: -// 1. destroy via the allocator -// else -// 2. if T has a non-trivial destructor, destroy the range without using the allocator -// 3. if T has a trivial destructor, do a no-op - -template - struct has_effectful_member_destroy - : has_member_destroy -{}; - -// std::allocator::destroy's only effect is to invoke its argument's destructor -template - struct has_effectful_member_destroy, T> - : thrust::detail::false_type -{}; - -// case 1: Allocator has an effectful 1-argument member function "destroy" -template - struct enable_if_destroy_range_case1 - : thrust::detail::enable_if< - has_effectful_member_destroy< - Allocator, - typename pointer_element::type - >::value - > -{}; - -// case 2: Allocator has no member function "destroy", but T has a non-trivial destructor -template - struct enable_if_destroy_range_case2 - : thrust::detail::enable_if< - !has_effectful_member_destroy< - Allocator, - typename pointer_element::type - >::value && - !has_trivial_destructor< - typename pointer_element::type - >::value - > -{}; - -// case 3: Allocator has no member function "destroy", and T has a trivial destructor -template - struct enable_if_destroy_range_case3 - : thrust::detail::enable_if< - !has_effectful_member_destroy< - Allocator, - typename pointer_element::type - >::value && - has_trivial_destructor< - typename pointer_element::type - >::value - > -{}; - - - -template - struct destroy_via_allocator -{ - Allocator &a; - - destroy_via_allocator(Allocator &a) - : a(a) - {} - - template - inline __host__ __device__ - void operator()(T &x) - { - allocator_traits::destroy(a, &x); - } -}; - - -// destroy_range case 1: destroy via allocator -template - typename enable_if_destroy_range_case1::type - destroy_range(Allocator &a, Pointer p, Size n) -{ - thrust::for_each_n(allocator_system::get(a), p, n, destroy_via_allocator(a)); -} - - -// we must prepare for His coming -struct gozer -{ - template - inline __host__ __device__ - void operator()(T &x) - { - x.~T(); - } -}; - -// destroy_range case 2: destroy without the allocator -template - typename enable_if_destroy_range_case2::type - destroy_range(Allocator &a, Pointer p, Size n) -{ - thrust::for_each_n(allocator_system::get(a), p, n, gozer()); -} - - -// destroy_range case 3: no-op -template - typename enable_if_destroy_range_case3::type - destroy_range(Allocator &, Pointer, Size) -{ - // no op -} - - -} // end allocator_traits_detail - - -template - void destroy_range(Allocator &a, Pointer p, Size n) -{ - return allocator_traits_detail::destroy_range(a,p,n); -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/fill_construct_range.h b/compat/thrust/detail/allocator/fill_construct_range.h deleted file mode 100644 index 66fec41..0000000 --- a/compat/thrust/detail/allocator/fill_construct_range.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - - -template -inline void fill_construct_range(Allocator &a, Pointer p, Size n, const T &value); - - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/fill_construct_range.inl b/compat/thrust/detail/allocator/fill_construct_range.inl deleted file mode 100644 index e2c9c09..0000000 --- a/compat/thrust/detail/allocator/fill_construct_range.inl +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace allocator_traits_detail -{ - -// fill_construct_range has 2 cases: -// if Allocator has an effectful member function construct: -// 1. construct via the allocator -// else -// 2. construct via uninitialized_fill - -template - struct has_effectful_member_construct2 - : has_member_construct2 -{}; - -// std::allocator::construct's only effect is to invoke placement new -template - struct has_effectful_member_construct2,T,Arg1> - : thrust::detail::false_type -{}; - - -template - struct construct2_via_allocator -{ - Allocator &a; - Arg1 arg; - - construct2_via_allocator(Allocator &a, const Arg1 &arg) - : a(a), arg(arg) - {} - - template - inline __host__ __device__ - void operator()(T &x) - { - allocator_traits::construct(a, &x, arg); - } -}; - - -template - typename enable_if< - has_effectful_member_construct2< - Allocator, - typename pointer_element::type, - T - >::value - >::type - fill_construct_range(Allocator &a, Pointer p, Size n, const T &value) -{ - thrust::for_each_n(allocator_system::get(a), p, n, construct2_via_allocator(a, value)); -} - - -template - typename disable_if< - has_effectful_member_construct2< - Allocator, - typename pointer_element::type, - T - >::value - >::type - fill_construct_range(Allocator &a, Pointer p, Size n, const T &value) -{ - thrust::uninitialized_fill_n(allocator_system::get(a), p, n, value); -} - - -} // end allocator_traits_detail - - -template - void fill_construct_range(Alloc &a, Pointer p, Size n, const T &value) -{ - return allocator_traits_detail::fill_construct_range(a,p,n,value); -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/malloc_allocator.h b/compat/thrust/detail/allocator/malloc_allocator.h deleted file mode 100644 index cf4567e..0000000 --- a/compat/thrust/detail/allocator/malloc_allocator.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template - class malloc_allocator - : public thrust::detail::tagged_allocator< - T, System, Pointer - > -{ - private: - typedef thrust::detail::tagged_allocator< - T, System, Pointer - > super_t; - - public: - typedef typename super_t::pointer pointer; - typedef typename super_t::size_type size_type; - - pointer allocate(size_type cnt); - - void deallocate(pointer p, size_type n); -}; - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/malloc_allocator.inl b/compat/thrust/detail/allocator/malloc_allocator.inl deleted file mode 100644 index dd70202..0000000 --- a/compat/thrust/detail/allocator/malloc_allocator.inl +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - typename malloc_allocator::pointer - malloc_allocator - ::allocate(typename malloc_allocator::size_type cnt) -{ - using thrust::system::detail::generic::select_system; - - // XXX should use a hypothetical thrust::static_pointer_cast here - System system; - - pointer result = thrust::malloc(select_system(system), cnt); - - if(result.get() == 0) - { - throw thrust::system::detail::bad_alloc("malloc_allocator::allocate: malloc failed"); - } // end if - - return result; -} // end malloc_allocator::allocate() - - -template - void malloc_allocator - ::deallocate(typename malloc_allocator::pointer p, typename malloc_allocator::size_type n) -{ - using thrust::system::detail::generic::select_system; - - System system; - thrust::free(select_system(system), p); -} // end malloc_allocator - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/no_throw_allocator.h b/compat/thrust/detail/allocator/no_throw_allocator.h deleted file mode 100644 index ce397db..0000000 --- a/compat/thrust/detail/allocator/no_throw_allocator.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - -template - struct no_throw_allocator : BaseAllocator -{ - private: - typedef BaseAllocator super_t; - - public: - inline no_throw_allocator(const BaseAllocator &other = BaseAllocator()) - : super_t(other) - {} - - template - struct rebind - { - typedef no_throw_allocator::other> other; - }; // end rebind - - void deallocate(typename super_t::pointer p, typename super_t::size_type n) - { - try - { - super_t::deallocate(p, n); - } // end try - catch(...) - { - // catch anything - } // end catch - } // end deallocate() - - inline bool operator==(no_throw_allocator const &other) { return super_t::operator==(other); } - inline bool operator!=(no_throw_allocator const &other) { return super_t::operator!=(other); } -}; // end no_throw_allocator - -} // end detail -} // end thrust - - diff --git a/compat/thrust/detail/allocator/tagged_allocator.h b/compat/thrust/detail/allocator/tagged_allocator.h deleted file mode 100644 index 3cb87a3..0000000 --- a/compat/thrust/detail/allocator/tagged_allocator.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template class tagged_allocator; - -template - class tagged_allocator -{ - public: - typedef void value_type; - typedef typename thrust::detail::pointer_traits::template rebind::other pointer; - typedef typename thrust::detail::pointer_traits::template rebind::other const_pointer; - typedef std::size_t size_type; - typedef typename thrust::detail::pointer_traits::difference_type difference_type; - typedef Tag system_type; - - template - struct rebind - { - typedef tagged_allocator other; - }; // end rebind -}; - -template - class tagged_allocator -{ - public: - typedef T value_type; - typedef typename thrust::detail::pointer_traits::template rebind::other pointer; - typedef typename thrust::detail::pointer_traits::template rebind::other const_pointer; - typedef typename thrust::iterator_reference::type reference; - typedef typename thrust::iterator_reference::type const_reference; - typedef std::size_t size_type; - typedef typename thrust::detail::pointer_traits::difference_type difference_type; - typedef Tag system_type; - - template - struct rebind - { - typedef tagged_allocator other; - }; // end rebind - - __host__ __device__ - inline tagged_allocator(); - - __host__ __device__ - inline tagged_allocator(const tagged_allocator &); - - template - __host__ __device__ - inline tagged_allocator(const tagged_allocator &); - - __host__ __device__ - inline ~tagged_allocator(); - - __host__ __device__ - pointer address(reference x) const; - - __host__ __device__ - const_pointer address(const_reference x) const; - - size_type max_size() const; -}; - -template -__host__ __device__ -bool operator==(const tagged_allocator &, const tagged_allocator &); - -template -__host__ __device__ -bool operator!=(const tagged_allocator &, const tagged_allocator &); - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/tagged_allocator.inl b/compat/thrust/detail/allocator/tagged_allocator.inl deleted file mode 100644 index cb362a8..0000000 --- a/compat/thrust/detail/allocator/tagged_allocator.inl +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - tagged_allocator - ::tagged_allocator() -{} - - -template - tagged_allocator - ::tagged_allocator(const tagged_allocator &) -{} - - -template - template - tagged_allocator - ::tagged_allocator(const tagged_allocator &) -{} - - -template - tagged_allocator - ::~tagged_allocator() -{} - - -template - typename tagged_allocator::pointer - tagged_allocator - ::address(reference x) const -{ - return &x; -} - - -template - typename tagged_allocator::const_pointer - tagged_allocator - ::address(const_reference x) const -{ - return &x; -} - - -template - typename tagged_allocator::size_type - tagged_allocator - ::max_size() const -{ - return (std::numeric_limits::max)() / sizeof(T); -} - - -template -__host__ __device__ -bool operator==(const tagged_allocator &, const tagged_allocator &) -{ - return true; -} - - -template -__host__ __device__ -bool operator!=(const tagged_allocator &, const tagged_allocator &) -{ - return false; -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/allocator/temporary_allocator.h b/compat/thrust/detail/allocator/temporary_allocator.h deleted file mode 100644 index f0496f9..0000000 --- a/compat/thrust/detail/allocator/temporary_allocator.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -// XXX the pointer parameter given to tagged_allocator should be related to -// the type of the expression get_temporary_buffer(system, n).first -// without decltype, compromise on pointer -template - class temporary_allocator - : public thrust::detail::tagged_allocator< - T, System, thrust::pointer - > -{ - private: - typedef thrust::detail::tagged_allocator< - T, System, thrust::pointer - > super_t; - - System &m_system; - - public: - typedef typename super_t::pointer pointer; - typedef typename super_t::size_type size_type; - - inline explicit temporary_allocator(thrust::execution_policy &system) : - super_t(), - m_system(thrust::detail::derived_cast(system)) - {} - - pointer allocate(size_type cnt); - - void deallocate(pointer p, size_type n); - - inline System &system() - { - return m_system; - } // end system() - - private: - typedef thrust::pair pointer_and_size; -}; // end temporary_allocator - - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/allocator/temporary_allocator.inl b/compat/thrust/detail/allocator/temporary_allocator.inl deleted file mode 100644 index 63221d5..0000000 --- a/compat/thrust/detail/allocator/temporary_allocator.inl +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - typename temporary_allocator::pointer - temporary_allocator - ::allocate(typename temporary_allocator::size_type cnt) -{ - pointer_and_size result = thrust::get_temporary_buffer(system(), cnt); - - // handle failure - if(result.second < cnt) - { - // deallocate and throw - // note that we pass cnt to deallocate, not a value derived from result.second - deallocate(result.first, cnt); - - throw thrust::system::detail::bad_alloc("temporary_buffer::allocate: get_temporary_buffer failed"); - } // end if - - return result.first; -} // end temporary_allocator::allocate() - - -template - void temporary_allocator - ::deallocate(typename temporary_allocator::pointer p, typename temporary_allocator::size_type n) -{ - return thrust::return_temporary_buffer(system(), p); -} // end temporary_allocator - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/binary_search.inl b/compat/thrust/detail/binary_search.inl deleted file mode 100644 index 0fd799a..0000000 --- a/compat/thrust/detail/binary_search.inl +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file binary_search.inl - * \brief Inline file for binary_search.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -ForwardIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value) -{ - using thrust::system::detail::generic::lower_bound; - return lower_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} - - -template -ForwardIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::lower_bound; - return lower_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp); -} - - -template -ForwardIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value) -{ - using thrust::system::detail::generic::upper_bound; - return upper_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} - - -template -ForwardIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::upper_bound; - return upper_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp); -} - - -template -bool binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value) -{ - using thrust::system::detail::generic::binary_search; - return binary_search(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} - - -template -bool binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::binary_search; - return binary_search(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp); -} - - -template -thrust::pair -equal_range(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::equal_range; - return equal_range(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp); -} - - -template -thrust::pair -equal_range(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value) -{ - using thrust::system::detail::generic::equal_range; - return equal_range(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} - - -template -OutputIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output) -{ - using thrust::system::detail::generic::lower_bound; - return lower_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output); -} - - -template -OutputIterator lower_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::lower_bound; - return lower_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output, comp); -} - - -template -OutputIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output) -{ - using thrust::system::detail::generic::upper_bound; - return upper_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output); -} - - -template -OutputIterator upper_bound(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::upper_bound; - return upper_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output, comp); -} - - -template -OutputIterator binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output) -{ - using thrust::system::detail::generic::binary_search; - return binary_search(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output); -} - - -template -OutputIterator binary_search(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::binary_search; - return binary_search(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output, comp); -} - - -////////////////////// -// Scalar Functions // -////////////////////// - -template -ForwardIterator lower_bound(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::lower_bound(select_system(system), first, last, value); -} - -template -ForwardIterator lower_bound(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::lower_bound(select_system(system), first, last, value, comp); -} - -template -ForwardIterator upper_bound(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::upper_bound(select_system(system), first, last, value); -} - -template -ForwardIterator upper_bound(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::upper_bound(select_system(system), first, last, value, comp); -} - -template -bool binary_search(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::binary_search(select_system(system), first, last, value); -} - -template -bool binary_search(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::binary_search(select_system(system), first, last, value, comp); -} - -template -thrust::pair -equal_range(ForwardIterator first, - ForwardIterator last, - const LessThanComparable& value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::equal_range(select_system(system), first, last, value); -} - -template -thrust::pair -equal_range(ForwardIterator first, - ForwardIterator last, - const T& value, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::equal_range(select_system(system), first, last, value, comp); -} - -////////////////////// -// Vector Functions // -////////////////////// - -template -OutputIterator lower_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::lower_bound(select_system(system1,system2,system3), first, last, values_first, values_last, output); -} - -template -OutputIterator lower_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::lower_bound(select_system(system1,system2,system3), first, last, values_first, values_last, output, comp); -} - -template -OutputIterator upper_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::upper_bound(select_system(system1,system2,system3), first, last, values_first, values_last, output); -} - -template -OutputIterator upper_bound(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::upper_bound(select_system(system1,system2,system3), first, last, values_first, values_last, output, comp); -} - -template -OutputIterator binary_search(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::binary_search(select_system(system1,system2,system3), first, last, values_first, values_last, output); -} - -template -OutputIterator binary_search(ForwardIterator first, - ForwardIterator last, - InputIterator values_first, - InputIterator values_last, - OutputIterator output, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::binary_search(select_system(system1,system2,system3), first, last, values_first, values_last, output, comp); -} - -} // end namespace thrust - diff --git a/compat/thrust/detail/config.h b/compat/thrust/detail/config.h deleted file mode 100644 index d6b6691..0000000 --- a/compat/thrust/detail/config.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*! \file config.h - * \brief Defines platform configuration. - */ - -#pragma once - -#include - diff --git a/compat/thrust/detail/config/compiler.h b/compat/thrust/detail/config/compiler.h deleted file mode 100644 index 90ce911..0000000 --- a/compat/thrust/detail/config/compiler.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file compiler.h - * \brief Compiler-specific configuration - */ - -#pragma once - -#ifdef __CUDACC__ - -#include - -// Thrust supports CUDA >= 3.0 -#if CUDA_VERSION < 3000 -#error "CUDA v3.0 or newer is required" -#endif // CUDA_VERSION - -#endif // __CUDACC__ - -// enumerate host compilers we know about -#define THRUST_HOST_COMPILER_UNKNOWN 0 -#define THRUST_HOST_COMPILER_MSVC 1 -#define THRUST_HOST_COMPILER_GCC 2 - -// enumerate host compilers we know about -#define THRUST_DEVICE_COMPILER_UNKNOWN 0 -#define THRUST_DEVICE_COMPILER_MSVC 1 -#define THRUST_DEVICE_COMPILER_GCC 2 -#define THRUST_DEVICE_COMPILER_NVCC 3 - -// figure out which host compiler we're using -// XXX we should move the definition of THRUST_DEPRECATED out of this logic -#if defined(_MSC_VER) -#define THRUST_HOST_COMPILER THRUST_HOST_COMPILER_MSVC -#define THRUST_DEPRECATED __declspec(deprecated) -#elif defined(__GNUC__) -#define THRUST_HOST_COMPILER THRUST_HOST_COMPILER_GCC -#define THRUST_DEPRECATED __attribute__ ((deprecated)) -#define THRUST_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#else -#define THRUST_HOST_COMPILER THRUST_HOST_COMPILER_UNKNOWN -#define THRUST_DEPRECATED -#endif // THRUST_HOST_COMPILER - -// figure out which device compiler we're using -#if defined(__CUDACC__) -#define THRUST_DEVICE_COMPILER THRUST_DEVICE_COMPILER_NVCC -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC -#define THRUST_DEVICE_COMPILER THRUST_DEVICE_COMPILER_MSVC -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC -#define THRUST_DEVICE_COMPILER THRUST_DEVICE_COMPILER_GCC -#else -#define THRUST_DEVICE_COMPILER THRUST_DEVICE_COMPILER_UNKNOWN -#endif - -// is the device compiler capable of compiling omp? -#ifdef _OPENMP -#define THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE THRUST_TRUE -#else -#define THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE THRUST_FALSE -#endif // _OPENMP - -// disable specific MSVC warnings -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && !defined(__CUDA_ARCH__) -#define __THRUST_DISABLE_MSVC_WARNING_BEGIN(x) \ -__pragma(warning(push)) \ -__pragma(warning(disable : x)) -#define __THRUST_DISABLE_MSVC_WARNING_END(x) \ -__pragma(warning(pop)) -#else -#define __THRUST_DISABLE_MSVC_WARNING_BEGIN(x) -#define __THRUST_DISABLE_MSVC_WARNING_END(x) -#endif -#define __THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING(x) \ -__THRUST_DISABLE_MSVC_WARNING_BEGIN(4244 4267) \ -x;\ -__THRUST_DISABLE_MSVC_WARNING_END(4244 4267) -#define __THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN \ -__THRUST_DISABLE_MSVC_WARNING_BEGIN(4244 4267) -#define __THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END \ -__THRUST_DISABLE_MSVC_WARNING_END(4244 4267) -#define __THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL(x) \ -__THRUST_DISABLE_MSVC_WARNING_BEGIN(4800) \ -x;\ -__THRUST_DISABLE_MSVC_WARNING_END(4800) -#define __THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL_BEGIN \ -__THRUST_DISABLE_MSVC_WARNING_BEGIN(4800) -#define __THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL_END \ -__THRUST_DISABLE_MSVC_WARNING_END(4800) diff --git a/compat/thrust/detail/config/compiler_fence.h b/compat/thrust/detail/config/compiler_fence.h deleted file mode 100644 index f5cbf98..0000000 --- a/compat/thrust/detail/config/compiler_fence.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// msvc case -#if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC - -#ifndef _DEBUG - -#include -#pragma intrinsic(_ReadWriteBarrier) -#define __thrust_compiler_fence() _ReadWriteBarrier() -#else - -#define __thrust_compiler_fence() do {} while (0) - -#endif // _DEBUG - -// gcc case -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC - -#if THRUST_GCC_VERSION >= 40200 // atomic built-ins were introduced ~4.2 -#define __thrust_compiler_fence() __sync_synchronize() -#else -// allow the code to compile without any guarantees -#define __thrust_compiler_fence() do {} while (0) -#endif // THRUST_GCC_VERSION - -// unknown case -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_UNKNOWN - -// allow the code to compile without any guarantees -#define __thrust_compiler_fence() do {} while (0) - -#endif - diff --git a/compat/thrust/detail/config/config.h b/compat/thrust/detail/config/config.h deleted file mode 100644 index f3498ac..0000000 --- a/compat/thrust/detail/config/config.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file config.h - * \brief Defines platform configuration. - */ - -#pragma once - -// XXX the order of these #includes matters - -#include -#include -// host_system.h & device_system.h must be #included as early as possible -// because other config headers depend on it -#include -#include -#include -#include -#include -#include -#include - diff --git a/compat/thrust/detail/config/debug.h b/compat/thrust/detail/config/debug.h deleted file mode 100644 index 56c1bad..0000000 --- a/compat/thrust/detail/config/debug.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#ifndef THRUST_DEBUG -# ifndef NDEBUG -# if (DEBUG || _DEBUG) -# define THRUST_DEBUG 1 -# endif // (DEBUG || _DEBUG) -# endif // NDEBUG -#endif // THRUST_DEBUG - -#if THRUST_DEBUG -# ifndef __THRUST_SYNCHRONOUS -# define __THRUST_SYNCHRONOUS 1 -# endif // __THRUST_SYNCHRONOUS -#endif // THRUST_DEBUG - diff --git a/compat/thrust/detail/config/device_system.h b/compat/thrust/detail/config/device_system.h deleted file mode 100644 index a104906..0000000 --- a/compat/thrust/detail/config/device_system.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -// reserve 0 for undefined -#define THRUST_DEVICE_SYSTEM_CUDA 1 -#define THRUST_DEVICE_SYSTEM_OMP 2 -#define THRUST_DEVICE_SYSTEM_TBB 3 -#define THRUST_DEVICE_SYSTEM_CPP 4 - -#ifndef THRUST_DEVICE_SYSTEM -#define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_CUDA -#endif // THRUST_DEVICE_SYSTEM - -// XXX make the use of THRUST_DEVICE_BACKEND an error in Thrust 1.7 -// XXX eliminate the following in Thrust 1.7 - -#define THRUST_DEVICE_BACKEND_CUDA THRUST_DEVICE_SYSTEM_CUDA -#define THRUST_DEVICE_BACKEND_OMP THRUST_DEVICE_SYSTEM_OMP -#define THRUST_DEVICE_BACKEND_TBB THRUST_DEVICE_SYSTEM_TBB - -#ifdef THRUST_DEVICE_BACKEND -# if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC -# pragma message("----------------------------------------------------------------------------------") -# pragma message("| WARNING: THRUST_DEVICE_BACKEND is deprecated; use THRUST_DEVICE_SYSTEM instead |") -# pragma message("----------------------------------------------------------------------------------") -# else -# warning ---------------------------------------------------------------------------------- -# warning | WARNING: THRUST_DEVICE_BACKEND is deprecated; use THRUST_DEVICE_SYSTEM instead | -# warning ---------------------------------------------------------------------------------- -# endif // THRUST_HOST_COMPILER -# undef THRUST_DEVICE_SYSTEM -# define THRUST_DEVICE_SYSTEM THRUST_DEVICE_BACKEND -#endif // THRUST_DEVICE_BACKEND - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA -#define __THRUST_DEVICE_SYSTEM_NAMESPACE cuda -#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_OMP -#define __THRUST_DEVICE_SYSTEM_NAMESPACE omp -#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_TBB -#define __THRUST_DEVICE_SYSTEM_NAMESPACE tbb -#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CPP -#define __THRUST_DEVICE_SYSTEM_NAMESPACE cpp -#endif - -#define __THRUST_DEVICE_SYSTEM_ROOT thrust/system/__THRUST_DEVICE_SYSTEM_NAMESPACE - diff --git a/compat/thrust/detail/config/forceinline.h b/compat/thrust/detail/config/forceinline.h deleted file mode 100644 index 620769b..0000000 --- a/compat/thrust/detail/config/forceinline.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file forceinline.h - * \brief Defines __thrust_forceinline__ - */ - -#pragma once - -#include - -#if defined(__CUDACC__) - -#define __thrust_forceinline__ __forceinline__ - -#else - -// TODO add - -#define __thrust_forceinline__ - -#endif - diff --git a/compat/thrust/detail/config/hd_warning_disable.h b/compat/thrust/detail/config/hd_warning_disable.h deleted file mode 100644 index b993ef2..0000000 --- a/compat/thrust/detail/config/hd_warning_disable.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file hd_warning_disable.h - * \brief Defines __thrust_hd_warning_disable__ - */ - -#pragma once - -#include - -#if defined(__CUDACC__) - -#define __thrust_hd_warning_disable__ \ -#pragma hd_warning_disable -#else - -#define __thrust_hd_warning_disable__ - -#endif - - diff --git a/compat/thrust/detail/config/host_device.h b/compat/thrust/detail/config/host_device.h deleted file mode 100644 index 5d0975d..0000000 --- a/compat/thrust/detail/config/host_device.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file host_device.h - * \brief Defines __host__ and __device__ and other CUDA-isms - */ - -#pragma once - -#include - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - -#include - -#else - -// since __host__ & __device__ might have already be defined, only -// #define them if not defined already -// XXX this will break if the client does #include later - -#ifndef __host__ -#define __host__ -#endif // __host__ - -#ifndef __device__ -#define __device__ -#endif // __device__ - -#endif - diff --git a/compat/thrust/detail/config/host_system.h b/compat/thrust/detail/config/host_system.h deleted file mode 100644 index fb8edab..0000000 --- a/compat/thrust/detail/config/host_system.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -// reserve 0 for undefined -#define THRUST_HOST_SYSTEM_CPP 1 -#define THRUST_HOST_SYSTEM_OMP 2 -#define THRUST_HOST_SYSTEM_TBB 3 - -#ifndef THRUST_HOST_SYSTEM -#define THRUST_HOST_SYSTEM THRUST_HOST_SYSTEM_CPP -#endif // THRUST_HOST_SYSTEM - -// XXX make the use of THRUST_HOST_BACKEND an error in Thrust 1.7 -// XXX eliminate the following in Thrust 1.7 - -#define THRUST_HOST_BACKEND_CPP THRUST_HOST_SYSTEM_CPP -#define THRUST_HOST_BACKEND_OMP THRUST_HOST_SYSTEM_OMP -#define THRUST_HOST_BACKEND_TBB THRUST_HOST_SYSTEM_TBB - -#ifdef THRUST_HOST_BACKEND -# if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC -# pragma message("------------------------------------------------------------------------------") -# pragma message("| WARNING: THRUST_HOST_BACKEND is deprecated; use THRUST_HOST_SYSTEM instead |") -# pragma message("------------------------------------------------------------------------------") -# else -# warning ------------------------------------------------------------------------------ -# warning | WARNING: THRUST_HOST_BACKEND is deprecated; use THRUST_HOST_SYSTEM instead | -# warning ------------------------------------------------------------------------------ -# endif // THRUST_HOST_COMPILER -# undef THRUST_HOST_SYSTEM -# define THRUST_HOST_SYSTEM THRUST_HOST_BACKEND -#endif // THRUST_HOST_BACKEND - -#if THRUST_HOST_SYSTEM == THRUST_HOST_SYSTEM_CPP -#define __THRUST_HOST_SYSTEM_NAMESPACE cpp -#elif THRUST_HOST_SYSTEM == THRUST_HOST_SYSTEM_OMP -#define __THRUST_HOST_SYSTEM_NAMESPACE omp -#elif THRUST_HOST_SYSTEM == THRUST_HOST_SYSTEM_TBB -#define __THRUST_HOST_SYSTEM_NAMESPACE tbb -#endif - -#define __THRUST_HOST_SYSTEM_ROOT thrust/system/__THRUST_HOST_SYSTEM_NAMESPACE - diff --git a/compat/thrust/detail/config/simple_defines.h b/compat/thrust/detail/config/simple_defines.h deleted file mode 100644 index f9510ee..0000000 --- a/compat/thrust/detail/config/simple_defines.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file simple_defines.h - * \brief Primitive macros without dependencies. - */ - -#pragma once - -#define THRUST_UNKNOWN 0 -#define THRUST_FALSE 0 -#define THRUST_TRUE 1 - -#define THRUST_PREVENT_MACRO_SUBSTITUTION - diff --git a/compat/thrust/detail/contiguous_storage.h b/compat/thrust/detail/contiguous_storage.h deleted file mode 100644 index fe72bce..0000000 --- a/compat/thrust/detail/contiguous_storage.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -// XXX parameter T is redundant with parameter Alloc -template - class contiguous_storage -{ - private: - typedef thrust::detail::allocator_traits alloc_traits; - - public: - typedef Alloc allocator_type; - typedef T value_type; - typedef typename alloc_traits::pointer pointer; - typedef typename alloc_traits::const_pointer const_pointer; - typedef typename alloc_traits::size_type size_type; - typedef typename alloc_traits::difference_type difference_type; - - // XXX we should bring reference & const_reference into allocator_traits - // at the moment, it's unclear how -- we have nothing analogous to - // rebind_pointer for references - // we either need to add reference_traits or extend the existing - // pointer_traits to support wrapped references - typedef typename Alloc::reference reference; - typedef typename Alloc::const_reference const_reference; - - typedef thrust::detail::normal_iterator iterator; - typedef thrust::detail::normal_iterator const_iterator; - - explicit contiguous_storage(const allocator_type &alloc = allocator_type()); - - explicit contiguous_storage(size_type n, const allocator_type &alloc = allocator_type()); - - ~contiguous_storage(void); - - size_type size(void) const; - - size_type max_size(void) const; - - iterator begin(void); - - const_iterator begin(void) const; - - iterator end(void); - - const_iterator end(void) const; - - reference operator[](size_type n); - - const_reference operator[](size_type n) const; - - allocator_type get_allocator(void) const; - - // note that allocate does *not* automatically call deallocate - void allocate(size_type n); - - void deallocate(void); - - void swap(contiguous_storage &x); - - void default_construct_n(iterator first, size_type n); - - void uninitialized_fill_n(iterator first, size_type n, const value_type &value); - - template - iterator uninitialized_copy(InputIterator first, InputIterator last, iterator result); - - template - iterator uninitialized_copy(thrust::execution_policy &from_system, - InputIterator first, - InputIterator last, - iterator result); - - template - iterator uninitialized_copy_n(InputIterator first, Size n, iterator result); - - template - iterator uninitialized_copy_n(thrust::execution_policy &from_system, - InputIterator first, - Size n, - iterator result); - - void destroy(iterator first, iterator last); - - private: - // XXX we could inherit from this to take advantage of empty base class optimization - allocator_type m_allocator; - - iterator m_begin; - - size_type m_size; - - // disallow assignment - contiguous_storage &operator=(const contiguous_storage &x); -}; // end contiguous_storage - -} // end detail - -template void swap(detail::contiguous_storage &lhs, detail::contiguous_storage &rhs); - -} // end thrust - -#include - diff --git a/compat/thrust/detail/contiguous_storage.inl b/compat/thrust/detail/contiguous_storage.inl deleted file mode 100644 index 7e26c26..0000000 --- a/compat/thrust/detail/contiguous_storage.inl +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include // for use of std::swap in the WAR below - -namespace thrust -{ - -namespace detail -{ - -template - contiguous_storage - ::contiguous_storage(const Alloc &alloc) - :m_allocator(alloc), - m_begin(pointer(static_cast(0))), - m_size(0) -{ - ; -} // end contiguous_storage::contiguous_storage() - -template - contiguous_storage - ::contiguous_storage(size_type n, const Alloc &alloc) - :m_allocator(alloc), - m_begin(pointer(static_cast(0))), - m_size(0) -{ - allocate(n); -} // end contiguous_storage::contiguous_storage() - -template - contiguous_storage - ::~contiguous_storage(void) -{ - deallocate(); -} // end contiguous_storage::~contiguous_storage() - -template - typename contiguous_storage::size_type - contiguous_storage - ::size(void) const -{ - return m_size; -} // end contiguous_storage::size() - -template - typename contiguous_storage::size_type - contiguous_storage - ::max_size(void) const -{ - return alloc_traits::max_size(m_allocator); -} // end contiguous_storage::max_size() - -template - typename contiguous_storage::iterator - contiguous_storage - ::begin(void) -{ - return m_begin; -} // end contiguous_storage::begin() - -template - typename contiguous_storage::const_iterator - contiguous_storage - ::begin(void) const -{ - return m_begin; -} // end contiguous_storage::begin() - -template - typename contiguous_storage::iterator - contiguous_storage - ::end(void) -{ - return m_begin + size(); -} // end contiguous_storage::end() - -template - typename contiguous_storage::const_iterator - contiguous_storage - ::end(void) const -{ - return m_begin + size(); -} // end contiguous_storage::end() - -template - typename contiguous_storage::reference - contiguous_storage - ::operator[](size_type n) -{ - return m_begin[n]; -} // end contiguous_storage::operator[]() - -template - typename contiguous_storage::const_reference - contiguous_storage - ::operator[](size_type n) const -{ - return m_begin[n]; -} // end contiguous_storage::operator[]() - -template - typename contiguous_storage::allocator_type - contiguous_storage - ::get_allocator(void) const -{ - return m_allocator; -} // end contiguous_storage::get_allocator() - -template - void contiguous_storage - ::allocate(size_type n) -{ - if(n > 0) - { - m_begin = iterator(m_allocator.allocate(n)); - m_size = n; - } // end if - else - { - m_begin = iterator(pointer(static_cast(0))); - m_size = 0; - } // end else -} // end contiguous_storage::allocate() - -template - void contiguous_storage - ::deallocate(void) -{ - if(size() > 0) - { - m_allocator.deallocate(m_begin.base(), size()); - m_begin = iterator(pointer(static_cast(0))); - m_size = 0; - } // end if -} // end contiguous_storage::deallocate() - -template - void contiguous_storage - ::swap(contiguous_storage &x) -{ - thrust::swap(m_begin, x.m_begin); - thrust::swap(m_size, x.m_size); - - // XXX WAR nvcc 4.0's "calling a __host__ function from a __host__ __device__ function is not allowed" warning - //thrust::swap(m_allocator, x.m_allocator); - std::swap(m_allocator, x.m_allocator); -} // end contiguous_storage::swap() - -template - void contiguous_storage - ::default_construct_n(iterator first, size_type n) -{ - default_construct_range(m_allocator, first.base(), n); -} // end contiguous_storage::default_construct_n() - -template - void contiguous_storage - ::uninitialized_fill_n(iterator first, size_type n, const value_type &x) -{ - fill_construct_range(m_allocator, first.base(), n, x); -} // end contiguous_storage::uninitialized_fill() - -template - template - typename contiguous_storage::iterator - contiguous_storage - ::uninitialized_copy(thrust::execution_policy &from_system, InputIterator first, InputIterator last, iterator result) -{ - return iterator(copy_construct_range(from_system, m_allocator, first, last, result.base())); -} // end contiguous_storage::uninitialized_copy() - -template - template - typename contiguous_storage::iterator - contiguous_storage - ::uninitialized_copy(InputIterator first, InputIterator last, iterator result) -{ - // XXX assumes InputIterator's associated System is default-constructible - typename thrust::iterator_system::type from_system; - - return iterator(copy_construct_range(from_system, m_allocator, first, last, result.base())); -} // end contiguous_storage::uninitialized_copy() - -template - template - typename contiguous_storage::iterator - contiguous_storage - ::uninitialized_copy_n(thrust::execution_policy &from_system, InputIterator first, Size n, iterator result) -{ - return iterator(copy_construct_range_n(from_system, m_allocator, first, n, result.base())); -} // end contiguous_storage::uninitialized_copy_n() - -template - template - typename contiguous_storage::iterator - contiguous_storage - ::uninitialized_copy_n(InputIterator first, Size n, iterator result) -{ - // XXX assumes InputIterator's associated System is default-constructible - typename thrust::iterator_system::type from_system; - - return iterator(copy_construct_range_n(from_system, m_allocator, first, n, result.base())); -} // end contiguous_storage::uninitialized_copy_n() - -template - void contiguous_storage - ::destroy(iterator first, iterator last) -{ - destroy_range(m_allocator, first.base(), last - first); -} // end contiguous_storage::destroy() - -} // end detail - -template - void swap(detail::contiguous_storage &lhs, detail::contiguous_storage &rhs) -{ - lhs.swap(rhs); -} // end swap() - -} // end thrust - diff --git a/compat/thrust/detail/copy.h b/compat/thrust/detail/copy.h deleted file mode 100644 index 8ed3abd..0000000 --- a/compat/thrust/detail/copy.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -template - OutputIterator copy(const thrust::detail::execution_policy_base &system, - InputIterator first, - InputIterator last, - OutputIterator result); - -template - OutputIterator copy_n(const thrust::detail::execution_policy_base &system, - InputIterator first, - Size n, - OutputIterator result); - -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result); - -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result); - - -namespace detail -{ - - -template - OutputIterator two_system_copy(thrust::execution_policy &from_system, - thrust::execution_policy &two_system, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template - OutputIterator two_system_copy_n(thrust::execution_policy &from_system, - thrust::execution_policy &two_system, - InputIterator first, - Size n, - OutputIterator result); - - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/copy.inl b/compat/thrust/detail/copy.inl deleted file mode 100644 index 9ac4807..0000000 --- a/compat/thrust/detail/copy.inl +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::copy; - return copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result); -} // end copy() - - -template - OutputIterator copy_n(const thrust::detail::execution_policy_base &exec, - InputIterator first, - Size n, - OutputIterator result) -{ - using thrust::system::detail::generic::copy_n; - return copy_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, result); -} // end copy_n() - - -namespace detail -{ - - -template - OutputIterator two_system_copy(thrust::execution_policy &system1, - thrust::execution_policy &system2, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - return thrust::copy(select_system(thrust::detail::derived_cast(thrust::detail::strip_const(system1)), thrust::detail::derived_cast(thrust::detail::strip_const(system2))), first, last, result); -} // end two_system_copy() - - -template - OutputIterator two_system_copy_n(thrust::execution_policy &system1, - thrust::execution_policy &system2, - InputIterator first, - Size n, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - return thrust::copy_n(select_system(thrust::detail::derived_cast(thrust::detail::strip_const(system1)), thrust::detail::derived_cast(thrust::detail::strip_const(system2))), first, n, result); -} // end two_system_copy_n() - - -} // end detail - - -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result) -{ - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::detail::two_system_copy(system1, system2, first, last, result); -} // end copy() - - -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result) -{ - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::detail::two_system_copy_n(system1, system2, first, n, result); -} // end copy_n() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/copy_if.h b/compat/thrust/detail/copy_if.h deleted file mode 100644 index 54e1ef4..0000000 --- a/compat/thrust/detail/copy_if.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -template - OutputIterator copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - -template - OutputIterator copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - -template - OutputIterator copy_if(InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - -template - OutputIterator copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - -} // end thrust - -#include - diff --git a/compat/thrust/detail/copy_if.inl b/compat/thrust/detail/copy_if.inl deleted file mode 100644 index e443bb7..0000000 --- a/compat/thrust/detail/copy_if.inl +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::copy_if; - return copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, pred); -} // end copy_if() - - -template - OutputIterator copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::copy_if; - return copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, pred); -} // end copy_if() - - -template - OutputIterator copy_if(InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::copy_if(select_system(system1,system2), first, last, result, pred); -} // end copy_if() - - -template - OutputIterator copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::copy_if(select_system(system1,system2,system3), first, last, stencil, result, pred); -} // end copy_if() - - -} // end thrust - diff --git a/compat/thrust/detail/count.inl b/compat/thrust/detail/count.inl deleted file mode 100644 index d2856ae..0000000 --- a/compat/thrust/detail/count.inl +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file count.inl - * \brief Inline file for count.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - typename thrust::iterator_traits::difference_type - count(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, const EqualityComparable& value) -{ - using thrust::system::detail::generic::count; - return count(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} // end count() - - -template - typename thrust::iterator_traits::difference_type - count_if(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::count_if; - return count_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end count_if() - - -template -typename thrust::iterator_traits::difference_type -count(InputIterator first, InputIterator last, const EqualityComparable& value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::count(select_system(system), first, last, value); -} // end count() - - -template -typename thrust::iterator_traits::difference_type -count_if(InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::count_if(select_system(system), first, last, pred); -} // end count_if() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/cstdint.h b/compat/thrust/detail/cstdint.h deleted file mode 100644 index 25d30fd..0000000 --- a/compat/thrust/detail/cstdint.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC) -#include -#endif - -namespace thrust -{ -namespace detail -{ - -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) - -#if (_MSC_VER < 1300) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef signed __int8 int8_t; - typedef signed __int16 int16_t; - typedef signed __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - -#else - -typedef ::int8_t int8_t; -typedef ::int16_t int16_t; -typedef ::int32_t int32_t; -typedef ::int64_t int64_t; -typedef ::uint8_t uint8_t; -typedef ::uint16_t uint16_t; -typedef ::uint32_t uint32_t; -typedef ::uint64_t uint64_t; - -#endif - - -// an oracle to tell us how to define intptr_t -template struct divine_intptr_t; -template struct divine_uintptr_t; - -// 32b platforms -template<> struct divine_intptr_t<4> { typedef thrust::detail::int32_t type; }; -template<> struct divine_uintptr_t<4> { typedef thrust::detail::uint32_t type; }; - -// 64b platforms -template<> struct divine_intptr_t<8> { typedef thrust::detail::int64_t type; }; -template<> struct divine_uintptr_t<8> { typedef thrust::detail::uint64_t type; }; - -typedef divine_intptr_t<>::type intptr_t; -typedef divine_uintptr_t<>::type uintptr_t; - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/device_delete.inl b/compat/thrust/detail/device_delete.inl deleted file mode 100644 index dd70d76..0000000 --- a/compat/thrust/detail/device_delete.inl +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_delete.inl - * \brief Inline file for device_delete.h. - */ - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -// define an empty allocator class to use below -struct device_delete_allocator {}; - -} - -template - void device_delete(device_ptr ptr, - const size_t n) -{ - // we can use device_allocator to destroy the range - thrust::detail::device_delete_allocator a; - thrust::detail::destroy_range(a, ptr, n); - thrust::device_free(ptr); -} // end device_delete() - -} // end thrust - diff --git a/compat/thrust/detail/device_free.inl b/compat/thrust/detail/device_free.inl deleted file mode 100644 index ab8db9f..0000000 --- a/compat/thrust/detail/device_free.inl +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_free.inl - * \brief Inline file for device_free.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - -void device_free(thrust::device_ptr ptr) -{ - using thrust::system::detail::generic::select_system; - - typedef thrust::iterator_system< thrust::device_ptr >::type system; - - // XXX lower to select_system(system) here - system s; - - thrust::free(s, ptr); -} // end device_free() - -} // end thrust - diff --git a/compat/thrust/detail/device_malloc.inl b/compat/thrust/detail/device_malloc.inl deleted file mode 100644 index 76d0029..0000000 --- a/compat/thrust/detail/device_malloc.inl +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_malloc.inl - * \brief Inline file for device_malloc.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -thrust::device_ptr device_malloc(const std::size_t n) -{ - using thrust::system::detail::generic::select_system; - - typedef thrust::iterator_system< thrust::device_ptr >::type system; - - // XXX lower to select_system(system) here - system s; - - return thrust::device_ptr(thrust::malloc(s, n).get()); -} // end device_malloc() - - -template - thrust::device_ptr device_malloc(const std::size_t n) -{ - using thrust::system::detail::generic::select_system; - - typedef thrust::iterator_system< thrust::device_ptr >::type system; - - // XXX lower to select_system(system) here - system s; - - return thrust::device_ptr(thrust::malloc(s,n).get()); -} // end device_malloc() - - -} // end thrust - diff --git a/compat/thrust/detail/device_new.inl b/compat/thrust/detail/device_new.inl deleted file mode 100644 index 1f00a97..0000000 --- a/compat/thrust/detail/device_new.inl +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_new.inl - * \brief Inline file for device_new.h. - */ - -#include -#include -#include - -namespace thrust -{ - -template - device_ptr device_new(device_ptr p, - const size_t n) -{ - // XXX TODO dispatch n null device constructors at p here - // in the meantime, dispatch 1 null host constructor here - // and dispatch n copy constructors - return device_new(p, T(), n); -} // end device_new() - -template - device_ptr device_new(device_ptr p, - const T &exemplar, - const size_t n) -{ - device_ptr result(reinterpret_cast(p.get())); - - // run copy constructors at p here - thrust::uninitialized_fill(result, result + n, exemplar); - - return result; -} // end device_new() - -template - device_ptr device_new(const size_t n) -{ - // call placement new - return device_new(thrust::device_malloc(n)); -} // end device_new() - -} // thrust - diff --git a/compat/thrust/detail/device_ptr.inl b/compat/thrust/detail/device_ptr.inl deleted file mode 100644 index 0afe8a1..0000000 --- a/compat/thrust/detail/device_ptr.inl +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_ptr.inl - * \brief Inline file for device_ptr.h. - */ - -#include -#include -#include - -#include -#include - -namespace thrust -{ - -template - device_ptr device_pointer_cast(T *ptr) -{ - return device_ptr(ptr); -} // end device_pointer_cast() - -template - device_ptr device_pointer_cast(const device_ptr &ptr) -{ - return ptr; -} // end device_pointer_cast() - -// output to ostream -template - std::basic_ostream &operator<<(std::basic_ostream &os, const device_ptr &p) -{ - return os << p.get(); -} // end operator<<() - - -namespace detail -{ - -template - struct is_device_ptr< thrust::device_ptr > - : public true_type -{ -}; // end is_device_ptr - -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400) -// XXX WAR MSVC 2005 problem with correctly implementing -// pointer_raw_pointer for device_ptr by specializing it here -template - struct pointer_raw_pointer< thrust::device_ptr > -{ - typedef typename device_ptr::raw_pointer type; -}; // end pointer_raw_pointer -#endif - - -} // end namespace detail -} // end namespace thrust - diff --git a/compat/thrust/detail/device_reference.inl b/compat/thrust/detail/device_reference.inl deleted file mode 100644 index ad5cb76..0000000 --- a/compat/thrust/detail/device_reference.inl +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_reference.inl - * \brief Inline file for device_reference.h. - */ - -#include -#include - -namespace thrust -{ - -template - template - device_reference & - device_reference - ::operator=(const device_reference &other) -{ - return super_t::operator=(other); -} // end operator=() - -template - device_reference & - device_reference - ::operator=(const value_type &x) -{ - return super_t::operator=(x); -} // end operator=() - -template -__host__ __device__ -void swap(device_reference &a, device_reference &b) -{ - a.swap(b); -} // end swap() - -} // end thrust - diff --git a/compat/thrust/detail/device_vector.inl b/compat/thrust/detail/device_vector.inl deleted file mode 100644 index f6bafba..0000000 --- a/compat/thrust/detail/device_vector.inl +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_vector.inl - * \brief Inline file for device_vector.h. - */ - -#include - -namespace thrust -{ - -template - template - device_vector - ::device_vector(const host_vector &v) - :Parent(v) -{ - ; -} // end device_vector::device_vector() - -} // end namespace thrust - diff --git a/compat/thrust/detail/dispatch/is_trivial_copy.h b/compat/thrust/detail/dispatch/is_trivial_copy.h deleted file mode 100644 index 2bedf1f..0000000 --- a/compat/thrust/detail/dispatch/is_trivial_copy.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file trivial_copy.h - * \brief Device implementations for copying memory between host and device. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -namespace dispatch -{ - - -// a trivial copy's iterator's value_types match, -// the iterators themselves are normal_iterators -// and the ToIterator's value_type has_trivial_assign -template - struct is_trivial_copy : - integral_constant< - bool, - is_same< - typename thrust::iterator_value::type, - typename thrust::iterator_value::type - >::value - && is_trivial_iterator::value - && is_trivial_iterator::value - && has_trivial_assign::type>::value - > {}; - -} // end namespace dispatch - -} // end namespace detail - -} // end namespace thrust - diff --git a/compat/thrust/detail/distance.inl b/compat/thrust/detail/distance.inl deleted file mode 100644 index f37595f..0000000 --- a/compat/thrust/detail/distance.inl +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file distance.inl - * \brief Inline file for distance.h - */ - -#include -#include -#include - -namespace thrust -{ - - -template - inline typename thrust::iterator_traits::difference_type - distance(InputIterator first, InputIterator last) -{ - return thrust::system::detail::generic::distance(first, last); -} // end distance() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/equal.inl b/compat/thrust/detail/equal.inl deleted file mode 100644 index ca6fecc..0000000 --- a/compat/thrust/detail/equal.inl +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file equal.inl - * \brief Inline file for equal.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -bool equal(const thrust::detail::execution_policy_base &system, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) -{ - using thrust::system::detail::generic::equal; - return equal(thrust::detail::derived_cast(thrust::detail::strip_const(system)), first1, last1, first2); -} // end equal() - - -template -bool equal(const thrust::detail::execution_policy_base &system, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::equal; - return equal(thrust::detail::derived_cast(thrust::detail::strip_const(system)), first1, last1, first2, binary_pred); -} // end equal() - - -template -bool equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::equal(select_system(system1,system2), first1, last1, first2); -} - - -template -bool equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::equal(select_system(system1,system2), first1, last1, first2, binary_pred); -} - - -} // end namespace thrust - diff --git a/compat/thrust/detail/execute_with_allocator.h b/compat/thrust/detail/execute_with_allocator.h deleted file mode 100644 index 9d3c1ba..0000000 --- a/compat/thrust/detail/execute_with_allocator.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template -__host__ __device__ -ToPointer reinterpret_pointer_cast(FromPointer ptr) -{ - typedef typename thrust::detail::pointer_element::type to_element; - return ToPointer(reinterpret_cast(thrust::raw_pointer_cast(ptr))); -} - - -template class BaseSystem> - struct execute_with_allocator - : BaseSystem > -{ - Allocator &m_alloc; - - execute_with_allocator(Allocator &alloc) - : m_alloc(alloc) - {} - - template - friend thrust::pair - get_temporary_buffer(execute_with_allocator &system, std::ptrdiff_t n) - { - typedef typename thrust::detail::allocator_traits alloc_traits; - typedef typename alloc_traits::void_pointer void_pointer; - typedef typename alloc_traits::size_type size_type; - typedef typename alloc_traits::value_type value_type; - - // how many elements of type value_type do we need to accomodate n elements of type T? - size_type num_elements = thrust::detail::util::divide_ri(sizeof(T) * n, sizeof(value_type)); - - // allocate that many - void_pointer ptr = alloc_traits::allocate(system.m_alloc, num_elements); - - // return the pointer and the number of elements of type T allocated - return thrust::make_pair(thrust::detail::reinterpret_pointer_cast(ptr),n); - } - - template - friend void return_temporary_buffer(execute_with_allocator &system, Pointer p) - { - typedef typename thrust::detail::allocator_traits alloc_traits; - typedef typename alloc_traits::pointer pointer; - - // return the pointer to the allocator - pointer to_ptr = thrust::detail::reinterpret_pointer_cast(p); - alloc_traits::deallocate(system.m_alloc, to_ptr, 0); - } -}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/execution_policy.h b/compat/thrust/detail/execution_policy.h deleted file mode 100644 index 28e77f2..0000000 --- a/compat/thrust/detail/execution_policy.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - - -// execution_policy_base serves as a guard against -// inifinite recursion in thrust entry points: -// -// template -// void foo(const thrust::detail::execution_policy_base &s) -// { -// using thrust::system::detail::generic::foo; -// -// foo(thrust::detail::derived_cast(thrust::detail::strip_const(s)); -// } -// -// foo is not recursive when -// 1. DerivedPolicy is derived from thrust::execution_policy below -// 2. generic::foo takes thrust::execution_policy as a parameter -template struct execution_policy_base {}; - - -template -__host__ __device__ -inline execution_policy_base &strip_const(const execution_policy_base &x) -{ - return const_cast&>(x); -} - - -template -__host__ __device__ -inline DerivedPolicy &derived_cast(execution_policy_base &x) -{ - return static_cast(x); -} - - -template -__host__ __device__ -inline const DerivedPolicy &derived_cast(const execution_policy_base &x) -{ - return static_cast(x); -} - - -} // end detail - - -template - struct execution_policy - : thrust::detail::execution_policy_base -{}; - - -} // end thrust - diff --git a/compat/thrust/detail/extrema.inl b/compat/thrust/detail/extrema.inl deleted file mode 100644 index 4bcd0bd..0000000 --- a/compat/thrust/detail/extrema.inl +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -ForwardIterator min_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last) -{ - using thrust::system::detail::generic::min_element; - return min_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end min_element() - - -template -ForwardIterator min_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp) -{ - using thrust::system::detail::generic::min_element; - return min_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end min_element() - - -template -ForwardIterator max_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last) -{ - using thrust::system::detail::generic::max_element; - return max_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end max_element() - - -template -ForwardIterator max_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp) -{ - using thrust::system::detail::generic::max_element; - return max_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end max_element() - - -template -thrust::pair minmax_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last) -{ - using thrust::system::detail::generic::minmax_element; - return minmax_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end minmax_element() - - -template -thrust::pair minmax_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp) -{ - using thrust::system::detail::generic::minmax_element; - return minmax_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end minmax_element() - - -template -ForwardIterator min_element(ForwardIterator first, ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::min_element(select_system(system), first, last); -} // end min_element() - - -template -ForwardIterator min_element(ForwardIterator first, ForwardIterator last, - BinaryPredicate comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::min_element(select_system(system), first, last, comp); -} // end min_element() - - -template -ForwardIterator max_element(ForwardIterator first, ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::max_element(select_system(system), first, last); -} // end max_element() - - -template -ForwardIterator max_element(ForwardIterator first, ForwardIterator last, - BinaryPredicate comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::max_element(select_system(system), first, last, comp); -} // end max_element() - - -template -thrust::pair -minmax_element(ForwardIterator first, ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::minmax_element(select_system(system), first, last); -} // end minmax_element() - - -template -thrust::pair -minmax_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::minmax_element(select_system(system), first, last, comp); -} // end minmax_element() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/fill.inl b/compat/thrust/detail/fill.inl deleted file mode 100644 index c60e4a0..0000000 --- a/compat/thrust/detail/fill.inl +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file fill.inl - * \brief Inline file for fill.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void fill(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value) -{ - using thrust::system::detail::generic::fill; - return fill(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} // end fill() - - -template - OutputIterator fill_n(const thrust::detail::execution_policy_base &exec, - OutputIterator first, - Size n, - const T &value) -{ - using thrust::system::detail::generic::fill_n; - return fill_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, value); -} // end fill_n() - - -template - void fill(ForwardIterator first, - ForwardIterator last, - const T &value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - thrust::fill(select_system(system), first, last, value); -} // end fill() - - -template - OutputIterator fill_n(OutputIterator first, - Size n, - const T &value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::fill_n(select_system(system), first, n, value); -} // end fill() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/find.inl b/compat/thrust/detail/find.inl deleted file mode 100644 index 465c937..0000000 --- a/compat/thrust/detail/find.inl +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file find.inl - * \brief Inline file for find.h - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -InputIterator find(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - const T& value) -{ - using thrust::system::detail::generic::find; - return find(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} // end find() - - -template -InputIterator find_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::find_if; - return find_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end find_if() - - -template -InputIterator find_if_not(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::find_if_not; - return find_if_not(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end find_if_not() - - -template -InputIterator find(InputIterator first, - InputIterator last, - const T& value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::find(select_system(system), first, last, value); -} - -template -InputIterator find_if(InputIterator first, - InputIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::find_if(select_system(system), first, last, pred); -} - -template -InputIterator find_if_not(InputIterator first, - InputIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::find_if_not(select_system(system), first, last, pred); -} - - -} // end namespace thrust - diff --git a/compat/thrust/detail/for_each.inl b/compat/thrust/detail/for_each.inl deleted file mode 100644 index 7c9dc17..0000000 --- a/compat/thrust/detail/for_each.inl +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.inl - * \brief Inline file for for_each.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - InputIterator for_each(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - UnaryFunction f) -{ - using thrust::system::detail::generic::for_each; - - return for_each(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, f); -} - - -template -InputIterator for_each(InputIterator first, - InputIterator last, - UnaryFunction f) -{ - using thrust::system::detail::generic::select_system; - typedef typename thrust::iterator_system::type System; - - System system; - return thrust::for_each(select_system(system), first, last, f); -} // end for_each() - - -template - InputIterator for_each_n(const thrust::detail::execution_policy_base &exec, - InputIterator first, - Size n, - UnaryFunction f) -{ - using thrust::system::detail::generic::for_each_n; - - return for_each_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, f); -} // end for_each_n() - - -template -InputIterator for_each_n(InputIterator first, - Size n, - UnaryFunction f) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - return thrust::for_each_n(select_system(system), first, n, f); -} // end for_each_n() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/function.h b/compat/thrust/detail/function.h deleted file mode 100644 index 36b76c2..0000000 --- a/compat/thrust/detail/function.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - struct host_function -{ - // mutable because Function::operator() might be const - mutable Function m_f; - - inline host_function() - : m_f() - {} - - inline host_function(const Function &f) - : m_f(f) - {} - - template - inline Result operator()(Argument &x) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x))); - } - - template - inline Result operator()(const Argument &x) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x))); - } - - template - inline Result operator()(Argument1 &x, Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline Result operator()(const Argument1 &x, Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline Result operator()(const Argument1 &x, const Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline Result operator()(Argument1 &x, const Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } -}; // end host_function - - -template - struct device_function -{ - // mutable because Function::operator() might be const - mutable Function m_f; - - inline __device__ device_function() - : m_f() - {} - - inline __device__ device_function(const Function &f) - : m_f(f) - {} - - template - inline __device__ Result operator()(Argument &x) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x))); - } - - template - inline __device__ Result operator()(const Argument &x) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x))); - } - - template - inline __device__ Result operator()(Argument1 &x, Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline __device__ Result operator()(const Argument1 &x, Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline __device__ Result operator()(const Argument1 &x, const Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline __device__ Result operator()(Argument1 &x, const Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } -}; // end device_function - - -template - struct host_device_function -{ - // mutable because Function::operator() might be const - mutable Function m_f; - - inline __host__ __device__ - host_device_function() - : m_f() - {} - - inline __host__ __device__ - host_device_function(const Function &f) - : m_f(f) - {} - - __thrust_hd_warning_disable__ - template - inline __host__ __device__ - Result operator()(Argument &x) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x))); - } - - template - inline __host__ __device__ Result operator()(const Argument &x) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x))); - } - - template - inline __host__ __device__ Result operator()(Argument1 &x, Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline __host__ __device__ Result operator()(const Argument1 &x, Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline __host__ __device__ Result operator()(const Argument1 &x, const Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } - - template - inline __host__ __device__ Result operator()(Argument1 &x, const Argument2 &y) const - { - // we static cast to Result to handle void Result without error - // in case Function's result is non-void - return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); - } -}; // end host_device_function - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional.inl b/compat/thrust/detail/functional.inl deleted file mode 100644 index 4024585..0000000 --- a/compat/thrust/detail/functional.inl +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace thrust -{ - -namespace detail -{ - -template - struct unary_traits_imp; - -template - struct unary_traits_imp -{ - typedef Operation function_type; - typedef const function_type & param_type; - typedef typename Operation::result_type result_type; - typedef typename Operation::argument_type argument_type; -}; // end unary_traits_imp - -template - struct unary_traits_imp -{ - typedef Result (*function_type)(Argument); - typedef Result (*param_type)(Argument); - typedef Result result_type; - typedef Argument argument_type; -}; // end unary_traits_imp - -template - struct binary_traits_imp; - -template - struct binary_traits_imp -{ - typedef Operation function_type; - typedef const function_type & param_type; - typedef typename Operation::result_type result_type; - typedef typename Operation::first_argument_type first_argument_type; - typedef typename Operation::second_argument_type second_argument_type; -}; // end binary_traits_imp - -template - struct binary_traits_imp -{ - typedef Result (*function_type)(Argument1, Argument2); - typedef Result (*param_type)(Argument1, Argument2); - typedef Result result_type; - typedef Argument1 first_argument_type; - typedef Argument2 second_argument_type; -}; // end binary_traits_imp - -} // end detail - -template - struct unary_traits -{ - typedef typename detail::unary_traits_imp::function_type function_type; - typedef typename detail::unary_traits_imp::param_type param_type; - typedef typename detail::unary_traits_imp::result_type result_type; - typedef typename detail::unary_traits_imp::argument_type argument_type; -}; // end unary_traits - -template - struct unary_traits -{ - typedef Result (*function_type)(Argument); - typedef Result (*param_type)(Argument); - typedef Result result_type; - typedef Argument argument_type; -}; // end unary_traits - -template - struct binary_traits -{ - typedef typename detail::binary_traits_imp::function_type function_type; - typedef typename detail::binary_traits_imp::param_type param_type; - typedef typename detail::binary_traits_imp::result_type result_type; - typedef typename detail::binary_traits_imp::first_argument_type first_argument_type; - typedef typename detail::binary_traits_imp::second_argument_type second_argument_type; -}; // end binary_traits - -template - struct binary_traits -{ - typedef Result (*function_type)(Argument1, Argument2); - typedef Result (*param_type)(Argument1, Argument2); - typedef Result result_type; - typedef Argument1 first_argument_type; - typedef Argument2 second_argument_type; -}; // end binary_traits - -template - unary_negate not1(const Predicate &pred) -{ - return unary_negate(pred); -} // end not1() - -template - binary_negate not2(const BinaryPredicate &pred) -{ - return binary_negate(pred); -} // end not2() - -} // end thrust - diff --git a/compat/thrust/detail/functional/actor.h b/compat/thrust/detail/functional/actor.h deleted file mode 100644 index 0b95a6b..0000000 --- a/compat/thrust/detail/functional/actor.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Portions of this code are derived from -// -// Manjunath Kudlur's Carbon library -// -// and -// -// Based on Boost.Phoenix v1.2 -// Copyright (c) 2001-2002 Joel de Guzman - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template - struct apply_actor -{ - typedef typename Action::template result::type type; -}; - -template - struct actor - : Eval -{ - typedef Eval eval_type; - - __host__ __device__ - actor(void); - - __host__ __device__ - actor(const Eval &base); - - __host__ __device__ - typename apply_actor::type - operator()(void) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8) const; - - template - __host__ __device__ - typename apply_actor >::type - operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8, T9 &_9) const; - - template - __host__ __device__ - typename assign_result::type - operator=(const T &_1) const; -}; // end actor - -// in general, as_actor should turn things into values -template - struct as_actor -{ - typedef value type; - - static inline __host__ __device__ type convert(const T &x) - { - return val(x); - } // end convert() -}; // end as_actor - -// specialization for things which are already actors -template - struct as_actor > -{ - typedef actor type; - - static inline __host__ __device__ const type &convert(const actor &x) - { - return x; - } // end convert() -}; // end as_actor - -template - typename as_actor::type - __host__ __device__ - make_actor(const T &x) -{ - return as_actor::convert(x); -} // end make_actor() - -} // end functional - -// provide specializations for result_of for nullary, unary, and binary invocations of actor -template - struct result_of< - thrust::detail::functional::actor() - > -{ - typedef typename thrust::detail::functional::apply_actor< - thrust::detail::functional::actor, - thrust::null_type - >::type type; -}; // end result_of - -template - struct result_of< - thrust::detail::functional::actor(Arg1) - > -{ - typedef typename thrust::detail::functional::apply_actor< - thrust::detail::functional::actor, - thrust::tuple - >::type type; -}; // end result_of - -template - struct result_of< - thrust::detail::functional::actor(Arg1,Arg2) - > -{ - typedef typename thrust::detail::functional::apply_actor< - thrust::detail::functional::actor, - thrust::tuple - >::type type; -}; // end result_of - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/functional/actor.inl b/compat/thrust/detail/functional/actor.inl deleted file mode 100644 index 84347be..0000000 --- a/compat/thrust/detail/functional/actor.inl +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Portions of this code are derived from -// -// Manjunath Kudlur's Carbon library -// -// and -// -// Based on Boost.Phoenix v1.2 -// Copyright (c) 2001-2002 Joel de Guzman - -#include -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ -namespace functional -{ - -template - actor - ::actor(void) - : eval_type() -{} - -template - actor - ::actor(const Eval &base) - : eval_type(base) -{} - -template - typename apply_actor< - typename actor::eval_type, - typename thrust::null_type - >::type - actor - ::operator()(void) const -{ - return eval_type::eval(thrust::null_type()); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0) const -{ - return eval_type::eval(thrust::tie(_0)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1) const -{ - return eval_type::eval(thrust::tie(_0,_1)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6,_7)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6,_7,_8)); -} // end basic_environment::operator() - -template - template - typename apply_actor< - typename actor::eval_type, - typename thrust::tuple - >::type - actor - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8, T9 &_9) const -{ - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9)); -} // end basic_environment::operator() - -template - template - typename assign_result::type - actor - ::operator=(const T& _1) const -{ - return do_assign(*this,_1); -} // end actor::operator=() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/argument.h b/compat/thrust/detail/functional/argument.h deleted file mode 100644 index 96a20be..0000000 --- a/compat/thrust/detail/functional/argument.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Portions of this code are derived from -// -// Manjunath Kudlur's Carbon library -// -// and -// -// Based on Boost.Phoenix v1.2 -// Copyright (c) 2001-2002 Joel de Guzman - -#pragma once - -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template - struct argument_helper -{ - typedef typename thrust::tuple_element::type type; -}; - -template - struct argument_helper -{ - typedef thrust::null_type type; -}; - - -template - class argument -{ - public: - template - struct result - : argument_helper - { - }; - - __host__ __device__ - argument(void){} - - template - __host__ __device__ - typename result::type eval(const Env &e) const - { - return thrust::get(e); - } // end eval() -}; // end argument - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/composite.h b/compat/thrust/detail/functional/composite.h deleted file mode 100644 index 1d5fde3..0000000 --- a/compat/thrust/detail/functional/composite.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Portions of this code are derived from -// -// Manjunath Kudlur's Carbon library -// -// and -// -// Based on Boost.Phoenix v1.2 -// Copyright (c) 2001-2002 Joel de Guzman - -#pragma once - -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -// XXX we should just take a single EvalTuple -template - class composite; - -template - class composite< - Eval0, - Eval1, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type - > -{ - public: - template - struct result - { - typedef typename Eval0::template result< - thrust::tuple< - typename Eval1::template result::type - > - >::type type; - }; - - __host__ __device__ - composite(const Eval0 &e0, const Eval1 &e1) - : m_eval0(e0), - m_eval1(e1) - {} - - template - __host__ __device__ - typename result::type - eval(const Env &x) const - { - typename Eval1::template result::type result1 = m_eval1.eval(x); - return m_eval0.eval(thrust::tie(result1)); - } - - private: - Eval0 m_eval0; - Eval1 m_eval1; -}; // end composite - -template - class composite< - Eval0, - Eval1, - Eval2, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type, - thrust::null_type - > -{ - public: - template - struct result - { - typedef typename Eval0::template result< - thrust::tuple< - typename Eval1::template result::type, - typename Eval2::template result::type - > - >::type type; - }; - - __host__ __device__ - composite(const Eval0 &e0, const Eval1 &e1, const Eval2 &e2) - : m_eval0(e0), - m_eval1(e1), - m_eval2(e2) - {} - - template - __host__ __device__ - typename result::type - eval(const Env &x) const - { - typename Eval1::template result::type result1 = m_eval1.eval(x); - typename Eval2::template result::type result2 = m_eval2.eval(x); - return m_eval0.eval(thrust::tie(result1,result2)); - } - - private: - Eval0 m_eval0; - Eval1 m_eval1; - Eval2 m_eval2; -}; // end composite - -template -__host__ __device__ - actor > compose(const Eval0 &e0, const Eval1 &e1) -{ - return actor >(composite(e0,e1)); -} - -template -__host__ __device__ - actor > compose(const Eval0 &e0, const Eval1 &e1, const Eval2 &e2) -{ - return actor >(composite(e0,e1,e2)); -} - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators.h b/compat/thrust/detail/functional/operators.h deleted file mode 100644 index 0fc3539..0000000 --- a/compat/thrust/detail/functional/operators.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - diff --git a/compat/thrust/detail/functional/operators/arithmetic_operators.h b/compat/thrust/detail/functional/operators/arithmetic_operators.h deleted file mode 100644 index a11e7ac..0000000 --- a/compat/thrust/detail/functional/operators/arithmetic_operators.h +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -__host__ __device__ -operator-(const actor &_1) -{ - return compose(unary_operator(), _1); -} // end operator-() - -// there's no standard unary_plus functional, so roll an ad hoc one here -template - struct unary_plus - : public thrust::unary_function -{ - __host__ __device__ T operator()(const T &x) const {return +x;} -}; // end unary_plus - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -operator+(const actor &_1) -{ - return compose(unary_operator(), _1); -} // end operator+() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator+(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator+() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator+(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator+() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator+(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator+() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator-(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator-() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator-(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator-() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator-(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator-() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator*(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator*() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator*(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator*() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator*(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator*() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator/(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator/() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator/(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator/() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator/(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator/() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator%(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator%() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator%(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator%() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator%(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator%() - -// there's no standard prefix_increment functional, so roll an ad hoc one here -template - struct prefix_increment - : public thrust::unary_function -{ - __host__ __device__ T& operator()(T &x) const { return ++x; } -}; // end prefix_increment - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -operator++(const actor &_1) -{ - return compose(unary_operator(), _1); -} // end operator++() - -// there's no standard suffix_increment functional, so roll an ad hoc one here -template - struct suffix_increment - : public thrust::unary_function -{ - __host__ __device__ T operator()(T &x) const { return x++; } -}; // end suffix_increment - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -operator++(const actor &_1, int) -{ - return compose(unary_operator(), _1); -} // end operator++() - -// there's no standard prefix_decrement functional, so roll an ad hoc one here -template - struct prefix_decrement - : public thrust::unary_function -{ - __host__ __device__ T& operator()(T &x) const { return --x; } -}; // end prefix_decrement - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -operator--(const actor &_1) -{ - return compose(unary_operator(), _1); -} // end operator--() - -// there's no standard suffix_decrement functional, so roll an ad hoc one here -template - struct suffix_decrement - : public thrust::unary_function -{ - __host__ __device__ T operator()(T &x) const { return x--; } -}; // end suffix_decrement - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -operator--(const actor &_1, int) -{ - return compose(unary_operator(), _1); -} // end operator--() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators/assignment_operator.h b/compat/thrust/detail/functional/operators/assignment_operator.h deleted file mode 100644 index e5d6620..0000000 --- a/compat/thrust/detail/functional/operators/assignment_operator.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -// XXX WAR circular inclusion with this forward declaration -template struct binary_function; - -namespace detail -{ -namespace functional -{ - -// XXX WAR circular inclusion with this forward declaration -template struct as_actor; - -// there's no standard assign functional, so roll an ad hoc one here -template - struct assign - : thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T &rhs) const { return lhs = rhs; } -}; // end assign - -template - struct assign_result -{ - typedef actor< - composite< - binary_operator, - actor, - typename as_actor::type - > - > type; -}; // end assign_result - -template - __host__ __device__ - typename assign_result::type - do_assign(const actor &_1, const T &_2) -{ - return compose(binary_operator(), - _1, - as_actor::convert(_2)); -} // end do_assign() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators/bitwise_operators.h b/compat/thrust/detail/functional/operators/bitwise_operators.h deleted file mode 100644 index c89c5d4..0000000 --- a/compat/thrust/detail/functional/operators/bitwise_operators.h +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator&(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator&(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator&(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator|(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator|(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator|(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator^(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator^() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator^(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator^() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator^(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator^() - -// there's no standard bit_not functional, so roll an ad hoc one here -template - struct bit_not - : public thrust::unary_function -{ - __host__ __device__ T operator()(const T &x) const {return ~x;} -}; // end bit_not - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -__host__ __device__ -operator~(const actor &_1) -{ - return compose(unary_operator(), _1); -} // end operator~() - -// there's no standard bit_lshift functional, so roll an ad hoc one here -template - struct bit_lshift - : public thrust::binary_function -{ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs << rhs;} -}; // end bit_lshift - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator<<(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<<() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator<<(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<<() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator<<(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<<() - -// there's no standard bit_rshift functional, so roll an ad hoc one here -template - struct bit_rshift - : public thrust::binary_function -{ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs >> rhs;} -}; // end bit_rshift - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator>>(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>>() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator>>(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>>() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator>>(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>>() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators/compound_assignment_operators.h b/compat/thrust/detail/functional/operators/compound_assignment_operators.h deleted file mode 100644 index ef7389b..0000000 --- a/compat/thrust/detail/functional/operators/compound_assignment_operators.h +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template - struct plus_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T &rhs) const { return lhs += rhs; } -}; // end plus_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator+=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator+=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator+=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator+=() - -template - struct minus_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T &rhs) const { return lhs -= rhs; } -}; // end minus_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator-=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator-=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator-=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator-=() - -template - struct multiplies_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs *= rhs; } -}; // end multiplies_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator*=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator*=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator*=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator*=() - -template - struct divides_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs /= rhs; } -}; // end divides_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator/=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator/=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator/=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator/=() - -template - struct modulus_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs %= rhs; } -}; // end modulus_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator%=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator%=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator%=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator%=() - -template - struct bit_and_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs &= rhs; } -}; // end bit_and_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator&=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator&=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&=() - -template - struct bit_or_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs |= rhs; } -}; // end bit_or_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator|=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator|=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|=() - -template - struct bit_xor_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs ^= rhs; } -}; // end bit_xor_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator^=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator^=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator|=() - -template - struct bit_lshift_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs <<= rhs; } -}; // end bit_lshift_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator<<=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<<=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator<<=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<<=() - -template - struct bit_rshift_equal - : public thrust::binary_function -{ - __host__ __device__ T& operator()(T &lhs, const T&rhs) const { return lhs >>= rhs; } -}; // end bit_rshift_equal - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator>>=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>>=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator>>=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>>=() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators/logical_operators.h b/compat/thrust/detail/functional/operators/logical_operators.h deleted file mode 100644 index 9c95262..0000000 --- a/compat/thrust/detail/functional/operators/logical_operators.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator&&(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator&&(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator&&(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator||(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator||(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&&() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator||(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator&&() - -template -__host__ __device__ -actor< - composite< - unary_operator, - actor - > -> -operator!(const actor &_1) -{ - return compose(unary_operator(), _1); -} // end operator!() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators/operator_adaptors.h b/compat/thrust/detail/functional/operators/operator_adaptors.h deleted file mode 100644 index d35fe97..0000000 --- a/compat/thrust/detail/functional/operators/operator_adaptors.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -// this thing (which models Eval) is an adaptor for the unary -// functors inside functional.h -template class UnaryOperator> - struct unary_operator -{ - template - struct argument - : thrust::detail::eval_if< - (thrust::tuple_size::value == 0), - thrust::detail::identity_, - thrust::tuple_element<0,Env> - > - { - }; - - template - struct operator_type - { - typedef UnaryOperator< - typename thrust::detail::remove_reference< - typename argument::type - >::type - > type; - }; - - template - struct result - { - typedef typename operator_type::type op_type; - typedef typename op_type::result_type type; - }; - - template - __host__ __device__ - typename result::type eval(const Env &e) const - { - typename operator_type::type op; - return op(thrust::get<0>(e)); - } // end eval() -}; // end unary_operator - -// this thing (which models Eval) is an adaptor for the binary -// functors inside functional.h -template class BinaryOperator> - struct binary_operator -{ - template - struct first_argument - : thrust::detail::eval_if< - (thrust::tuple_size::value == 0), - thrust::detail::identity_, - thrust::tuple_element<0,Env> - > - { - }; - - template - struct operator_type - { - typedef BinaryOperator< - typename thrust::detail::remove_reference< - typename first_argument::type - >::type - > type; - }; - - template - struct result - { - typedef typename operator_type::type op_type; - typedef typename op_type::result_type type; - }; - - template - __host__ __device__ - typename result::type eval(const Env &e) const - { - typename operator_type::type op; - return op(thrust::get<0>(e), thrust::get<1>(e)); - } // end eval() -}; // end binary_operator - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/operators/relational_operators.h b/compat/thrust/detail/functional/operators/relational_operators.h deleted file mode 100644 index 6b26534..0000000 --- a/compat/thrust/detail/functional/operators/relational_operators.h +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator==(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator==() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator==(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator==() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator==(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator==() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator!=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator!=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator!=(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator!=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator!=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator!=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator>(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator>(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator>(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator<(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator<(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator<(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator>=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator>=(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator>=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator>=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - typename as_actor::type - > -> -operator<=(const actor &_1, const T2 &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - typename as_actor::type, - actor - > -> -operator<=(const T1 &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<=() - -template -__host__ __device__ -actor< - composite< - binary_operator, - actor, - actor - > -> -operator<=(const actor &_1, const actor &_2) -{ - return compose(binary_operator(), - make_actor(_1), - make_actor(_2)); -} // end operator<=() - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/placeholder.h b/compat/thrust/detail/functional/placeholder.h deleted file mode 100644 index 9acf6da..0000000 --- a/compat/thrust/detail/functional/placeholder.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - -template - struct placeholder -{ - typedef actor > type; -}; - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/functional/value.h b/compat/thrust/detail/functional/value.h deleted file mode 100644 index 27e2802..0000000 --- a/compat/thrust/detail/functional/value.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Portions of this code are derived from -// -// Manjunath Kudlur's Carbon library -// -// and -// -// Based on Boost.Phoenix v1.2 -// Copyright (c) 2001-2002 Joel de Guzman - -#pragma once - -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace functional -{ - - -template struct actor; - - -template - class value -{ - public: - - template - struct result - { - typedef T type; - }; - - __host__ __device__ - value(const T &arg) - : m_val(arg) - {} - - template - __host__ __device__ - T eval(const Env &) const - { - return m_val; - } - - private: - T m_val; -}; // end value - -template -__host__ __device__ -actor > val(const T &x) -{ - return value(x); -} // end val() - - -} // end functional -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/gather.inl b/compat/thrust/detail/gather.inl deleted file mode 100644 index 4edecd0..0000000 --- a/compat/thrust/detail/gather.inl +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file gather.inl - * \brief Inline file for gather.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator gather(const thrust::detail::execution_policy_base &exec, - InputIterator map_first, - InputIterator map_last, - RandomAccessIterator input_first, - OutputIterator result) -{ - using thrust::system::detail::generic::gather; - return gather(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), map_first, map_last, input_first, result); -} // end gather() - - -template - OutputIterator gather_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result) -{ - using thrust::system::detail::generic::gather_if; - return gather_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), map_first, map_last, stencil, input_first, result); -} // end gather_if() - - -template - OutputIterator gather_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::gather_if; - return gather_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), map_first, map_last, stencil, input_first, result, pred); -} // end gather_if() - - -template - OutputIterator gather(InputIterator map_first, - InputIterator map_last, - RandomAccessIterator input_first, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::gather(select_system(system1,system2,system3), map_first, map_last, input_first, result); -} // end gather() - - -template - OutputIterator gather_if(InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::gather_if(select_system(system1,system2,system3,system4), map_first, map_last, stencil, input_first, result); -} // end gather_if() - - -template - OutputIterator gather_if(InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::gather_if(select_system(system1,system2,system3,system4), map_first, map_last, stencil, input_first, result, pred); -} // end gather_if() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/generate.inl b/compat/thrust/detail/generate.inl deleted file mode 100644 index c125804..0000000 --- a/compat/thrust/detail/generate.inl +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file generate.inl - * \author Jared Hoberock - * \brief Inline file for generate.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void generate(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Generator gen) -{ - using thrust::system::detail::generic::generate; - return generate(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, gen); -} // end generate() - - -template - OutputIterator generate_n(const thrust::detail::execution_policy_base &exec, - OutputIterator first, - Size n, - Generator gen) -{ - using thrust::system::detail::generic::generate_n; - return generate_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, gen); -} // end generate_n() - - -template - void generate(ForwardIterator first, - ForwardIterator last, - Generator gen) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::generate(select_system(system), first, last, gen); -} // end generate() - - -template - OutputIterator generate_n(OutputIterator first, - Size n, - Generator gen) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::generate_n(select_system(system), first, n, gen); -} // end generate_n() - - -} // end thrust - diff --git a/compat/thrust/detail/host_vector.inl b/compat/thrust/detail/host_vector.inl deleted file mode 100644 index e5c60ab..0000000 --- a/compat/thrust/detail/host_vector.inl +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file host_vector.inl - * \brief Inline file for host_vector.h. - */ - -#include - -namespace thrust -{ - -template - template - host_vector - ::host_vector(const device_vector &v) - :Parent(v) -{ - ; -} // end host_vector::host_vector() - -} // end namespace thrust - diff --git a/compat/thrust/detail/inner_product.inl b/compat/thrust/detail/inner_product.inl deleted file mode 100644 index f7773d8..0000000 --- a/compat/thrust/detail/inner_product.inl +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file inner_product.inl - * \brief Inline file for inner_product.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -OutputType inner_product(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init) -{ - using thrust::system::detail::generic::inner_product; - return inner_product(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, init); -} // end inner_product() - - -template -OutputType inner_product(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init, - BinaryFunction1 binary_op1, - BinaryFunction2 binary_op2) -{ - using thrust::system::detail::generic::inner_product; - return inner_product(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, init, binary_op1, binary_op2); -} // end inner_product() - - -template -OutputType -inner_product(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, OutputType init) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::inner_product(select_system(system1,system2), first1, last1, first2, init); -} // end inner_product() - - -template -OutputType -inner_product(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, OutputType init, - BinaryFunction1 binary_op1, BinaryFunction2 binary_op2) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::inner_product(select_system(system1,system2), first1, last1, first2, init, binary_op1, binary_op2); -} // end inner_product() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/integer_traits.h b/compat/thrust/detail/integer_traits.h deleted file mode 100644 index e4cf5d1..0000000 --- a/compat/thrust/detail/integer_traits.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -template - class integer_traits -{ - public: - static const bool is_integral = false; -}; - -template - class integer_traits_base -{ - public: - static const bool is_integral = true; - static const T const_min = min_val; - static const T const_max = max_val; -}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - - -template<> - class integer_traits - : public std::numeric_limits, - public integer_traits_base -{}; - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/internal_functional.h b/compat/thrust/detail/internal_functional.h deleted file mode 100644 index 6d5264a..0000000 --- a/compat/thrust/detail/internal_functional.h +++ /dev/null @@ -1,678 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file internal_functional.inl - * \brief Non-public functionals used to implement algorithm internals. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include // for ::new - -namespace thrust -{ -namespace detail -{ - -// unary_negate does not need to know argument_type -template -struct unary_negate -{ - typedef bool result_type; - - Predicate pred; - - __host__ __device__ - explicit unary_negate(const Predicate& pred) : pred(pred) {} - - template - __host__ __device__ - bool operator()(const T& x) - { - return !bool(pred(x)); - } -}; - -// binary_negate does not need to know first_argument_type or second_argument_type -template -struct binary_negate -{ - typedef bool result_type; - - Predicate pred; - - __host__ __device__ - explicit binary_negate(const Predicate& pred) : pred(pred) {} - - template - __host__ __device__ - bool operator()(const T1& x, const T2& y) - { - return !bool(pred(x,y)); - } -}; - -template - __host__ __device__ - thrust::detail::unary_negate not1(const Predicate &pred) -{ - return thrust::detail::unary_negate(pred); -} - -template - __host__ __device__ - thrust::detail::binary_negate not2(const Predicate &pred) -{ - return thrust::detail::binary_negate(pred); -} - - -// convert a predicate to a 0 or 1 integral value -template -struct predicate_to_integral -{ - Predicate pred; - - __host__ __device__ - explicit predicate_to_integral(const Predicate& pred) : pred(pred) {} - - template - __host__ __device__ - bool operator()(const T& x) - { - return pred(x) ? IntegralType(1) : IntegralType(0); - } -}; - - -// note that detail::equal_to does not force conversion from T2 -> T1 as equal_to does -template -struct equal_to -{ - typedef bool result_type; - - template - __host__ __device__ - bool operator()(const T1& lhs, const T2& rhs) const - { - return lhs == rhs; - } -}; - -// note that equal_to_value does not force conversion from T2 -> T1 as equal_to does -template -struct equal_to_value -{ - T2 rhs; - - equal_to_value(const T2& rhs) : rhs(rhs) {} - - template - __host__ __device__ - bool operator()(const T1& lhs) const - { - return lhs == rhs; - } -}; - -template -struct tuple_binary_predicate -{ - typedef bool result_type; - - __host__ __device__ - tuple_binary_predicate(const Predicate& p) : pred(p) {} - - template - __host__ __device__ - bool operator()(const Tuple& t) const - { - return pred(thrust::get<0>(t), thrust::get<1>(t)); - } - - Predicate pred; -}; - -template -struct tuple_not_binary_predicate -{ - typedef bool result_type; - - __host__ __device__ - tuple_not_binary_predicate(const Predicate& p) : pred(p) {} - - template - __host__ __device__ - bool operator()(const Tuple& t) const - { - return !pred(thrust::get<0>(t), thrust::get<1>(t)); - } - - Predicate pred; -}; - -template - struct host_generate_functor -{ - typedef void result_type; - - __host__ __device__ - host_generate_functor(Generator g) - : gen(g) {} - - // operator() does not take an lvalue reference because some iterators - // produce temporary proxy references when dereferenced. for example, - // consider the temporary tuple of references produced by zip_iterator. - // such temporaries cannot bind to an lvalue reference. - // - // to WAR this, accept a const reference (which is bindable to a temporary), - // and const_cast in the implementation. - // - // XXX change to an rvalue reference upon c++0x (which either a named variable - // or temporary can bind to) - template - __host__ - void operator()(const T &x) - { - // we have to be naughty and const_cast this to get it to work - T &lvalue = const_cast(x); - - // this assigns correctly whether x is a true reference or proxy - lvalue = gen(); - } - - Generator gen; -}; - -template - struct device_generate_functor -{ - typedef void result_type; - - __host__ __device__ - device_generate_functor(Generator g) - : gen(g) {} - - // operator() does not take an lvalue reference because some iterators - // produce temporary proxy references when dereferenced. for example, - // consider the temporary tuple of references produced by zip_iterator. - // such temporaries cannot bind to an lvalue reference. - // - // to WAR this, accept a const reference (which is bindable to a temporary), - // and const_cast in the implementation. - // - // XXX change to an rvalue reference upon c++0x (which either a named variable - // or temporary can bind to) - template - __host__ __device__ - void operator()(const T &x) - { - // we have to be naughty and const_cast this to get it to work - T &lvalue = const_cast(x); - - // this assigns correctly whether x is a true reference or proxy - lvalue = gen(); - } - - Generator gen; -}; - -template - struct generate_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template - struct zipped_binary_op -{ - typedef ResultType result_type; - - __host__ __device__ - zipped_binary_op(BinaryFunction binary_op) - : m_binary_op(binary_op) {} - - template - __host__ __device__ - inline result_type operator()(Tuple t) - { - return m_binary_op(thrust::get<0>(t), thrust::get<1>(t)); - } - - BinaryFunction m_binary_op; -}; - - -template - struct is_non_const_reference - : thrust::detail::and_< - thrust::detail::not_ >, - thrust::detail::is_reference - > -{}; - -template struct is_tuple_of_iterator_references : thrust::detail::false_type {}; - -template - struct is_tuple_of_iterator_references< - thrust::detail::tuple_of_iterator_references< - T1,T2,T3,T4,T5,T6,T7,T8,T9,T10 - > - > - : thrust::detail::true_type -{}; - -// use this enable_if to avoid assigning to temporaries in the transform functors below -// XXX revisit this problem with c++11 perfect forwarding -template - struct enable_if_non_const_reference_or_tuple_of_iterator_references - : thrust::detail::enable_if< - is_non_const_reference::value || is_tuple_of_iterator_references::value - > -{}; - - -template - struct host_unary_transform_functor -{ - typedef void result_type; - - UnaryFunction f; - - host_unary_transform_functor(UnaryFunction f_) - :f(f_) {} - - template - inline __host__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<1,Tuple>::type - >::type - operator()(Tuple t) - { - thrust::get<1>(t) = f(thrust::get<0>(t)); - } -}; - -template - struct device_unary_transform_functor -{ - typedef void result_type; - - UnaryFunction f; - - device_unary_transform_functor(UnaryFunction f_) - :f(f_) {} - - // add __host__ to allow the omp backend compile with nvcc - template - inline __host__ __device__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<1,Tuple>::type - >::type - operator()(Tuple t) - { - thrust::get<1>(t) = f(thrust::get<0>(t)); - } -}; - - -template - struct unary_transform_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template - struct host_binary_transform_functor -{ - BinaryFunction f; - - host_binary_transform_functor(BinaryFunction f_) - :f(f_) - {} - - template - __host__ - void operator()(Tuple t) - { - thrust::get<2>(t) = f(thrust::get<0>(t), thrust::get<1>(t)); - } -}; // end binary_transform_functor - - -template - struct device_binary_transform_functor -{ - BinaryFunction f; - - device_binary_transform_functor(BinaryFunction f_) - :f(f_) - {} - - // add __host__ to allow the omp backend compile with nvcc - template - inline __host__ __device__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<2,Tuple>::type - >::type - operator()(Tuple t) - { - thrust::get<2>(t) = f(thrust::get<0>(t), thrust::get<1>(t)); - } -}; // end binary_transform_functor - - -template - struct binary_transform_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template -struct host_unary_transform_if_functor -{ - UnaryFunction unary_op; - Predicate pred; - - host_unary_transform_if_functor(UnaryFunction unary_op_, Predicate pred_) - : unary_op(unary_op_), pred(pred_) {} - - template - inline __host__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<1,Tuple>::type - >::type - operator()(Tuple t) - { - if(pred(thrust::get<0>(t))) - { - thrust::get<1>(t) = unary_op(thrust::get<0>(t)); - } - } -}; // end host_unary_transform_if_functor - - -template -struct device_unary_transform_if_functor -{ - UnaryFunction unary_op; - Predicate pred; - - device_unary_transform_if_functor(UnaryFunction unary_op_, Predicate pred_) - : unary_op(unary_op_), pred(pred_) {} - - template - inline __host__ __device__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<1,Tuple>::type - >::type - operator()(Tuple t) - { - if(pred(thrust::get<0>(t))) - { - thrust::get<1>(t) = unary_op(thrust::get<0>(t)); - } - } -}; // end device_unary_transform_if_functor - - -template - struct unary_transform_if_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template -struct host_unary_transform_if_with_stencil_functor -{ - UnaryFunction unary_op; - Predicate pred; - - host_unary_transform_if_with_stencil_functor(UnaryFunction _unary_op, Predicate _pred) - : unary_op(_unary_op), pred(_pred) {} - - template - inline __host__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<2,Tuple>::type - >::type - operator()(Tuple t) - { - if(pred(thrust::get<1>(t))) - thrust::get<2>(t) = unary_op(thrust::get<0>(t)); - } -}; // end host_unary_transform_if_with_stencil_functor - - -template -struct device_unary_transform_if_with_stencil_functor -{ - UnaryFunction unary_op; - Predicate pred; - - device_unary_transform_if_with_stencil_functor(UnaryFunction _unary_op, Predicate _pred) - : unary_op(_unary_op), pred(_pred) {} - - // add __host__ to allow the omp backend compile with nvcc - template - inline __host__ __device__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<2,Tuple>::type - >::type - operator()(Tuple t) - { - if(pred(thrust::get<1>(t))) - thrust::get<2>(t) = unary_op(thrust::get<0>(t)); - } -}; // end device_unary_transform_if_with_stencil_functor - - -template - struct unary_transform_if_with_stencil_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template -struct host_binary_transform_if_functor -{ - BinaryFunction binary_op; - Predicate pred; - - host_binary_transform_if_functor(BinaryFunction _binary_op, Predicate _pred) - : binary_op(_binary_op), pred(_pred) {} - - template - inline __host__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<3,Tuple>::type - >::type - operator()(Tuple t) - { - if(pred(thrust::get<2>(t))) - thrust::get<3>(t) = binary_op(thrust::get<0>(t), thrust::get<1>(t)); - } -}; // end host_binary_transform_if_functor - - -template -struct device_binary_transform_if_functor -{ - BinaryFunction binary_op; - Predicate pred; - - device_binary_transform_if_functor(BinaryFunction _binary_op, Predicate _pred) - : binary_op(_binary_op), pred(_pred) {} - - // add __host__ to allow the omp backend compile with nvcc - template - inline __host__ __device__ - typename enable_if_non_const_reference_or_tuple_of_iterator_references< - typename thrust::tuple_element<3,Tuple>::type - >::type - operator()(Tuple t) - { - if(pred(thrust::get<2>(t))) - thrust::get<3>(t) = binary_op(thrust::get<0>(t), thrust::get<1>(t)); - } -}; // end device_binary_transform_if_functor - - -template - struct binary_transform_if_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template - struct host_destroy_functor -{ - __host__ - void operator()(T &x) const - { - x.~T(); - } // end operator()() -}; // end host_destroy_functor - - -template - struct device_destroy_functor -{ - // add __host__ to allow the omp backend to compile with nvcc - __host__ __device__ - void operator()(T &x) const - { - x.~T(); - } // end operator()() -}; // end device_destroy_functor - - -template - struct destroy_functor - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - > -{}; - - -template -struct fill_functor -{ - const T exemplar; - - fill_functor(const T& _exemplar) - : exemplar(_exemplar) {} - - __host__ __device__ - T operator()(void) const - { - return exemplar; - } -}; - - -template - struct uninitialized_fill_functor -{ - T exemplar; - - uninitialized_fill_functor(T x):exemplar(x){} - - __host__ __device__ - void operator()(T &x) - { - ::new(static_cast(&x)) T(exemplar); - } // end operator()() -}; // end uninitialized_fill_functor - - -// this predicate tests two two-element tuples -// we first use a Compare for the first element -// if the first elements are equivalent, we use -// < for the second elements -template - struct compare_first_less_second -{ - compare_first_less_second(Compare c) - : comp(c) {} - - template - __host__ __device__ - bool operator()(T1 lhs, T2 rhs) - { - return comp(thrust::get<0>(lhs), thrust::get<0>(rhs)) || (!comp(thrust::get<0>(rhs), thrust::get<0>(lhs)) && thrust::get<1>(lhs) < thrust::get<1>(rhs)); - } - - Compare comp; -}; // end compare_first_less_second - - -template - struct compare_first -{ - Compare comp; - - compare_first(Compare comp) - : comp(comp) - {} - - template - __host__ __device__ - bool operator()(const Tuple1 &x, const Tuple2 &y) - { - return comp(thrust::raw_reference_cast(thrust::get<0>(x)), thrust::raw_reference_cast(thrust::get<0>(y))); - } -}; // end compare_first - - -} // end namespace detail -} // end namespace thrust - diff --git a/compat/thrust/detail/logical.inl b/compat/thrust/detail/logical.inl deleted file mode 100644 index 126a3e3..0000000 --- a/compat/thrust/detail/logical.inl +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file logical.inl - * \brief Inline file for logical.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -bool all_of(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::all_of; - return all_of(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end all_of() - - -template -bool any_of(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::any_of; - return any_of(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end any_of() - - -template -bool none_of(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::none_of; - return none_of(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end none_of() - - -template -bool all_of(InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::all_of(select_system(system), first, last, pred); -} - - -template -bool any_of(InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::any_of(select_system(system), first, last, pred); -} - - -template -bool none_of(InputIterator first, InputIterator last, Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::none_of(select_system(system), first, last, pred); -} - - -} // end namespace thrust - diff --git a/compat/thrust/detail/malloc_and_free.h b/compat/thrust/detail/malloc_and_free.h deleted file mode 100644 index 57b1685..0000000 --- a/compat/thrust/detail/malloc_and_free.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -template -pointer malloc(const thrust::detail::execution_policy_base &exec, std::size_t n) -{ - using thrust::system::detail::generic::malloc; - - // XXX should use a hypothetical thrust::static_pointer_cast here - void *raw_ptr = static_cast(thrust::raw_pointer_cast(malloc(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n))); - - return pointer(raw_ptr); -} - -template -pointer malloc(const thrust::detail::execution_policy_base &exec, std::size_t n) -{ - using thrust::system::detail::generic::malloc; - - T *raw_ptr = static_cast(thrust::raw_pointer_cast(malloc(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n))); - - return pointer(raw_ptr); -} - - -// XXX WAR nvbug 992955 -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC -#if CUDA_VERSION < 5000 - -// cudafe generates unqualified calls to free(int *volatile) -// which get confused with thrust::free -// spoof a thrust::free which simply maps to ::free -inline __host__ __device__ -void free(int *volatile ptr) -{ - ::free(ptr); -} - -#endif // CUDA_VERSION -#endif // THRUST_DEVICE_COMPILER - -template -void free(const thrust::detail::execution_policy_base &exec, Pointer ptr) -{ - using thrust::system::detail::generic::free; - - free(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), ptr); -} - -// XXX consider another form of free which does not take a system argument and -// instead infers the system from the pointer - -} // end namespace thrust - diff --git a/compat/thrust/detail/merge.inl b/compat/thrust/detail/merge.inl deleted file mode 100644 index 77f09f5..0000000 --- a/compat/thrust/detail/merge.inl +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file merge.inl - * \brief Inline file for merge.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator merge(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::merge; - return merge(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result); -} // end merge() - - -template - OutputIterator merge(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::merge; - return merge(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result, comp); -} // end merge() - - -template - thrust::pair - merge_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::merge_by_key; - return merge_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end merge_by_key() - - -template - thrust::pair - merge_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - Compare comp) -{ - using thrust::system::detail::generic::merge_by_key; - return merge_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end merge_by_key() - - -template - OutputIterator merge(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::merge(select_system(system1,system2,system3), first1, last1, first2, last2, result, comp); -} // end merge() - - -template - OutputIterator merge(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::merge(select_system(system1,system2,system3), first1, last1, first2, last2, result); -} // end merge() - - -template - thrust::pair - merge_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::merge_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end merge_by_key() - - -template - thrust::pair - merge_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::merge_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end merge_by_key() - - -} // end thrust - diff --git a/compat/thrust/detail/minmax.h b/compat/thrust/detail/minmax.h deleted file mode 100644 index a560ea1..0000000 --- a/compat/thrust/detail/minmax.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ - - -template -__host__ __device__ - T min THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs, BinaryPredicate comp) -{ - return comp(rhs, lhs) ? rhs : lhs; -} // end min() - -template -__host__ __device__ - T min THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs) -{ - return rhs < lhs ? rhs : lhs; -} // end min() - -template -__host__ __device__ - T max THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs, BinaryPredicate comp) -{ - return comp(lhs,rhs) ? rhs : lhs; -} // end max() - -template -__host__ __device__ - T max THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs) -{ - return lhs < rhs ? rhs : lhs; -} // end max() - - -} // end thrust - diff --git a/compat/thrust/detail/mismatch.inl b/compat/thrust/detail/mismatch.inl deleted file mode 100644 index 37ac663..0000000 --- a/compat/thrust/detail/mismatch.inl +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file mismatch.inl - * \brief Inline file for mismatch.h - */ - - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -thrust::pair mismatch(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2) -{ - using thrust::system::detail::generic::mismatch; - return mismatch(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2); -} // end mismatch() - - -template -thrust::pair mismatch(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - BinaryPredicate pred) -{ - using thrust::system::detail::generic::mismatch; - return mismatch(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, pred); -} // end mismatch() - - -template -thrust::pair mismatch(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::mismatch(select_system(system1,system2), first1, last1, first2); -} // end mismatch() - - -template -thrust::pair mismatch(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - BinaryPredicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::mismatch(select_system(system1,system2), first1, last1, first2, pred); -} // end mismatch() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/mpl/math.h b/compat/thrust/detail/mpl/math.h deleted file mode 100644 index 80adfc1..0000000 --- a/compat/thrust/detail/mpl/math.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file math.h - * \brief Math-related metaprogramming functionality. - */ - - -#pragma once - -namespace thrust -{ - -namespace detail -{ - -namespace mpl -{ - -namespace math -{ - -namespace detail -{ - -// compute the log base-2 of an integer at compile time -template -struct log2 -{ - static const unsigned int value = log2::value; -}; - -template -struct log2<1, Cur> -{ - static const unsigned int value = Cur; -}; - -template -struct log2<0, Cur> -{ - // undefined -}; - -} // end namespace detail - - -template -struct log2 -{ - static const unsigned int value = detail::log2::value; -}; - - -template -struct min -{ - static const T value = (lhs < rhs) ? lhs : rhs; -}; - - -template -struct max -{ - static const T value = (!(lhs < rhs)) ? lhs : rhs; -}; - - -template - struct mul -{ - static const result_type value = x * y; -}; - - -template - struct mod -{ - static const result_type value = x % y; -}; - - -template - struct div -{ - static const result_type value = x / y; -}; - - -template - struct geq -{ - static const bool value = x >= y; -}; - - -template - struct lt -{ - static const bool value = x < y; -}; - - -template - struct gt -{ - static const bool value = x > y; -}; - - -template - struct or_ -{ - static const bool value = (x || y); -}; - - -template - struct bit_and -{ - static const result_type value = x & y; -}; - - -template - struct plus -{ - static const result_type value = x + y; -}; - - -template - struct minus -{ - static const result_type value = x - y; -}; - - -template - struct equal -{ - static const bool value = x == y; -}; - - -template - struct is_odd -{ - static const bool value = x & 1; -}; - - -} // end namespace math - -} // end namespace mpl - -} // end namespace detail - -} // end namespace thrust - diff --git a/compat/thrust/detail/numeric_traits.h b/compat/thrust/detail/numeric_traits.h deleted file mode 100644 index a3bc56c..0000000 --- a/compat/thrust/detail/numeric_traits.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -//#include // for intmax_t (not provided on MSVS 2005) - -namespace thrust -{ - -namespace detail -{ - -// XXX good enough for the platforms we care about -typedef long long intmax_t; - -template - struct is_signed - : integral_constant::is_signed> -{}; // end is_signed - - -template - struct num_digits - : eval_if< - std::numeric_limits::is_specialized, - integral_constant< - int, - std::numeric_limits::digits - >, - integral_constant< - int, - sizeof(T) * std::numeric_limits::digits - (is_signed::value ? 1 : 0) - > - >::type -{}; // end num_digits - - -template - struct integer_difference - //: eval_if< - // sizeof(Integer) >= sizeof(intmax_t), - // eval_if< - // is_signed::value, - // identity_, - // identity_ - // >, - // eval_if< - // sizeof(Integer) < sizeof(std::ptrdiff_t), - // identity_, - // identity_ - // > - // > -{ - private: - // XXX workaround a pedantic warning in old versions of g++ - // which complains about &&ing with a constant value - template - struct and_ - { - static const bool value = false; - }; - - template - struct and_ - { - static const bool value = y; - }; - - public: - typedef typename - eval_if< - and_< - std::numeric_limits::is_signed, - // digits is the number of no-sign bits - (!std::numeric_limits::is_bounded || (int(std::numeric_limits::digits) + 1 >= num_digits::value)) - >::value, - identity_, - eval_if< - int(std::numeric_limits::digits) + 1 < num_digits::value, - identity_, - eval_if< - int(std::numeric_limits::digits) + 1 < num_digits::value, - identity_, - identity_ - > - > - >::type type; -}; // end integer_difference - - -template - struct numeric_difference - : eval_if< - is_integral::value, - integer_difference, - identity_ - > -{}; // end numeric_difference - - -template -__host__ __device__ -typename numeric_difference::type -numeric_distance(Number x, Number y) -{ - typedef typename numeric_difference::type difference_type; - return difference_type(y) - difference_type(x); -} // end numeric_distance - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/overlapped_copy.h b/compat/thrust/detail/overlapped_copy.h deleted file mode 100644 index a5540b8..0000000 --- a/compat/thrust/detail/overlapped_copy.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - OutputIterator sequential_copy(InputIterator first, - InputIterator last, - OutputIterator result) -{ - for(; first != last; ++first, ++result) - { - *result = *first; - } // end for - - return result; -} // end sequential_copy() - - -template - BidirectionalIterator2 sequential_copy_backward(BidirectionalIterator1 first, - BidirectionalIterator1 last, - BidirectionalIterator2 result) -{ - // yes, we preincrement - // the ranges are open on the right, i.e. [first, last) - while(first != last) - { - *--result = *--last; - } // end while - - return result; -} // end sequential_copy_backward() - - -namespace dispatch -{ - - -template - RandomAccessIterator2 overlapped_copy(thrust::system::cpp::detail::execution_policy &, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - RandomAccessIterator2 result) -{ - if(first < last && first <= result && result < last) - { - // result lies in [first, last) - // it's safe to use std::copy_backward here - thrust::detail::sequential_copy_backward(first, last, result + (last - first)); - result += (last - first); - } // end if - else - { - // result + (last - first) lies in [first, last) - // it's safe to use sequential_copy here - result = thrust::detail::sequential_copy(first, last, result); - } // end else - - return result; -} // end overlapped_copy() - - -template - RandomAccessIterator2 overlapped_copy(thrust::execution_policy &exec, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - RandomAccessIterator2 result) -{ - typedef typename thrust::iterator_value::type value_type; - - // make a temporary copy of [first,last), and copy into it first - thrust::detail::temporary_array temp(exec, first, last); - return thrust::copy(exec, temp.begin(), temp.end(), result); -} // end overlapped_copy() - -} // end dispatch - - -template - RandomAccessIterator2 overlapped_copy(RandomAccessIterator1 first, - RandomAccessIterator1 last, - RandomAccessIterator2 result) -{ - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - typedef typename thrust::detail::minimum_system::type System; - - // XXX presumes System is default constructible - System system; - - return thrust::detail::dispatch::overlapped_copy(system, first, last, result); -} // end overlapped_copy() - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/pair.inl b/compat/thrust/detail/pair.inl deleted file mode 100644 index 776bdc2..0000000 --- a/compat/thrust/detail/pair.inl +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace thrust -{ - -template - pair - ::pair(void) - :first(),second() -{ - ; -} // end pair::pair() - - -template - pair - ::pair(const T1 &x, const T2 &y) - :first(x),second(y) -{ - ; -} // end pair::pair() - - -template - template - pair - ::pair(const pair &p) - :first(p.first),second(p.second) -{ - ; -} // end pair::pair() - - -template - template - pair - ::pair(const std::pair &p) - :first(p.first),second(p.second) -{ - ; -} // end pair::pair() - - -template - inline __host__ __device__ - void pair - ::swap(thrust::pair &p) -{ - using thrust::swap; - - swap(first, p.first); - swap(second, p.second); -} // end pair::swap() - - -template - inline __host__ __device__ - bool operator==(const pair &x, const pair &y) -{ - return x.first == y.first && x.second == y.second; -} // end operator==() - - -template - inline __host__ __device__ - bool operator<(const pair &x, const pair &y) -{ - return x.first < y.first || (!(y.first < x.first) && x.second < y.second); -} // end operator<() - - -template - inline __host__ __device__ - bool operator!=(const pair &x, const pair &y) -{ - return !(x == y); -} // end operator==() - - -template - inline __host__ __device__ - bool operator>(const pair &x, const pair &y) -{ - return y < x; -} // end operator<() - - -template - inline __host__ __device__ - bool operator<=(const pair &x, const pair &y) -{ - return !(y < x); -} // end operator<=() - - -template - inline __host__ __device__ - bool operator>=(const pair &x, const pair &y) -{ - return !(x < y); -} // end operator>=() - - -template - inline __host__ __device__ - void swap(pair &x, pair &y) -{ - return x.swap(y); -} // end swap() - - -template - inline __host__ __device__ - pair make_pair(T1 x, T2 y) -{ - return pair(x,y); -} // end make_pair() - - -// specializations of tuple_element for pair -template - struct tuple_element<0, pair > -{ - typedef T1 type; -}; // end tuple_element - -template - struct tuple_element<1, pair > -{ - typedef T2 type; -}; // end tuple_element - - -// specialization of tuple_size for pair -template - struct tuple_size< pair > -{ - static const unsigned int value = 2; -}; // end tuple_size - - - -namespace detail -{ - - -template struct pair_get {}; - -template - struct pair_get<0, Pair> -{ - inline __host__ __device__ - const typename tuple_element<0, Pair>::type & - operator()(const Pair &p) const - { - return p.first; - } // end operator()() - - inline __host__ __device__ - typename tuple_element<0, Pair>::type & - operator()(Pair &p) const - { - return p.first; - } // end operator()() -}; // end pair_get - - -template - struct pair_get<1, Pair> -{ - inline __host__ __device__ - const typename tuple_element<1, Pair>::type & - operator()(const Pair &p) const - { - return p.second; - } // end operator()() - - inline __host__ __device__ - typename tuple_element<1, Pair>::type & - operator()(Pair &p) const - { - return p.second; - } // end operator()() -}; // end pair_get - -} // end detail - - - -template - inline __host__ __device__ - typename tuple_element >::type & - get(pair &p) -{ - return detail::pair_get >()(p); -} // end get() - -template - inline __host__ __device__ - const typename tuple_element >::type & - get(const pair &p) -{ - return detail::pair_get >()(p); -} // end get() - - -} // end thrust - diff --git a/compat/thrust/detail/partition.inl b/compat/thrust/detail/partition.inl deleted file mode 100644 index 19ef08a..0000000 --- a/compat/thrust/detail/partition.inl +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file partition.inl - * \brief Inline file for partition.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - ForwardIterator partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::partition; - return partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end partition() - - -template - ForwardIterator partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - using thrust::system::detail::generic::partition; - return partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred); -} // end partition() - - -template - thrust::pair - partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::partition_copy; - return partition_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, out_true, out_false, pred); -} // end partition_copy() - - -template - thrust::pair - partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::partition_copy; - return partition_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, out_true, out_false, pred); -} // end partition_copy() - - -template - ForwardIterator stable_partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::stable_partition; - return stable_partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end stable_partition() - - -template - ForwardIterator stable_partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - using thrust::system::detail::generic::stable_partition; - return stable_partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred); -} // end stable_partition() - - -template - thrust::pair - stable_partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::stable_partition_copy; - return stable_partition_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, out_true, out_false, pred); -} // end stable_partition_copy() - - -template - thrust::pair - stable_partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::stable_partition_copy; - return stable_partition_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, out_true, out_false, pred); -} // end stable_partition_copy() - - -template - ForwardIterator partition_point(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::partition_point; - return partition_point(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end partition_point() - - -template - bool is_partitioned(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::is_partitioned; - return is_partitioned(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end is_partitioned() - - -template - ForwardIterator partition(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::partition(select_system(system), first, last, pred); -} // end partition() - - -template - ForwardIterator partition(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::partition(select_system(system1,system2), first, last, stencil, pred); -} // end partition() - - -template - ForwardIterator stable_partition(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::stable_partition(select_system(system), first, last, pred); -} // end stable_partition() - - -template - ForwardIterator stable_partition(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::stable_partition(select_system(system1,system2), first, last, stencil, pred); -} // end stable_partition() - - -template - thrust::pair - partition_copy(InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::partition_copy(select_system(system1,system2,system3), first, last, out_true, out_false, pred); -} // end partition_copy() - - -template - thrust::pair - partition_copy(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::partition_copy(select_system(system1,system2,system3,system4), first, last, stencil, out_true, out_false, pred); -} // end partition_copy() - - -template - thrust::pair - stable_partition_copy(InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::stable_partition_copy(select_system(system1,system2,system3), first, last, out_true, out_false, pred); -} // end stable_partition_copy() - - -template - thrust::pair - stable_partition_copy(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::stable_partition_copy(select_system(system1,system2,system3,system4), first, last, stencil, out_true, out_false, pred); -} // end stable_partition_copy() - - -template - ForwardIterator partition_point(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::partition_point(select_system(system), first, last, pred); -} // end partition_point() - - -template - bool is_partitioned(InputIterator first, - InputIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::is_partitioned(select_system(system), first, last, pred); -} // end is_partitioned() - - -} // end thrust - diff --git a/compat/thrust/detail/pointer.h b/compat/thrust/detail/pointer.h deleted file mode 100644 index bc97939..0000000 --- a/compat/thrust/detail/pointer.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -// declare pointer with default values of template parameters -template class pointer; - -} // end thrust - - -// specialize std::iterator_traits to avoid problems with the name of -// pointer's constructor shadowing its nested pointer type -// do this before pointer is defined so the specialization is correctly -// used inside the definition -namespace std -{ - -template - struct iterator_traits > -{ - private: - typedef thrust::pointer ptr; - - public: - typedef typename ptr::iterator_category iterator_category; - typedef typename ptr::value_type value_type; - typedef typename ptr::difference_type difference_type; - // XXX implement this type (the result of operator->) later - typedef void pointer; - typedef typename ptr::reference reference; -}; // end iterator_traits - -} // end std - - -namespace thrust -{ - -namespace detail -{ - -// this metafunction computes the type of iterator_adaptor thrust::pointer should inherit from -template - struct pointer_base -{ - // void pointers should have no element type - // note that we remove_cv from the Element type to get the value_type - typedef typename thrust::detail::eval_if< - thrust::detail::is_void::type>::value, - thrust::detail::identity_, - thrust::detail::remove_cv - >::type value_type; - - // if no Derived type is given, just use pointer - typedef typename thrust::detail::eval_if< - thrust::detail::is_same::value, - thrust::detail::identity_ >, - thrust::detail::identity_ - >::type derived_type; - - // void pointers should have no reference type - // if no Reference type is given, just use reference - typedef typename thrust::detail::eval_if< - thrust::detail::is_void::type>::value, - thrust::detail::identity_, - thrust::detail::eval_if< - thrust::detail::is_same::value, - thrust::detail::identity_ >, - thrust::detail::identity_ - > - >::type reference_arg; - - typedef thrust::iterator_adaptor< - derived_type, // pass along the type of our Derived class to iterator_adaptor - Element *, // we adapt a raw pointer - value_type, // the value type - Tag, // system tag - thrust::random_access_traversal_tag, // pointers have random access traversal - reference_arg, // pass along our Reference type - std::ptrdiff_t - > type; -}; // end pointer_base - - -} // end detail - - -// the base type for all of thrust's tagged pointers. -// for reasonable pointer-like semantics, derived types should reimplement the following: -// 1. no-argument constructor -// 2. constructor from OtherElement * -// 3. constructor from OtherPointer related by convertibility -// 4. assignment from OtherPointer related by convertibility -// These should just call the corresponding members of pointer. -template - class pointer - : public thrust::detail::pointer_base::type -{ - private: - typedef typename thrust::detail::pointer_base::type super_t; - - typedef typename thrust::detail::pointer_base::derived_type derived_type; - - // friend iterator_core_access to give it access to dereference - friend class thrust::iterator_core_access; - - __host__ __device__ - typename super_t::reference dereference() const; - - // don't provide access to this part of super_t's interface - using super_t::base; - using typename super_t::base_type; - - public: - typedef typename super_t::base_type raw_pointer; - - // constructors - - __host__ __device__ - pointer(); - - // OtherValue shall be convertible to Value - // XXX consider making the pointer implementation a template parameter which defaults to Element * - template - __host__ __device__ - explicit pointer(OtherElement *ptr); - - // OtherPointer's element_type shall be convertible to Element - // OtherPointer's system shall be convertible to Tag - template - __host__ __device__ - pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type * = 0); - - // assignment - - // OtherPointer's element_type shall be convertible to Element - // OtherPointer's system shall be convertible to Tag - template - __host__ __device__ - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - derived_type & - >::type - operator=(const OtherPointer &other); - - // observers - - __host__ __device__ - Element *get() const; -}; // end pointer - -} // end thrust - -#include - diff --git a/compat/thrust/detail/pointer.inl b/compat/thrust/detail/pointer.inl deleted file mode 100644 index 1d066b0..0000000 --- a/compat/thrust/detail/pointer.inl +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - - -namespace thrust -{ - - -template - pointer - ::pointer() - : super_t(static_cast(0)) -{} // end pointer::pointer - - -template - template - pointer - ::pointer(OtherElement *other) - : super_t(other) -{} // end pointer::pointer - - -template - template - pointer - ::pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type *) - : super_t(thrust::detail::pointer_traits::get(other)) -{} // end pointer::pointer - - -template - template - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - typename pointer::derived_type & - >::type - pointer - ::operator=(const OtherPointer &other) -{ - super_t::base_reference() = thrust::detail::pointer_traits::get(other); - return static_cast(*this); -} // end pointer::operator= - - -template - typename pointer::super_t::reference - pointer - ::dereference() const -{ - return typename super_t::reference(static_cast(*this)); -} // end pointer::dereference - - -template - Element *pointer - ::get() const -{ - return super_t::base(); -} // end pointer::get - - -namespace detail -{ - -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400) -// XXX WAR MSVC 2005 problem with correctly implementing -// pointer_raw_pointer for pointer by specializing it here -template - struct pointer_raw_pointer< thrust::pointer > -{ - typedef typename pointer::raw_pointer type; -}; // end pointer_raw_pointer -#endif - - -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC) && (THRUST_GCC_VERSION < 40200) -// XXX WAR g++-4.1 problem with correctly implementing -// pointer_element for pointer by specializing it here -template - struct pointer_element< thrust::pointer > -{ - typedef Element type; -}; // end pointer_element - -template - struct pointer_element< thrust::pointer > - : pointer_element< thrust::pointer > -{}; // end pointer_element - -template - struct pointer_element< thrust::pointer > - : pointer_element< thrust::pointer > -{}; // end pointer_element - - - -// XXX WAR g++-4.1 problem with correctly implementing -// rebind_pointer for pointer by specializing it here -template - struct rebind_pointer, NewElement> -{ - // XXX note we don't attempt to rebind the pointer's Reference type (or Derived) - typedef thrust::pointer type; -}; - -template - struct rebind_pointer, NewElement> - : rebind_pointer, NewElement> -{}; - -template - struct rebind_pointer, NewElement> - : rebind_pointer, NewElement> -{}; -#endif - -} // end namespace detail - - -} // end thrust - diff --git a/compat/thrust/detail/range/tail_flags.h b/compat/thrust/detail/range/tail_flags.h deleted file mode 100644 index 06fd9f8..0000000 --- a/compat/thrust/detail/range/tail_flags.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template::type>, - typename IndexType = typename thrust::iterator_difference::type> - class tail_flags -{ - private: - struct tail_flag_functor - { - BinaryPredicate binary_pred; // this must be the first member for performance reasons - IndexType n; - - typedef bool result_type; - - tail_flag_functor(IndexType n) - : binary_pred(), n(n) - {} - - tail_flag_functor(IndexType n, BinaryPredicate binary_pred) - : binary_pred(binary_pred), n(n) - {} - - template - __host__ __device__ __thrust_forceinline__ - result_type operator()(const Tuple &t) - { - const IndexType i = thrust::get<0>(t); - - // note that we do not dereference the tuple's 2nd element when i >= n - // and therefore do not dereference a bad location at the boundary - return (i == (n - 1) || !binary_pred(thrust::get<1>(t), thrust::get<2>(t))); - } - }; - - typedef thrust::counting_iterator counting_iterator; - - public: - typedef thrust::transform_iterator< - tail_flag_functor, - thrust::zip_iterator > - > iterator; - - tail_flags(RandomAccessIterator first, RandomAccessIterator last) - : m_begin(thrust::make_transform_iterator(thrust::make_zip_iterator(thrust::make_tuple(thrust::counting_iterator(0), first, first + 1)), - tail_flag_functor(last - first))), - m_end(m_begin + (last - first)) - {} - - tail_flags(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred) - : m_begin(thrust::make_transform_iterator(thrust::make_zip_iterator(thrust::make_tuple(thrust::counting_iterator(0), first, first + 1)), - tail_flag_functor(last - first, binary_pred))), - m_end(m_begin + (last - first)) - {} - - iterator begin() const - { - return m_begin; - } - - iterator end() const - { - return m_end; - } - - template - typename iterator::reference operator[](OtherIndex i) - { - return *(begin() + i); - } - - private: - iterator m_begin, m_end; -}; - - -template - tail_flags - make_tail_flags(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred) -{ - return tail_flags(first, last, binary_pred); -} - - -template - tail_flags - make_tail_flags(RandomAccessIterator first, RandomAccessIterator last) -{ - return tail_flags(first, last); -} - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/raw_pointer_cast.h b/compat/thrust/detail/raw_pointer_cast.h deleted file mode 100644 index 05e1e6b..0000000 --- a/compat/thrust/detail/raw_pointer_cast.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -template - inline __host__ __device__ typename thrust::detail::pointer_traits::raw_pointer - raw_pointer_cast(const Pointer &ptr) -{ - return thrust::detail::pointer_traits::get(ptr); -} // end raw_pointer_cast() - -} // end thrust - diff --git a/compat/thrust/detail/raw_reference_cast.h b/compat/thrust/detail/raw_reference_cast.h deleted file mode 100644 index 1ffd7e5..0000000 --- a/compat/thrust/detail/raw_reference_cast.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -__THRUST_DEFINE_HAS_NESTED_TYPE(is_wrapped_reference, wrapped_reference_hint) - -namespace raw_reference_detail -{ - -template - struct raw_reference - : add_reference -{}; - - -// XXX consider making raw_reference an error - - -template - struct raw_reference< - T, - typename thrust::detail::enable_if< - is_wrapped_reference< - typename remove_cv::type - >::value - >::type - > -{ - typedef typename add_reference< - typename pointer_element::type - >::type type; -}; - -} // end raw_reference_ns - -template - struct raw_reference : - raw_reference_detail::raw_reference -{}; - - -// wrapped reference-like things which aren't strictly wrapped references -// (e.g. tuples of wrapped references) are considered unwrappable -template - struct is_unwrappable - : is_wrapped_reference -{}; - - -template - struct enable_if_unwrappable - : enable_if< - is_unwrappable::value, - Result - > -{}; - - -} // end detail - - -template - inline __host__ __device__ typename detail::raw_reference::type raw_reference_cast(T &ref) -{ - return *thrust::raw_pointer_cast(&ref); -} // end raw_reference_cast - - -template - inline __host__ __device__ typename detail::raw_reference::type raw_reference_cast(const T &ref) -{ - return *thrust::raw_pointer_cast(&ref); -} // end raw_reference_cast - - -template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> -inline __host__ __device__ -typename detail::enable_if_unwrappable< - thrust::detail::tuple_of_iterator_references, - typename detail::raw_reference< - thrust::detail::tuple_of_iterator_references - >::type ->::type -raw_reference_cast(detail::tuple_of_iterator_references t); - - -} // end thrust - -#include - diff --git a/compat/thrust/detail/raw_reference_cast.inl b/compat/thrust/detail/raw_reference_cast.inl deleted file mode 100644 index ea619ec..0000000 --- a/compat/thrust/detail/raw_reference_cast.inl +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -// specialize is_unwrappable -// a tuple is_unwrappable if any of its elements is_unwrappable -template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - struct is_unwrappable< - thrust::tuple - > - : or_< - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable - > -{}; - - -// specialize is_unwrappable -// a tuple_of_iterator_references is_unwrappable if any of its elements is_unwrappable -template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - struct is_unwrappable< - thrust::detail::tuple_of_iterator_references - > - : or_< - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable - > -{}; - - -namespace raw_reference_detail -{ - -// unlike raw_reference, -// raw_reference_tuple_helper needs to return a value -// when it encounters one, rather than a reference -// upon encountering tuple, recurse -// -// we want the following behavior: -// 1. T -> T -// 2. T& -> T& -// 3. null_type -> null_type -// 4. reference -> T& -// 5. tuple_of_iterator_references -> tuple_of_iterator_references::type> - - -// wrapped references are unwrapped using raw_reference, otherwise, return T -template - struct raw_reference_tuple_helper - : eval_if< - is_unwrappable< - typename remove_cv::type - >::value, - raw_reference, - identity_ - > -{}; - - -// recurse on tuples -template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - struct raw_reference_tuple_helper< - thrust::tuple - > -{ - typedef thrust::tuple< - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type - > type; -}; - - -template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - struct raw_reference_tuple_helper< - thrust::detail::tuple_of_iterator_references - > -{ - typedef thrust::detail::tuple_of_iterator_references< - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type - > type; -}; - - -} // end raw_reference_detail - - -// if a tuple "tuple_type" is_unwrappable, -// then the raw_reference of tuple_type is a tuple of its members' raw_references -// else the raw_reference of tuple_type is tuple_type & -template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - struct raw_reference< - thrust::tuple - > -{ - private: - typedef thrust::tuple tuple_type; - - public: - typedef typename eval_if< - is_unwrappable::value, - raw_reference_detail::raw_reference_tuple_helper, - add_reference - >::type type; -}; - - -template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - struct raw_reference< - thrust::detail::tuple_of_iterator_references - > -{ - private: - typedef detail::tuple_of_iterator_references tuple_type; - - public: - typedef typename raw_reference_detail::raw_reference_tuple_helper::type type; - - // XXX figure out why is_unwrappable seems to be broken for tuple_of_iterator_references - //typedef typename eval_if< - // is_unwrappable::value, - // raw_reference_detail::raw_reference_tuple_helper, - // add_reference - //>::type type; -}; - - -struct raw_reference_caster -{ - template - __host__ __device__ - typename detail::raw_reference::type operator()(T &ref) - { - return thrust::raw_reference_cast(ref); - } - - template - __host__ __device__ - typename detail::raw_reference::type operator()(const T &ref) - { - return thrust::raw_reference_cast(ref); - } - - template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 - > - __host__ __device__ - typename detail::raw_reference< - thrust::detail::tuple_of_iterator_references - >::type - operator()(thrust::detail::tuple_of_iterator_references t, - typename enable_if< - is_unwrappable >::value - >::type * = 0) - { - return thrust::raw_reference_cast(t); - } -}; // end raw_reference_caster - - -} // end detail - - -template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> -__host__ __device__ -typename detail::enable_if_unwrappable< - thrust::detail::tuple_of_iterator_references, - typename detail::raw_reference< - thrust::detail::tuple_of_iterator_references - >::type ->::type -raw_reference_cast(thrust::detail::tuple_of_iterator_references t) -{ - thrust::detail::raw_reference_caster f; - - // note that we pass raw_reference_tuple_helper, not raw_reference as the unary metafunction - // the subtle difference is important - return thrust::detail::tuple_host_device_transform(t, f); -} // end raw_reference_cast - - -} // end thrust - diff --git a/compat/thrust/detail/reduce.inl b/compat/thrust/detail/reduce.inl deleted file mode 100644 index ba84423..0000000 --- a/compat/thrust/detail/reduce.inl +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.inl - * \brief Inline file for reduce.h. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - typename thrust::iterator_traits::value_type - reduce(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last) -{ - using thrust::system::detail::generic::reduce; - return reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end reduce() - - -template - T reduce(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - T init) -{ - using thrust::system::detail::generic::reduce; - return reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init); -} // end reduce() - - -template - T reduce(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - T init, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::reduce; - return reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init, binary_op); -} // end reduce() - - -template - thrust::pair - reduce_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output) -{ - using thrust::system::detail::generic::reduce_by_key; - return reduce_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output); -} // end reduce_by_key() - - -template - thrust::pair - reduce_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::reduce_by_key; - return reduce_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output, binary_pred); -} // end reduce_by_key() - - -template - thrust::pair - reduce_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::reduce_by_key; - return reduce_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output, binary_pred, binary_op); -} // end reduce_by_key() - - -template -typename thrust::iterator_traits::value_type - reduce(InputIterator first, - InputIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::reduce(select_system(system), first, last); -} - -template - T reduce(InputIterator first, - InputIterator last, - T init) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::reduce(select_system(system), first, last, init); -} - - -template - T reduce(InputIterator first, - InputIterator last, - T init, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::reduce(select_system(system), first, last, init, binary_op); -} - -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::reduce_by_key(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output); -} - -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::reduce_by_key(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output, binary_pred); -} - -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::reduce_by_key(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output, binary_pred, binary_op); -} - -} // end namespace thrust - diff --git a/compat/thrust/detail/reference.h b/compat/thrust/detail/reference.h deleted file mode 100644 index 8c0b061..0000000 --- a/compat/thrust/detail/reference.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - - -namespace thrust -{ -namespace detail -{ - -template struct is_wrapped_reference; - -} - -// the base type for all of thrust's system-annotated references. -// for reasonable reference-like semantics, derived types must reimplement the following: -// 1. constructor from pointer -// 2. copy constructor -// 3. templated copy constructor from other reference -// 4. templated assignment from other reference -// 5. assignment from value_type -template - class reference -{ - private: - typedef typename thrust::detail::eval_if< - thrust::detail::is_same::value, - thrust::detail::identity_, - thrust::detail::identity_ - >::type derived_type; - - // hint for is_wrapped_reference lets it know that this type (or a derived type) - // is a wrapped reference - struct wrapped_reference_hint {}; - template friend struct thrust::detail::is_wrapped_reference; - - public: - typedef Pointer pointer; - typedef typename thrust::detail::remove_const::type value_type; - - __host__ __device__ - explicit reference(const pointer &ptr); - - template - __host__ __device__ - reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type * = 0); - - __host__ __device__ - derived_type &operator=(const reference &other); - - // XXX this may need an enable_if - template - __host__ __device__ - derived_type &operator=(const reference &other); - - __host__ __device__ - derived_type &operator=(const value_type &x); - - __host__ __device__ - pointer operator&() const; - - __host__ __device__ - operator value_type () const; - - __host__ __device__ - void swap(derived_type &other); - - derived_type &operator++(); - - value_type operator++(int); - - // XXX parameterize the type of rhs - derived_type &operator+=(const value_type &rhs); - - derived_type &operator--(); - - value_type operator--(int); - - // XXX parameterize the type of rhs - derived_type &operator-=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator*=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator/=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator%=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator<<=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator>>=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator&=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator|=(const value_type &rhs); - - // XXX parameterize the type of rhs - derived_type &operator^=(const value_type &rhs); - - private: - const pointer m_ptr; - - // allow access to m_ptr for other references - template friend class reference; - - template - __host__ __device__ - inline value_type strip_const_get_value(const System &system) const; - - template - __host__ __device__ - inline void assign_from(OtherPointer src); - - // XXX this helper exists only to avoid warnings about null references from the other assign_from - template - inline __host__ __device__ - void assign_from(System1 *system1, System2 *system2, OtherPointer src); - - template - __host__ __device__ - inline void strip_const_assign_value(const System &system, OtherPointer src); - - // XXX this helper exists only to avoid warnings about null references from the other swap - template - inline __host__ __device__ - void swap(System *system, derived_type &other); - - // XXX this helper exists only to avoid warnings about null references from operator value_type () - template - inline __host__ __device__ - value_type convert_to_value_type(System *system) const; -}; // end reference - - -} // end thrust - -#include - diff --git a/compat/thrust/detail/reference.inl b/compat/thrust/detail/reference.inl deleted file mode 100644 index 8b55edb..0000000 --- a/compat/thrust/detail/reference.inl +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace thrust -{ - - -template - template - reference - ::reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type *) - : m_ptr(other.m_ptr) -{} - - -template - reference - ::reference(const pointer &ptr) - : m_ptr(ptr) -{} - - -template - typename reference::pointer - reference - ::operator&() const -{ - return m_ptr; -} // end reference::operator&() - - -template - typename reference::derived_type & - reference - ::operator=(const value_type &v) -{ - assign_from(&v); - return static_cast(*this); -} // end reference::operator=() - - -template - typename reference::derived_type & - reference - ::operator=(const reference &other) -{ - assign_from(&other); - return static_cast(*this); -} // end reference::operator=() - - -template - template - typename reference::derived_type & - reference - ::operator=(const reference &other) -{ - assign_from(&other); - return static_cast(*this); -} // end reference::operator=() - - -template - template - typename reference::value_type - reference - ::convert_to_value_type(System *system) const -{ - using thrust::system::detail::generic::select_system; - return strip_const_get_value(select_system(*system)); -} // end convert_to_value_type() - - -template - reference - ::operator typename reference::value_type () const -{ - typedef typename thrust::iterator_system::type System; - - // XXX avoid default-constructing a system - // XXX use null a reference for dispatching - // XXX this assumes that the eventual invocation of - // XXX get_value will not access system state - System *system = 0; - - return convert_to_value_type(system); -} // end reference::operator value_type () - - -template - template - typename reference::value_type - reference - ::strip_const_get_value(const System &system) const -{ - System &non_const_system = const_cast(system); - - using thrust::system::detail::generic::get_value; - - return get_value(thrust::detail::derived_cast(non_const_system), m_ptr); -} // end reference::strip_const_get_value() - - -template - template - void reference - ::assign_from(System1 *system1, System2 *system2, OtherPointer src) -{ - using thrust::system::detail::generic::select_system; - - strip_const_assign_value(select_system(*system1, *system2), src); -} // end assign_from() - - -template - template - void reference - ::assign_from(OtherPointer src) -{ - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - // XXX avoid default-constructing a system - // XXX use null references for dispatching - // XXX this assumes that the eventual invocation of - // XXX assign_value will not access system state - System1 *system1 = 0; - System2 *system2 = 0; - - assign_from(system1, system2, src); -} // end assign_from() - - -template - template - void reference - ::strip_const_assign_value(const System &system, OtherPointer src) -{ - System &non_const_system = const_cast(system); - - using thrust::system::detail::generic::assign_value; - - assign_value(thrust::detail::derived_cast(non_const_system), m_ptr, src); -} // end strip_const_assign_value() - - -template - template - void reference - ::swap(System *system, derived_type &other) -{ - using thrust::system::detail::generic::select_system; - using thrust::system::detail::generic::iter_swap; - - iter_swap(select_system(*system, *system), m_ptr, other.m_ptr); -} // end reference::swap() - - -template - void reference - ::swap(derived_type &other) -{ - typedef typename thrust::iterator_system::type System; - - // XXX avoid default-constructing a system - // XXX use null references for dispatching - // XXX this assumes that the eventual invocation - // XXX of iter_swap will not access system state - System *system = 0; - - swap(system, other); -} // end reference::swap() - - -template - typename reference::derived_type & - reference - ::operator++(void) -{ - value_type temp = *this; - ++temp; - *this = temp; - return static_cast(*this); -} // end reference::operator++() - - -template - typename reference::value_type - reference - ::operator++(int) -{ - value_type temp = *this; - value_type result = temp++; - *this = temp; - return result; -} // end reference::operator++() - - -template - typename reference::derived_type & - reference - ::operator+=(const value_type &rhs) -{ - value_type temp = *this; - temp += rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator+=() - -template - typename reference::derived_type & - reference - ::operator--(void) -{ - value_type temp = *this; - --temp; - *this = temp; - return static_cast(*this); -} // end reference::operator--() - -template - typename reference::value_type - reference - ::operator--(int) -{ - value_type temp = *this; - value_type result = temp--; - *this = temp; - return result; -} // end reference::operator--() - -template - typename reference::derived_type & - reference - ::operator-=(const value_type &rhs) -{ - value_type temp = *this; - temp -= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator-=() - -template - typename reference::derived_type & - reference - ::operator*=(const value_type &rhs) -{ - value_type temp = *this; - temp *= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator*=() - -template - typename reference::derived_type & - reference - ::operator/=(const value_type &rhs) -{ - value_type temp = *this; - temp /= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator/=() - -template - typename reference::derived_type & - reference - ::operator%=(const value_type &rhs) -{ - value_type temp = *this; - temp %= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator%=() - -template - typename reference::derived_type & - reference - ::operator<<=(const value_type &rhs) -{ - value_type temp = *this; - temp <<= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator<<=() - -template - typename reference::derived_type & - reference - ::operator>>=(const value_type &rhs) -{ - value_type temp = *this; - temp >>= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator>>=() - -template - typename reference::derived_type & - reference - ::operator&=(const value_type &rhs) -{ - value_type temp = *this; - temp &= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator&=() - -template - typename reference::derived_type & - reference - ::operator|=(const value_type &rhs) -{ - value_type temp = *this; - temp |= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator|=() - -template - typename reference::derived_type & - reference - ::operator^=(const value_type &rhs) -{ - value_type temp = *this; - temp ^= rhs; - *this = temp; - return static_cast(*this); -} // end reference::operator^=() - - -} // end thrust - diff --git a/compat/thrust/detail/reference_forward_declaration.h b/compat/thrust/detail/reference_forward_declaration.h deleted file mode 100644 index 60524d3..0000000 --- a/compat/thrust/detail/reference_forward_declaration.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -template class reference; - -} // end thrust - diff --git a/compat/thrust/detail/remove.inl b/compat/thrust/detail/remove.inl deleted file mode 100644 index 5675243..0000000 --- a/compat/thrust/detail/remove.inl +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file remove.inl - * \brief Inline file for remove.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - ForwardIterator remove(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value) -{ - using thrust::system::detail::generic::remove; - return remove(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value); -} // end remove() - - -template - OutputIterator remove_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - const T &value) -{ - using thrust::system::detail::generic::remove_copy; - return remove_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, value); -} // end remove_copy() - - -template - ForwardIterator remove_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::remove_if; - return remove_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred); -} // end remove_if() - - -template - OutputIterator remove_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::remove_copy_if; - return remove_copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, pred); -} // end remove_copy_if() - - -template - ForwardIterator remove_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - using thrust::system::detail::generic::remove_if; - return remove_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred); -} // end remove_if() - - -template - OutputIterator remove_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::remove_copy_if; - return remove_copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, pred); -} // end remove_copy_if() - - -template - ForwardIterator remove(ForwardIterator first, - ForwardIterator last, - const T &value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::remove(select_system(system), first, last, value); -} // end remove() - - -template - OutputIterator remove_copy(InputIterator first, - InputIterator last, - OutputIterator result, - const T &value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::remove_copy(select_system(system1,system2), first, last, result, value); -} // end remove_copy() - - -template - ForwardIterator remove_if(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::remove_if(select_system(system), first, last, pred); -} // end remove_if() - - -template - ForwardIterator remove_if(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::remove_if(select_system(system1,system2), first, last, stencil, pred); -} // end remove_if() - - -template - OutputIterator remove_copy_if(InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::remove_copy_if(select_system(system1,system2), first, last, result, pred); -} // end remove_copy_if() - - -template - OutputIterator remove_copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::remove_copy_if(select_system(system1,system2,system3), first, last, stencil, result, pred); -} // end remove_copy_if() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/replace.inl b/compat/thrust/detail/replace.inl deleted file mode 100644 index 1eaf24d..0000000 --- a/compat/thrust/detail/replace.inl +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file replace.inl - * \brief Inline file for replace.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void replace(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, ForwardIterator last, - const T &old_value, - const T &new_value) -{ - using thrust::system::detail::generic::replace; - return replace(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, old_value, new_value); -} // end replace() - - -template - void replace_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, ForwardIterator last, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::replace_if; - return replace_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred, new_value); -} // end replace_if() - - -template - void replace_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, ForwardIterator last, - InputIterator stencil, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::replace_if; - return replace_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred, new_value); -} // end replace_if() - - -template - OutputIterator replace_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - const T &old_value, - const T &new_value) -{ - using thrust::system::detail::generic::replace_copy; - return replace_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, old_value, new_value); -} // end replace_copy() - - -template - OutputIterator replace_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::replace_copy_if; - return replace_copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, pred, new_value); -} // end replace_copy_if() - - -template - OutputIterator replace_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::replace_copy_if; - return replace_copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, pred, new_value); -} // end replace_copy_if() - - -template - OutputIterator replace_copy_if(InputIterator first, InputIterator last, - OutputIterator result, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::replace_copy_if(select_system(system1,system2), first, last, result, pred, new_value); -} // end replace_copy_if() - - -template - OutputIterator replace_copy_if(InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::replace_copy_if(select_system(system1,system2,system3), first, last, stencil, result, pred, new_value); -} // end replace_copy_if() - - -template - OutputIterator replace_copy(InputIterator first, InputIterator last, - OutputIterator result, - const T &old_value, - const T &new_value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::replace_copy(select_system(system1,system2), first, last, result, old_value, new_value); -} // end replace_copy() - - -template - void replace_if(ForwardIterator first, ForwardIterator last, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::replace_if(select_system(system), first, last, pred, new_value); -} // end replace_if() - - -template - void replace_if(ForwardIterator first, ForwardIterator last, - InputIterator stencil, - Predicate pred, - const T &new_value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::replace_if(select_system(system1,system2), first, last, stencil, pred, new_value); -} // end replace_if() - - -template - void replace(ForwardIterator first, ForwardIterator last, - const T &old_value, - const T &new_value) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::replace(select_system(system), first, last, old_value, new_value); -} // end replace() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/reverse.inl b/compat/thrust/detail/reverse.inl deleted file mode 100644 index 18c26c0..0000000 --- a/compat/thrust/detail/reverse.inl +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reverse.inl - * \brief Inline file for reverse.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void reverse(const thrust::detail::execution_policy_base &exec, - BidirectionalIterator first, - BidirectionalIterator last) -{ - using thrust::system::detail::generic::reverse; - return reverse(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end reverse() - - -template - OutputIterator reverse_copy(const thrust::detail::execution_policy_base &exec, - BidirectionalIterator first, - BidirectionalIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::reverse_copy; - return reverse_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result); -} // end reverse_copy() - - -template - void reverse(BidirectionalIterator first, - BidirectionalIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::reverse(select_system(system), first, last); -} // end reverse() - - -template - OutputIterator reverse_copy(BidirectionalIterator first, - BidirectionalIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::reverse_copy(select_system(system1,system2), first, last, result); -} // end reverse_copy() - - -} // end thrust - diff --git a/compat/thrust/detail/scan.inl b/compat/thrust/detail/scan.inl deleted file mode 100644 index 3e5fd9b..0000000 --- a/compat/thrust/detail/scan.inl +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.inl - * \brief Inline file for scan.h. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator inclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::inclusive_scan; - return inclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result); -} // end inclusive_scan() - - -template - OutputIterator inclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::inclusive_scan; - return inclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, binary_op); -} // end inclusive_scan() - - -template - OutputIterator exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::exclusive_scan; - return exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result); -} // end exclusive_scan() - - -template - OutputIterator exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init) -{ - using thrust::system::detail::generic::exclusive_scan; - return exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, init); -} // end exclusive_scan() - - -template - OutputIterator exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::exclusive_scan; - return exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, init, binary_op); -} // end exclusive_scan() - - -template - OutputIterator inclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result) -{ - using thrust::system::detail::generic::inclusive_scan_by_key; - return inclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result); -} // end inclusive_scan_by_key() - - -template - OutputIterator inclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::inclusive_scan_by_key; - return inclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, binary_pred); -} // end inclusive_scan_by_key() - - -template - OutputIterator inclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::inclusive_scan_by_key; - return inclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, binary_pred, binary_op); -} // end inclusive_scan_by_key() - - -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result) -{ - using thrust::system::detail::generic::exclusive_scan_by_key; - return exclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result); -} // end exclusive_scan_by_key() - - -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init) -{ - using thrust::system::detail::generic::exclusive_scan_by_key; - return exclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, init); -} // end exclusive_scan_by_key() - - -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::exclusive_scan_by_key; - return exclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, init, binary_pred); -} // end exclusive_scan_by_key() - - -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::exclusive_scan_by_key; - return exclusive_scan_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, init, binary_pred, binary_op); -} // end exclusive_scan_by_key() - - -template - OutputIterator inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::inclusive_scan(select_system(system1,system2), first, last, result); -} // end inclusive_scan() - - -template - OutputIterator inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::inclusive_scan(select_system(system1,system2), first, last, result, binary_op); -} // end inclusive_scan() - - -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::exclusive_scan(select_system(system1,system2), first, last, result); -} // end exclusive_scan() - - -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - T init) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::exclusive_scan(select_system(system1,system2), first, last, result, init); -} // end exclusive_scan() - - -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::exclusive_scan(select_system(system1,system2), first, last, result, init, binary_op); -} // end exclusive_scan() - - -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::inclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result); -} - - -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::inclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result, binary_pred); -} - - -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::inclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result, binary_pred, binary_op); -} - - -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::exclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result); -} - - -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::exclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result, init); -} - - -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::exclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result, init, binary_pred); -} - - -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::exclusive_scan_by_key(select_system(system1,system2,system3), first1, last1, first2, result, init, binary_pred, binary_op); -} - - -} // end namespace thrust - diff --git a/compat/thrust/detail/scatter.inl b/compat/thrust/detail/scatter.inl deleted file mode 100644 index 934addb..0000000 --- a/compat/thrust/detail/scatter.inl +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scatter.inl - * \brief Inline file for scatter.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void scatter(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - RandomAccessIterator output) -{ - using thrust::system::detail::generic::scatter; - return scatter(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, map, output); -} // end scatter() - - -template - void scatter_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output) -{ - using thrust::system::detail::generic::scatter_if; - return scatter_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, map, stencil, output); -} // end scatter_if() - - -template - void scatter_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output, - Predicate pred) -{ - using thrust::system::detail::generic::scatter_if; - return scatter_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, map, stencil, output, pred); -} // end scatter_if() - - -template - void scatter(InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - RandomAccessIterator output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::scatter(select_system(system1,system2,system3), first, last, map, output); -} // end scatter() - - -template - void scatter_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::scatter_if(select_system(system1,system2,system3,system4), first, last, map, stencil, output); -} // end scatter_if() - - -template - void scatter_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::scatter_if(select_system(system1,system2,system3,system4), first, last, map, stencil, output, pred); -} // end scatter_if() - -} // end namespace thrust - diff --git a/compat/thrust/detail/sequence.inl b/compat/thrust/detail/sequence.inl deleted file mode 100644 index f174187..0000000 --- a/compat/thrust/detail/sequence.inl +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file sequence.inl - * \brief Inline file for sequence.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void sequence(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::sequence; - return sequence(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end sequence() - - -template - void sequence(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - T init) -{ - using thrust::system::detail::generic::sequence; - return sequence(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init); -} // end sequence() - - -template - void sequence(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - T init, - T step) -{ - using thrust::system::detail::generic::sequence; - return sequence(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init, step); -} // end sequence() - - -template - void sequence(ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::sequence(select_system(system), first, last); -} // end sequence() - - -template - void sequence(ForwardIterator first, - ForwardIterator last, - T init) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::sequence(select_system(system), first, last, init); -} // end sequence() - - -template - void sequence(ForwardIterator first, - ForwardIterator last, - T init, - T step) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::sequence(select_system(system), first, last, init, step); -} // end sequence() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/set_operations.inl b/compat/thrust/detail/set_operations.inl deleted file mode 100644 index daec461..0000000 --- a/compat/thrust/detail/set_operations.inl +++ /dev/null @@ -1,836 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file set_operations.inl - * \brief Inline file for set_operations.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator set_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::set_difference; - return set_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result); -} // end set_difference() - - -template - OutputIterator set_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_difference; - return set_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result, comp); -} // end set_difference() - - -template - thrust::pair - set_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::set_difference_by_key; - return set_difference_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end set_difference_by_key() - - -template - thrust::pair - set_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_difference_by_key; - return set_difference_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end set_difference_by_key() - - -template - OutputIterator set_intersection(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::set_intersection; - return set_intersection(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result); -} // end set_intersection() - - -template - OutputIterator set_intersection(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_intersection; - return set_intersection(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result, comp); -} // end set_intersection() - - -template - thrust::pair - set_intersection_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::set_intersection_by_key; - return set_intersection_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, keys_result, values_result); -} // end set_intersection_by_key() - - -template - thrust::pair - set_intersection_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_intersection_by_key; - return set_intersection_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, keys_result, values_result, comp); -} // end set_intersection_by_key() - - -template - OutputIterator set_symmetric_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::set_symmetric_difference; - return set_symmetric_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result); -} // end set_symmetric_difference() - - -template - OutputIterator set_symmetric_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_symmetric_difference; - return set_symmetric_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result, comp); -} // end set_symmetric_difference() - - -template - thrust::pair - set_symmetric_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::set_symmetric_difference_by_key; - return set_symmetric_difference_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end set_symmetric_difference_by_key() - - -template - thrust::pair - set_symmetric_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_symmetric_difference_by_key; - return set_symmetric_difference_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end set_symmetric_difference_by_key() - - -template - OutputIterator set_union(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::set_union; - return set_union(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result); -} // end set_union() - - -template - OutputIterator set_union(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_union; - return set_union(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result, comp); -} // end set_union() - - -template - thrust::pair - set_union_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::set_union_by_key; - return set_union_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end set_union_by_key() - - -template - thrust::pair - set_union_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp) -{ - using thrust::system::detail::generic::set_union_by_key; - return set_union_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end set_union_by_key() - - -template - OutputIterator set_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_difference(select_system(system1,system2,system3), first1, last1, first2, last2, result, comp); -} // end set_difference() - - -template - OutputIterator set_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_difference(select_system(system1,system2,system3), first1, last1, first2, last2, result); -} // end set_difference() - - -template - thrust::pair - set_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::set_difference_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end set_difference_by_key() - - -template - thrust::pair - set_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::set_difference_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end set_difference_by_key() - - -template - OutputIterator set_intersection(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_intersection(select_system(system1,system2,system3), first1, last1, first2, last2, result, comp); -} // end set_intersection() - - -template - OutputIterator set_intersection(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_intersection(select_system(system1,system2,system3), first1, last1, first2, last2, result); -} // end set_intersection() - - -template - thrust::pair - set_intersection_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - - return thrust::set_intersection_by_key(select_system(system1,system2,system3,system4,system5), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, keys_result, values_result, comp); -} // end set_intersection_by_key() - - -template - thrust::pair - set_intersection_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - - return thrust::set_intersection_by_key(select_system(system1,system2,system3,system4,system5), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, keys_result, values_result); -} // end set_intersection_by_key() - - -template - OutputIterator set_symmetric_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_symmetric_difference(select_system(system1,system2,system3), first1, last1, first2, last2, result, comp); -} // end set_symmetric_difference() - - -template - OutputIterator set_symmetric_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_symmetric_difference(select_system(system1,system2,system3), first1, last1, first2, last2, result); -} // end set_symmetric_difference() - - -template - thrust::pair - set_symmetric_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::set_symmetric_difference_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end set_symmetric_difference_by_key() - - -template - thrust::pair - set_symmetric_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::set_symmetric_difference_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end set_symmetric_difference_by_key() - - -template - OutputIterator set_union(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_union(select_system(system1,system2,system3), first1, last1, first2, last2, result, comp); -} // end set_union() - - -template - OutputIterator set_union(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::set_union(select_system(system1,system2,system3), first1, last1, first2, last2, result); -} // end set_union() - - -template - thrust::pair - set_union_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::set_union_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} // end set_union_by_key() - - -template - thrust::pair - set_union_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - typedef typename thrust::iterator_system::type System5; - typedef typename thrust::iterator_system::type System6; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - System5 system5; - System6 system6; - - return thrust::set_union_by_key(select_system(system1,system2,system3,system4,system5,system6), keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result); -} // end set_union_by_key() - - -} // end thrust - diff --git a/compat/thrust/detail/sort.inl b/compat/thrust/detail/sort.inl deleted file mode 100644 index 08be55a..0000000 --- a/compat/thrust/detail/sort.inl +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file sort.inl - * \brief Inline file for sort.h. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - using thrust::system::detail::generic::sort; - return sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end sort() - - -template - void sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::sort; - return sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end sort() - - -template - void stable_sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - using thrust::system::detail::generic::stable_sort; - return stable_sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end stable_sort() - - -template - void stable_sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::stable_sort; - return stable_sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end stable_sort() - - -template - void sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - using thrust::system::detail::generic::sort_by_key; - return sort_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first); -} // end sort_by_key() - - -template - void sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::sort_by_key; - return sort_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, comp); -} // end sort_by_key() - - -template - void stable_sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - using thrust::system::detail::generic::stable_sort_by_key; - return stable_sort_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first); -} // end stable_sort_by_key() - - -template - void stable_sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::stable_sort_by_key; - return stable_sort_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, comp); -} // end stable_sort_by_key() - - -template - bool is_sorted(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::is_sorted; - return is_sorted(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end is_sorted() - - -template - bool is_sorted(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp) -{ - using thrust::system::detail::generic::is_sorted; - return is_sorted(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end is_sorted() - - -template - ForwardIterator is_sorted_until(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::is_sorted_until; - return is_sorted_until(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end is_sorted_until() - - -template - ForwardIterator is_sorted_until(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp) -{ - using thrust::system::detail::generic::is_sorted_until; - return is_sorted_until(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp); -} // end is_sorted_until() - - -/////////////// -// Key Sorts // -/////////////// - -template - void sort(RandomAccessIterator first, - RandomAccessIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::sort(select_system(system), first, last); -} // end sort() - - -template - void sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::sort(select_system(system), first, last, comp); -} // end sort() - - -template - void stable_sort(RandomAccessIterator first, - RandomAccessIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::stable_sort(select_system(system), first, last); -} // end stable_sort() - - -template - void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::stable_sort(select_system(system), first, last, comp); -} // end stable_sort() - - - -///////////////////// -// Key-Value Sorts // -///////////////////// - -template - void sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::sort_by_key(select_system(system1,system2), keys_first, keys_last, values_first); -} // end sort_by_key() - - -template - void sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::sort_by_key(select_system(system1,system2), keys_first, keys_last, values_first, comp); -} // end sort_by_key() - - -template - void stable_sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::stable_sort_by_key(select_system(system1,system2), keys_first, keys_last, values_first); -} // end stable_sort_by_key() - - -template - void stable_sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::stable_sort_by_key(select_system(system1,system2), keys_first, keys_last, values_first, comp); -} // end stable_sort_by_key() - - -template - bool is_sorted(ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::is_sorted(select_system(system), first, last); -} // end is_sorted() - - -template - bool is_sorted(ForwardIterator first, - ForwardIterator last, - Compare comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::is_sorted(select_system(system), first, last, comp); -} // end is_sorted() - - -template - ForwardIterator is_sorted_until(ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::is_sorted_until(select_system(system), first, last); -} // end is_sorted_until() - - -template - ForwardIterator is_sorted_until(ForwardIterator first, - ForwardIterator last, - Compare comp) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::is_sorted_until(select_system(system), first, last, comp); -} // end is_sorted_until() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/static_assert.h b/compat/thrust/detail/static_assert.h deleted file mode 100644 index ccc0842..0000000 --- a/compat/thrust/detail/static_assert.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -/* - * (C) Copyright John Maddock 2000. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -// -// Helper macro THRUST_JOIN (based on BOOST_JOIN): -// The following piece of macro magic joins the two -// arguments together, even when one of the arguments is -// itself a macro (see 16.3.1 in C++ standard). The key -// is that macro expansion of macro arguments does not -// occur in THRUST_DO_JOIN2 but does in THRUST_DO_JOIN. -// -#define THRUST_JOIN( X, Y ) THRUST_DO_JOIN( X, Y ) -#define THRUST_DO_JOIN( X, Y ) THRUST_DO_JOIN2(X,Y) -#define THRUST_DO_JOIN2( X, Y ) X##Y - -namespace thrust -{ - -namespace detail -{ - -// HP aCC cannot deal with missing names for template value parameters -template struct STATIC_ASSERTION_FAILURE; - -template <> struct STATIC_ASSERTION_FAILURE { enum { value = 1 }; }; - -// HP aCC cannot deal with missing names for template value parameters -template struct static_assert_test{}; - -template - struct depend_on_instantiation -{ - static const bool value = x; -}; - -} // end detail - -} // end thrust - -#define THRUST_STATIC_ASSERT( B ) \ - typedef ::thrust::detail::static_assert_test<\ - sizeof(::thrust::detail::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\ - THRUST_JOIN(thrust_static_assert_typedef_, __LINE__) - diff --git a/compat/thrust/detail/swap.h b/compat/thrust/detail/swap.h deleted file mode 100644 index 9f82ac2..0000000 --- a/compat/thrust/detail/swap.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -namespace thrust -{ - -template -__host__ __device__ -inline void swap(Assignable1 &a, Assignable2 &b) -{ - Assignable1 temp = a; - a = b; - b = temp; -} // end swap() - -} // end namespace thrust - diff --git a/compat/thrust/detail/swap.inl b/compat/thrust/detail/swap.inl deleted file mode 100644 index eafd70a..0000000 --- a/compat/thrust/detail/swap.inl +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - diff --git a/compat/thrust/detail/swap_ranges.inl b/compat/thrust/detail/swap_ranges.inl deleted file mode 100644 index e3b06de..0000000 --- a/compat/thrust/detail/swap_ranges.inl +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file swap_ranges.inl - * \brief Inline file for swap_ranges.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - ForwardIterator2 swap_ranges(const thrust::detail::execution_policy_base &exec, - ForwardIterator1 first1, - ForwardIterator1 last1, - ForwardIterator2 first2) -{ - using thrust::system::detail::generic::swap_ranges; - return swap_ranges(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2); -} // end swap_ranges() - - -template - ForwardIterator2 swap_ranges(ForwardIterator1 first1, - ForwardIterator1 last1, - ForwardIterator2 first2) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::swap_ranges(select_system(system1,system2), first1, last1, first2); -} // end swap_ranges() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/tabulate.inl b/compat/thrust/detail/tabulate.inl deleted file mode 100644 index 961c76e..0000000 --- a/compat/thrust/detail/tabulate.inl +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void tabulate(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - UnaryOperation unary_op) -{ - using thrust::system::detail::generic::tabulate; - return tabulate(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, unary_op); -} // end tabulate() - - -template - void tabulate(ForwardIterator first, - ForwardIterator last, - UnaryOperation unary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::tabulate(select_system(system), first, last, unary_op); -} // end tabulate() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/temporary_array.h b/compat/thrust/detail/temporary_array.h deleted file mode 100644 index 3a9e084..0000000 --- a/compat/thrust/detail/temporary_array.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file temporary_array.h - * \brief Container-like class temporary storage inside algorithms. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - class temporary_array - : public contiguous_storage< - T, - no_throw_allocator< - temporary_allocator - > - > -{ - private: - typedef contiguous_storage< - T, - no_throw_allocator< - temporary_allocator - > - > super_t; - - // to help out the constructor - typedef no_throw_allocator > alloc_type; - - public: - typedef typename super_t::size_type size_type; - - temporary_array(thrust::execution_policy &system, size_type n); - - // provide a kill-switch to explicitly avoid initialization - temporary_array(int uninit, thrust::execution_policy &system, size_type n); - - template - temporary_array(thrust::execution_policy &system, - InputIterator first, - size_type n); - - template - temporary_array(thrust::execution_policy &system, - thrust::execution_policy &input_system, - InputIterator first, - size_type n); - - template - temporary_array(thrust::execution_policy &system, - InputIterator first, - InputIterator last); - - template - temporary_array(thrust::execution_policy &system, - thrust::execution_policy &input_system, - InputIterator first, - InputIterator last); - - ~temporary_array(); -}; // end temporary_array - - -// XXX eliminate this when we do ranges for real -template - class tagged_iterator_range -{ - public: - typedef thrust::detail::tagged_iterator iterator; - - template - tagged_iterator_range(const Ignored1 &, const Ignored2 &, Iterator first, Iterator last) - : m_begin(reinterpret_tag(first)), - m_end(reinterpret_tag(last)) - {} - - iterator begin(void) const { return m_begin; } - iterator end(void) const { return m_end; } - - private: - iterator m_begin, m_end; -}; - - -// if FromSystem is convertible to ToSystem, then just make a shallow -// copy of the range. else, use a temporary_array -// note that the resulting iterator is explicitly tagged with ToSystem either way -template - struct move_to_system_base - : public eval_if< - is_convertible< - FromSystem, - ToSystem - >::value, - identity_< - tagged_iterator_range - >, - identity_< - temporary_array< - typename thrust::iterator_value::type, - ToSystem - > - > - > -{}; - - -template - class move_to_system - : public move_to_system_base< - Iterator, - FromSystem, - ToSystem - >::type -{ - typedef typename move_to_system_base::type super_t; - - public: - move_to_system(thrust::execution_policy &from_system, - thrust::execution_policy &to_system, - Iterator first, - Iterator last) - : super_t(to_system, from_system, first, last) {} -}; - - -} // end detail -} // end thrust - -#include - diff --git a/compat/thrust/detail/temporary_array.inl b/compat/thrust/detail/temporary_array.inl deleted file mode 100644 index 36ed167..0000000 --- a/compat/thrust/detail/temporary_array.inl +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - - -namespace thrust -{ - -namespace detail -{ -namespace temporary_array_detail -{ - - -template struct avoid_initialization : thrust::detail::has_trivial_copy_constructor {}; - - -template -typename thrust::detail::enable_if< - avoid_initialization::value ->::type - construct_values(TemporaryArray &, - Size) -{ - // avoid the overhead of initialization -} // end construct_values() - - -template -typename thrust::detail::disable_if< - avoid_initialization::value ->::type - construct_values(TemporaryArray &a, - Size n) -{ - a.default_construct_n(a.begin(), n); -} // end construct_values() - - -} // end temporary_array_detail - - -template - temporary_array - ::temporary_array(thrust::execution_policy &system, size_type n) - :super_t(n, alloc_type(temporary_allocator(system))) -{ - temporary_array_detail::construct_values(*this, n); -} // end temporary_array::temporary_array() - - -template - temporary_array - ::temporary_array(int, thrust::execution_policy &system, size_type n) - :super_t(n, alloc_type(temporary_allocator(system))) -{ - // avoid initialization - ; -} // end temporary_array::temporary_array() - - -template - template - temporary_array - ::temporary_array(thrust::execution_policy &system, - InputIterator first, - size_type n) - : super_t(alloc_type(temporary_allocator(system))) -{ - super_t::allocate(n); - - super_t::uninitialized_copy_n(system, first, n, super_t::begin()); -} // end temporary_array::temporary_array() - - -template - template - temporary_array - ::temporary_array(thrust::execution_policy &system, - thrust::execution_policy &input_system, - InputIterator first, - size_type n) - : super_t(alloc_type(temporary_allocator(system))) -{ - super_t::allocate(n); - - super_t::uninitialized_copy_n(input_system, first, n, super_t::begin()); -} // end temporary_array::temporary_array() - - -template - template - temporary_array - ::temporary_array(thrust::execution_policy &system, - InputIterator first, - InputIterator last) - : super_t(alloc_type(temporary_allocator(system))) -{ - super_t::allocate(thrust::distance(first,last)); - - super_t::uninitialized_copy(system, first, last, super_t::begin()); -} // end temporary_array::temporary_array() - - -template - template - temporary_array - ::temporary_array(thrust::execution_policy &system, - thrust::execution_policy &input_system, - InputIterator first, - InputIterator last) - : super_t(alloc_type(temporary_allocator(system))) -{ - super_t::allocate(thrust::distance(first,last)); - - super_t::uninitialized_copy(input_system, first, last, super_t::begin()); -} // end temporary_array::temporary_array() - - -template - temporary_array - ::~temporary_array() -{ - // note that super_t::destroy will ignore trivial destructors automatically - super_t::destroy(super_t::begin(), super_t::end()); -} // end temporary_array::~temporary_array() - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/temporary_buffer.h b/compat/thrust/detail/temporary_buffer.h deleted file mode 100644 index 046a3b3..0000000 --- a/compat/thrust/detail/temporary_buffer.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ -namespace get_temporary_buffer_detail -{ - - -template - thrust::pair, typename thrust::pointer::difference_type> - down_cast_pair(Pair p) -{ - // XXX should use a hypothetical thrust::static_pointer_cast here - thrust::pointer ptr = thrust::pointer(static_cast(thrust::raw_pointer_cast(p.first))); - - typedef thrust::pair, typename thrust::pointer::difference_type> result_type; - return result_type(ptr, p.second); -} // end down_cast_pair() - - -} // end get_temporary_buffer_detail -} // end detail - - -template - thrust::pair, typename thrust::pointer::difference_type> - get_temporary_buffer(const thrust::detail::execution_policy_base &exec, typename thrust::pointer::difference_type n) -{ - using thrust::system::detail::generic::get_temporary_buffer; - - return thrust::detail::get_temporary_buffer_detail::down_cast_pair(get_temporary_buffer(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n)); -} // end get_temporary_buffer() - - -template - void return_temporary_buffer(const thrust::detail::execution_policy_base &exec, Pointer p) -{ - using thrust::system::detail::generic::return_temporary_buffer; - - return return_temporary_buffer(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), p); -} // end return_temporary_buffer() - - -} // end thrust - diff --git a/compat/thrust/detail/transform.inl b/compat/thrust/detail/transform.inl deleted file mode 100644 index ae303bc..0000000 --- a/compat/thrust/detail/transform.inl +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file transform.inl - * \brief Inline file for transform.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator transform(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - UnaryFunction op) -{ - using thrust::system::detail::generic::transform; - return transform(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, op); -} // end transform() - - -template - OutputIterator transform(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryFunction op) -{ - using thrust::system::detail::generic::transform; - return transform(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, op); -} // end transform() - - -template - ForwardIterator transform_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - ForwardIterator result, - UnaryFunction op, - Predicate pred) -{ - using thrust::system::detail::generic::transform_if; - return transform_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, op, pred); -} // end transform_if() - - -template - ForwardIterator transform_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - ForwardIterator result, - UnaryFunction op, - Predicate pred) -{ - using thrust::system::detail::generic::transform_if; - return transform_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, op, pred); -} // end transform_if() - - -template - ForwardIterator transform_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - InputIterator3 stencil, - ForwardIterator result, - BinaryFunction binary_op, - Predicate pred) -{ - using thrust::system::detail::generic::transform_if; - return transform_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, stencil, result, binary_op, pred); -} // end transform_if() - - -template - OutputIterator transform(InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::transform(select_system(system1,system2), first, last, result, op); -} // end transform() - - -template - OutputIterator transform(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryFunction op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::transform(select_system(system1,system2,system3), first1, last1, first2, result, op); -} // end transform() - - -template - ForwardIterator transform_if(InputIterator first, - InputIterator last, - ForwardIterator result, - UnaryFunction unary_op, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::transform_if(select_system(system1,system2), first, last, result, unary_op, pred); -} // end transform_if() - - -template - ForwardIterator transform_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - ForwardIterator result, - UnaryFunction unary_op, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - - System1 system1; - System2 system2; - System3 system3; - - return thrust::transform_if(select_system(system1,system2,system3), first, last, stencil, result, unary_op, pred); -} // end transform_if() - - -template - ForwardIterator transform_if(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator3 stencil, - ForwardIterator result, - BinaryFunction binary_op, - Predicate pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::transform_if(select_system(system1,system2,system3,system4), first1, last1, first2, stencil, result, binary_op, pred); -} // end transform_if() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/transform_reduce.inl b/compat/thrust/detail/transform_reduce.inl deleted file mode 100644 index ede6503..0000000 --- a/compat/thrust/detail/transform_reduce.inl +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file transform_reduce.inl - * \brief Inline file for transform_reduce.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputType transform_reduce(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::transform_reduce; - return transform_reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, unary_op, init, binary_op); -} // end transform_reduce() - - -template - OutputType transform_reduce(InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::transform_reduce(select_system(system), first, last, unary_op, init, binary_op); -} // end transform_reduce() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/transform_scan.inl b/compat/thrust/detail/transform_scan.inl deleted file mode 100644 index 0187c4b..0000000 --- a/compat/thrust/detail/transform_scan.inl +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file transform_scan.inl - * \brief Inline file for transform_scan.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - OutputIterator transform_inclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::transform_inclusive_scan; - return transform_inclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, unary_op, binary_op); -} // end transform_inclusive_scan() - - -template - OutputIterator transform_exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - T init, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::transform_exclusive_scan; - return transform_exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, unary_op, init, binary_op); -} // end transform_exclusive_scan() - - -template - OutputIterator transform_inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - BinaryFunction binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::transform_inclusive_scan(select_system(system1,system2), first, last, result, unary_op, binary_op); -} // end transform_inclusive_scan() - - -template - OutputIterator transform_exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - T init, - AssociativeOperator binary_op) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::transform_exclusive_scan(select_system(system1,system2), first, last, result, unary_op, init, binary_op); -} // end transform_exclusive_scan() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/trivial_sequence.h b/compat/thrust/detail/trivial_sequence.h deleted file mode 100644 index cc7e32b..0000000 --- a/compat/thrust/detail/trivial_sequence.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file trivial_sequence.h - * \brief Container-like class for wrapping sequences. The wrapped - * sequence always has trivial iterators, even when the input - * sequence does not. - */ - - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -// never instantiated -template struct _trivial_sequence { }; - -// trivial case -template -struct _trivial_sequence -{ - typedef Iterator iterator_type; - Iterator first, last; - - _trivial_sequence(thrust::execution_policy &, Iterator _first, Iterator _last) : first(_first), last(_last) - { -// std::cout << "trivial case" << std::endl; - } - - iterator_type begin() { return first; } - iterator_type end() { return last; } -}; - -// non-trivial case -template -struct _trivial_sequence -{ - typedef typename thrust::iterator_value::type iterator_value; - typedef typename thrust::detail::temporary_array::iterator iterator_type; - - thrust::detail::temporary_array buffer; - - _trivial_sequence(thrust::execution_policy &exec, Iterator first, Iterator last) - : buffer(exec, first, last) - { -// std::cout << "non-trivial case" << std::endl; - } - - iterator_type begin() { return buffer.begin(); } - iterator_type end() { return buffer.end(); } -}; - -template -struct trivial_sequence - : detail::_trivial_sequence::type> -{ - typedef _trivial_sequence::type> super_t; - - trivial_sequence(thrust::execution_policy &exec, Iterator first, Iterator last) : super_t(exec, first, last) { } -}; - -} // end namespace detail - -} // end namespace thrust - diff --git a/compat/thrust/detail/tuple.inl b/compat/thrust/detail/tuple.inl deleted file mode 100644 index 067ad63..0000000 --- a/compat/thrust/detail/tuple.inl +++ /dev/null @@ -1,948 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace thrust -{ - -// define null_type -struct null_type {}; - -// null_type comparisons -__host__ __device__ inline -bool operator==(const null_type&, const null_type&) { return true; } - -__host__ __device__ inline -bool operator>=(const null_type&, const null_type&) { return true; } - -__host__ __device__ inline -bool operator<=(const null_type&, const null_type&) { return true; } - -__host__ __device__ inline -bool operator!=(const null_type&, const null_type&) { return false; } - -__host__ __device__ inline -bool operator<(const null_type&, const null_type&) { return false; } - -__host__ __device__ inline -bool operator>(const null_type&, const null_type&) { return false; } - -// forward declaration for tuple -template < - class T0 = null_type, class T1 = null_type, class T2 = null_type, - class T3 = null_type, class T4 = null_type, class T5 = null_type, - class T6 = null_type, class T7 = null_type, class T8 = null_type, - class T9 = null_type> -class tuple; - -// forward declaration of tuple_element -template struct tuple_element; - -// specializations for tuple_element -template - struct tuple_element<0,T> -{ - typedef typename T::head_type type; -}; // end tuple_element<0,T> - -template - struct tuple_element -{ - private: - typedef typename T::tail_type Next; - typedef typename tuple_element::type unqualified_type; - - public: - typedef typename thrust::detail::add_const::type type; -}; // end tuple_element - -template - struct tuple_element<0,const T> -{ - typedef typename thrust::detail::add_const::type type; -}; // end tuple_element<0,const T> - - - -// forward declaration of tuple_size -template struct tuple_size; - -// specializations for tuple_size -template<> - struct tuple_size< tuple<> > -{ - static const int value = 0; -}; // end tuple_size< tuple<> > - -template<> - struct tuple_size -{ - static const int value = 0; -}; // end tuple_size - - - -// forward declaration of detail::cons -namespace detail -{ - -template struct cons; - -} // end detail - - -// -- some traits classes for get functions -template struct access_traits -{ - typedef const T& const_type; - typedef T& non_const_type; - - typedef const typename thrust::detail::remove_cv::type& parameter_type; - -// used as the tuple constructors parameter types -// Rationale: non-reference tuple element types can be cv-qualified. -// It should be possible to initialize such types with temporaries, -// and when binding temporaries to references, the reference must -// be non-volatile and const. 8.5.3. (5) -}; // end access_traits - -template struct access_traits -{ - typedef T& const_type; - typedef T& non_const_type; - - typedef T& parameter_type; -}; // end access_traits - -// forward declarations of get() -template -__host__ __device__ -inline typename access_traits< - typename tuple_element >::type - >::non_const_type -// XXX we probably don't need to do this for any compiler we care about -jph -//get(cons& c BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int, N)); -get(detail::cons& c); - -template -__host__ __device__ -inline typename access_traits< - typename tuple_element >::type - >::const_type -// XXX we probably don't need to do this for any compiler we care about -jph -//get(const cons& c BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int, N)); -get(const detail::cons& c); - -namespace detail -{ - -// -- generate error template, referencing to non-existing members of this -// template is used to produce compilation errors intentionally -template -class generate_error; - -// - cons getters -------------------------------------------------------- -// called: get_class::get(aTuple) - -template< int N > -struct get_class -{ - template - __host__ __device__ - inline static RET get(const cons& t) - { - // XXX we may not need to deal with this for any compiler we care about -jph - //return get_class::BOOST_NESTED_TEMPLATE get(t.tail); - return get_class::template get(t.tail); - - // gcc 4.3 couldn't compile this: - //return get_class::get(t.tail); - } - - template - __host__ __device__ - inline static RET get(cons& t) - { - // XXX we may not need to deal with this for any compiler we care about -jph - //return get_class::BOOST_NESTED_TEMPLATE get(t.tail); - return get_class::template get(t.tail); - - // gcc 4.3 couldn't compile this: - //return get_class::get(t.tail); - } -}; // end get_class - -template<> -struct get_class<0> -{ - template - __host__ __device__ - inline static RET get(const cons& t) - { - return t.head; - } - - template - __host__ __device__ - inline static RET get(cons& t) - { - return t.head; - } -}; // get get_class<0> - - -template struct IF -{ - typedef Then RET; -}; - -template struct IF -{ - typedef Else RET; -}; - -// These helper templates wrap void types and plain function types. -// The rationale is to allow one to write tuple types with those types -// as elements, even though it is not possible to instantiate such object. -// E.g: typedef tuple some_type; // ok -// but: some_type x; // fails - -template class non_storeable_type -{ - __host__ __device__ - non_storeable_type(); -}; - -template struct wrap_non_storeable_type -{ - // XXX is_function looks complicated; punt for now -jph - //typedef typename IF< - // ::thrust::detail::is_function::value, non_storeable_type, T - //>::RET type; - - typedef T type; -}; - -template <> struct wrap_non_storeable_type -{ - typedef non_storeable_type type; -}; - - -template - struct cons -{ - typedef HT head_type; - typedef TT tail_type; - - typedef typename - wrap_non_storeable_type::type stored_head_type; - - stored_head_type head; - tail_type tail; - - inline __host__ __device__ - typename access_traits::non_const_type - get_head() { return head; } - - inline __host__ __device__ - typename access_traits::non_const_type - get_tail() { return tail; } - - inline __host__ __device__ - typename access_traits::const_type - get_head() const { return head; } - - inline __host__ __device__ - typename access_traits::const_type - get_tail() const { return tail; } - - inline __host__ __device__ - cons(void) : head(), tail() {} - // cons() : head(detail::default_arg::f()), tail() {} - - // the argument for head is not strictly needed, but it prevents - // array type elements. This is good, since array type elements - // cannot be supported properly in any case (no assignment, - // copy works only if the tails are exactly the same type, ...) - - inline __host__ __device__ - cons(typename access_traits::parameter_type h, - const tail_type& t) - : head (h), tail(t) {} - - template - inline __host__ __device__ - cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, - T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 ) - : head (t1), - tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, static_cast(null_type())) - {} - - template - inline __host__ __device__ - cons( const null_type& /*t1*/, T2& t2, T3& t3, T4& t4, T5& t5, - T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 ) - : head (), - tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, static_cast(null_type())) - {} - - - template - inline __host__ __device__ - cons( const cons& u ) : head(u.head), tail(u.tail) {} - - template - inline __host__ __device__ - cons& operator=( const cons& u ) { - head=u.head; tail=u.tail; return *this; - } - - // must define assignment operator explicitly, implicit version is - // illformed if HT is a reference (12.8. (12)) - inline __host__ __device__ - cons& operator=(const cons& u) { - head = u.head; tail = u.tail; return *this; - } - - // XXX enable when we support std::pair -jph - //template - //__host__ __device__ - //cons& operator=( const std::pair& u ) { - // //BOOST_STATIC_ASSERT(length::value == 2); // check length = 2 - // head = u.first; tail.head = u.second; return *this; - //} - - // get member functions (non-const and const) - template - __host__ __device__ - typename access_traits< - typename tuple_element >::type - >::non_const_type - get() { - return thrust::get(*this); // delegate to non-member get - } - - template - __host__ __device__ - typename access_traits< - typename tuple_element >::type - >::const_type - get() const { - return thrust::get(*this); // delegate to non-member get - } - - inline __host__ __device__ - void swap(cons &c) - { - using thrust::swap; - - swap(head, c.head); - tail.swap(c.tail); - } -}; - -template - struct cons -{ - typedef HT head_type; - typedef null_type tail_type; - typedef cons self_type; - - typedef typename - wrap_non_storeable_type::type stored_head_type; - stored_head_type head; - - typename access_traits::non_const_type - inline __host__ __device__ - get_head() { return head; } - - inline __host__ __device__ - null_type get_tail() { return null_type(); } - - inline __host__ __device__ - typename access_traits::const_type - get_head() const { return head; } - - inline __host__ __device__ - null_type get_tail() const { return null_type(); } - - inline __host__ __device__ - cons() : head() {} - - inline __host__ __device__ - cons(typename access_traits::parameter_type h, - const null_type& = null_type()) - : head (h) {} - - template - inline __host__ __device__ - cons(T1& t1, const null_type&, const null_type&, const null_type&, - const null_type&, const null_type&, const null_type&, - const null_type&, const null_type&, const null_type&) - : head (t1) {} - - inline __host__ __device__ - cons(const null_type&, - const null_type&, const null_type&, const null_type&, - const null_type&, const null_type&, const null_type&, - const null_type&, const null_type&, const null_type&) - : head () {} - - template - inline __host__ __device__ - cons( const cons& u ) : head(u.head) {} - - template - inline __host__ __device__ - cons& operator=(const cons& u ) - { - head = u.head; - return *this; - } - - // must define assignment operator explicitly, implicit version - // is illformed if HT is a reference - inline __host__ __device__ - cons& operator=(const cons& u) { head = u.head; return *this; } - - template - inline __host__ __device__ - typename access_traits< - typename tuple_element::type - >::non_const_type - // XXX we probably don't need this for the compilers we care about -jph - //get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) - get(void) - { - return thrust::get(*this); - } - - template - inline __host__ __device__ - typename access_traits< - typename tuple_element::type - >::const_type - // XXX we probably don't need this for the compilers we care about -jph - //get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) const - get(void) const - { - return thrust::get(*this); - } - - inline __host__ __device__ - void swap(cons &c) - { - using thrust::swap; - - swap(head, c.head); - } -}; // end cons - -template - struct map_tuple_to_cons -{ - typedef cons::type - > type; -}; // end map_tuple_to_cons - -// The empty tuple is a null_type -template <> - struct map_tuple_to_cons -{ - typedef null_type type; -}; // end map_tuple_to_cons<...> - - - -// --------------------------------------------------------------------------- -// The call_traits for make_tuple - -// Must be instantiated with plain or const plain types (not with references) - -// from template foo(const T& t) : make_tuple_traits::type -// from template foo(T& t) : make_tuple_traits::type - -// Conversions: -// T -> T, -// references -> compile_time_error -// array -> const ref array - - -template -struct make_tuple_traits { - typedef T type; - - // commented away, see below (JJ) - // typedef typename IF< - // boost::is_function::value, - // T&, - // T>::RET type; - -}; - -// The is_function test was there originally for plain function types, -// which can't be stored as such (we must either store them as references or -// pointers). Such a type could be formed if make_tuple was called with a -// reference to a function. -// But this would mean that a const qualified function type was formed in -// the make_tuple function and hence make_tuple can't take a function -// reference as a parameter, and thus T can't be a function type. -// So is_function test was removed. -// (14.8.3. says that type deduction fails if a cv-qualified function type -// is created. (It only applies for the case of explicitly specifying template -// args, though?)) (JJ) - -template -struct make_tuple_traits { - typedef typename - detail::generate_error:: - do_not_use_with_reference_type error; -}; - -// Arrays can't be stored as plain types; convert them to references. -// All arrays are converted to const. This is because make_tuple takes its -// parameters as const T& and thus the knowledge of the potential -// non-constness of actual argument is lost. -template struct make_tuple_traits { - typedef const T (&type)[n]; -}; - -template -struct make_tuple_traits { - typedef const T (&type)[n]; -}; - -template struct make_tuple_traits { - typedef const volatile T (&type)[n]; -}; - -template -struct make_tuple_traits { - typedef const volatile T (&type)[n]; -}; - -// XXX enable these if we ever care about reference_wrapper -jph -//template -//struct make_tuple_traits >{ -// typedef T& type; -//}; -// -//template -//struct make_tuple_traits >{ -// typedef T& type; -//}; - - -// a helper traits to make the make_tuple functions shorter (Vesa Karvonen's -// suggestion) -template < - class T0 = null_type, class T1 = null_type, class T2 = null_type, - class T3 = null_type, class T4 = null_type, class T5 = null_type, - class T6 = null_type, class T7 = null_type, class T8 = null_type, - class T9 = null_type -> -struct make_tuple_mapper { - typedef - tuple::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type, - typename make_tuple_traits::type> type; -}; - -} // end detail - - -template -__host__ __device__ -inline typename access_traits< - typename tuple_element >::type - >::non_const_type -get(detail::cons& c) -{ - //return detail::get_class::BOOST_NESTED_TEMPLATE - - // gcc 4.3 couldn't compile this: - //return detail::get_class:: - - return detail::get_class::template - get< - typename access_traits< - typename tuple_element >::type - >::non_const_type, - HT,TT - >(c); -} - - -// get function for const cons-lists, returns a const reference to -// the element. If the element is a reference, returns the reference -// as such (that is, can return a non-const reference) -template -__host__ __device__ -inline typename access_traits< - typename tuple_element >::type - >::const_type -get(const detail::cons& c) -{ - //return detail::get_class::BOOST_NESTED_TEMPLATE - - // gcc 4.3 couldn't compile this: - //return detail::get_class:: - - return detail::get_class::template - get< - typename access_traits< - typename tuple_element >::type - >::const_type, - HT,TT - >(c); -} - - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3,t4); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3,t4,t5); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3,t4,t5,t6); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3,t4,t5,t6,t7); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3,t4,t5,t6,t7,t8); -} // end make_tuple() - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9) -{ - typedef typename detail::make_tuple_mapper::type t; - return t(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9); -} // end make_tuple() - - -template -__host__ __device__ inline -tuple tie(T0 &t0) -{ - return tuple(t0); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1) -{ - return tuple(t0,t1); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2) -{ - return tuple(t0,t1,t2); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3) -{ - return tuple(t0,t1,t2,t3); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4) -{ - return tuple(t0,t1,t2,t3,t4); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) -{ - return tuple(t0,t1,t2,t3,t4,t5); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6) -{ - return tuple(t0,t1,t2,t3,t4,t5,t6); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7) -{ - return tuple(t0,t1,t2,t3,t4,t5,t6,t7); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8) -{ - return tuple(t0,t1,t2,t3,t4,t5,t6,t7,t8); -} - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9) -{ - return tuple(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9); -} - -template< - typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, - typename U0, typename U1, typename U2, typename U3, typename U4, typename U5, typename U6, typename U7, typename U8, typename U9 -> -__host__ __device__ inline -void swap(thrust::tuple &x, - thrust::tuple &y) -{ - return x.swap(y); -} - - - -namespace detail -{ - -template -__host__ __device__ -inline bool eq(const T1& lhs, const T2& rhs) { - return lhs.get_head() == rhs.get_head() && - eq(lhs.get_tail(), rhs.get_tail()); -} -template<> -inline bool eq(const null_type&, const null_type&) { return true; } - -template -__host__ __device__ -inline bool neq(const T1& lhs, const T2& rhs) { - return lhs.get_head() != rhs.get_head() || - neq(lhs.get_tail(), rhs.get_tail()); -} -template<> -__host__ __device__ -inline bool neq(const null_type&, const null_type&) { return false; } - -template -__host__ __device__ -inline bool lt(const T1& lhs, const T2& rhs) { - return (lhs.get_head() < rhs.get_head()) || - (!(rhs.get_head() < lhs.get_head()) && - lt(lhs.get_tail(), rhs.get_tail())); -} -template<> -__host__ __device__ -inline bool lt(const null_type&, const null_type&) { return false; } - -template -__host__ __device__ -inline bool gt(const T1& lhs, const T2& rhs) { - return (lhs.get_head() > rhs.get_head()) || - (!(rhs.get_head() > lhs.get_head()) && - gt(lhs.get_tail(), rhs.get_tail())); -} -template<> -__host__ __device__ -inline bool gt(const null_type&, const null_type&) { return false; } - -template -__host__ __device__ -inline bool lte(const T1& lhs, const T2& rhs) { - return lhs.get_head() <= rhs.get_head() && - ( !(rhs.get_head() <= lhs.get_head()) || - lte(lhs.get_tail(), rhs.get_tail())); -} -template<> -__host__ __device__ -inline bool lte(const null_type&, const null_type&) { return true; } - -template -__host__ __device__ -inline bool gte(const T1& lhs, const T2& rhs) { - return lhs.get_head() >= rhs.get_head() && - ( !(rhs.get_head() >= lhs.get_head()) || - gte(lhs.get_tail(), rhs.get_tail())); -} -template<> -__host__ __device__ -inline bool gte(const null_type&, const null_type&) { return true; } - -} // end detail - - - -// equal ---- - -template -__host__ __device__ -inline bool operator==(const detail::cons& lhs, const detail::cons& rhs) -{ - // XXX support this eventually -jph - //// check that tuple lengths are equal - //BOOST_STATIC_ASSERT(tuple_size::value == tuple_size::value); - - return detail::eq(lhs, rhs); -} // end operator==() - -// not equal ----- - -template -__host__ __device__ -inline bool operator!=(const detail::cons& lhs, const detail::cons& rhs) -{ - // XXX support this eventually -jph - //// check that tuple lengths are equal - //BOOST_STATIC_ASSERT(tuple_size::value == tuple_size::value); - - return detail::neq(lhs, rhs); -} // end operator!=() - -// < -template -__host__ __device__ -inline bool operator<(const detail::cons& lhs, const detail::cons& rhs) -{ - // XXX support this eventually -jph - //// check that tuple lengths are equal - //BOOST_STATIC_ASSERT(tuple_size::value == tuple_size::value); - - return detail::lt(lhs, rhs); -} // end operator<() - -// > -template -__host__ __device__ -inline bool operator>(const detail::cons& lhs, const detail::cons& rhs) -{ - // XXX support this eventually -jph - //// check that tuple lengths are equal - //BOOST_STATIC_ASSERT(tuple_size::value == tuple_size::value); - - return detail::gt(lhs, rhs); -} // end operator>() - -// <= -template -__host__ __device__ -inline bool operator<=(const detail::cons& lhs, const detail::cons& rhs) -{ - // XXX support this eventually -jph - //// check that tuple lengths are equal - //BOOST_STATIC_ASSERT(tuple_size::value == tuple_size::value); - - return detail::lte(lhs, rhs); -} // end operator<=() - -// >= -template -__host__ __device__ -inline bool operator>=(const detail::cons& lhs, const detail::cons& rhs) -{ - // XXX support this eventually -jph - //// check that tuple lengths are equal - //BOOST_STATIC_ASSERT(tuple_size::value == tuple_size::value); - - return detail::gte(lhs, rhs); -} // end operator>=() - -} // end thrust - diff --git a/compat/thrust/detail/tuple_meta_transform.h b/compat/thrust/detail/tuple_meta_transform.h deleted file mode 100644 index ff99709..0000000 --- a/compat/thrust/detail/tuple_meta_transform.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ - -namespace detail -{ - -template class UnaryMetaFunction, - unsigned int sz = thrust::tuple_size::value> - struct tuple_meta_transform; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef null_type type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/tuple_transform.h b/compat/thrust/detail/tuple_transform.h deleted file mode 100644 index f18b872..0000000 --- a/compat/thrust/detail/tuple_transform.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace detail -{ - -template class UnaryMetaFunction, - typename UnaryFunction, - unsigned int sz = thrust::tuple_size::value> - struct tuple_transform_functor; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - return thrust::null_type(); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - return thrust::null_type(); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t)), - f(thrust::get<9>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t)), - f(thrust::get<9>(t))); - } -}; - - -template class UnaryMetaFunction, - typename Tuple, - typename UnaryFunction> -typename tuple_meta_transform::type -tuple_host_transform(const Tuple &t, UnaryFunction f) -{ - return tuple_transform_functor::do_it_on_the_host(t,f); -} - -template class UnaryMetaFunction, - typename Tuple, - typename UnaryFunction> -typename tuple_meta_transform::type -__host__ __device__ -tuple_host_device_transform(const Tuple &t, UnaryFunction f) -{ - return tuple_transform_functor::do_it_on_the_host_or_device(t,f); -} - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/type_traits.h b/compat/thrust/detail/type_traits.h deleted file mode 100644 index 5dbeb90..0000000 --- a/compat/thrust/detail/type_traits.h +++ /dev/null @@ -1,641 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file type_traits.h - * \brief Temporarily define some type traits - * until nvcc can compile tr1::type_traits. - */ - -#pragma once - -#include - -// XXX nvcc 2.2 closed beta can't compile type_traits -//// find type_traits -// -//#ifdef __GNUC__ -// -//#if __GNUC__ == 4 && __GNUC_MINOR__ == 2 -//#include -//#elif __GNUC__ == 4 && __GNUC_MINOR__ > 2 -//#include -//#endif // GCC version -// -//#endif // GCC -// -//#ifdef _MSC_VER -//#include -//#endif // MSVC - - -namespace thrust -{ - -// forward declaration of device_reference -template class device_reference; - -namespace detail -{ - /// helper classes [4.3]. - template - struct integral_constant - { - static const _Tp value = __v; - typedef _Tp value_type; - typedef integral_constant<_Tp, __v> type; - }; - - /// typedef for true_type - typedef integral_constant true_type; - - /// typedef for true_type - typedef integral_constant false_type; - -//template struct is_integral : public std::tr1::is_integral {}; -template struct is_integral : public false_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; -template<> struct is_integral : public true_type {}; - -template struct is_floating_point : public false_type {}; -template<> struct is_floating_point : public true_type {}; -template<> struct is_floating_point : public true_type {}; -template<> struct is_floating_point : public true_type {}; - -template struct is_arithmetic : public is_integral {}; -template<> struct is_arithmetic : public true_type {}; -template<> struct is_arithmetic : public true_type {}; -template<> struct is_arithmetic : public true_type {}; -template<> struct is_arithmetic : public true_type {}; - -template struct is_pointer : public false_type {}; -template struct is_pointer : public true_type {}; - -template struct is_device_ptr : public false_type {}; - -template struct is_void : public false_type {}; -template<> struct is_void : public true_type {}; -template<> struct is_void : public true_type {}; - - -namespace tt_detail -{ - - -} // end tt_detail - -template struct is_pod - : public integral_constant< - bool, - is_void::value || is_pointer::value || is_arithmetic::value -#if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC -// use intrinsic type traits - || __is_pod(T) -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC -// only use the intrinsic for >= 4.3 -#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) - || __is_pod(T) -#endif // GCC VERSION -#endif // THRUST_HOST_COMPILER - > - {}; - - -template struct has_trivial_constructor - : public integral_constant< - bool, - is_pod::value -#if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC - || __has_trivial_constructor(T) -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC -// only use the intrinsic for >= 4.3 -#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) - || __has_trivial_constructor(T) -#endif // GCC VERSION -#endif // THRUST_HOST_COMPILER - > -{}; - -template struct has_trivial_copy_constructor - : public integral_constant< - bool, - is_pod::value -#if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC - || __has_trivial_copy(T) -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC -// only use the intrinsic for >= 4.3 -#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) - || __has_trivial_copy(T) -#endif // GCC VERSION -#endif // THRUST_HOST_COMPILER - > -{}; - -template struct has_trivial_destructor : public is_pod {}; - -template struct is_const : public false_type {}; -template struct is_const : public true_type {}; - -template struct is_volatile : public false_type {}; -template struct is_volatile : public true_type {}; - -template - struct add_const -{ - typedef T const type; -}; // end add_const - -template - struct remove_const -{ - typedef T type; -}; // end remove_const - -template - struct remove_const -{ - typedef T type; -}; // end remove_const - -template - struct add_volatile -{ - typedef volatile T type; -}; // end add_volatile - -template - struct remove_volatile -{ - typedef T type; -}; // end remove_volatile - -template - struct remove_volatile -{ - typedef T type; -}; // end remove_volatile - -template - struct add_cv -{ - typedef const volatile T type; -}; // end add_cv - -template - struct remove_cv -{ - typedef typename remove_const::type>::type type; -}; // end remove_cv - - -template struct is_reference : public false_type {}; -template struct is_reference : public true_type {}; - -template struct is_device_reference : public false_type {}; -template struct is_device_reference< thrust::device_reference > : public true_type {}; - - -// NB: Careful with reference to void. -template::value || is_reference<_Tp>::value)> - struct __add_reference_helper - { typedef _Tp& type; }; - -template - struct __add_reference_helper<_Tp, true> - { typedef _Tp type; }; - -template - struct add_reference - : public __add_reference_helper<_Tp>{}; - -template - struct remove_reference -{ - typedef T type; -}; // end remove_reference - -template - struct remove_reference -{ - typedef T type; -}; // end remove_reference - -template - struct is_same - : public false_type -{ -}; // end is_same - -template - struct is_same - : public true_type -{ -}; // end is_same - -template - struct lazy_is_same - : is_same -{ -}; // end lazy_is_same - -template - struct is_different - : public true_type -{ -}; // end is_different - -template - struct is_different - : public false_type -{ -}; // end is_different - -template - struct lazy_is_different - : is_different -{ -}; // end lazy_is_different - -namespace tt_detail -{ - -template - struct is_int_or_cref -{ - typedef typename remove_reference::type type_sans_ref; - static const bool value = (is_integral::value - || (is_integral::value - && is_const::value - && !is_volatile::value)); -}; // end is_int_or_cref - - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN -__THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL_BEGIN - - -template - struct is_convertible_sfinae -{ - private: - typedef char one_byte; - typedef struct { char two_chars[2]; } two_bytes; - - static one_byte test(To); - static two_bytes test(...); - static From m_from; - - public: - static const bool value = sizeof(test(m_from)) == sizeof(one_byte); -}; // end is_convertible_sfinae - - -__THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL_END -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - - -template - struct is_convertible_needs_simple_test -{ - static const bool from_is_void = is_void::value; - static const bool to_is_void = is_void::value; - static const bool from_is_float = is_floating_point::type>::value; - static const bool to_is_int_or_cref = is_int_or_cref::value; - - static const bool value = (from_is_void || to_is_void || (from_is_float && to_is_int_or_cref)); -}; // end is_convertible_needs_simple_test - - -template::value> - struct is_convertible -{ - static const bool value = (is_void::value - || (is_int_or_cref::value - && !is_void::value)); -}; // end is_convertible - - -template - struct is_convertible -{ - static const bool value = (is_convertible_sfinae::type, To>::value); -}; // end is_convertible - - -} // end tt_detail - -template - struct is_convertible - : public integral_constant::value> -{ -}; // end is_convertible - - -template - struct is_one_convertible_to_the_other - : public integral_constant< - bool, - is_convertible::value || is_convertible::value - > -{}; - - -// mpl stuff - -template - struct or_ - : public integral_constant< - bool, - Condition1::value || Condition2::value || Condition3::value || Condition4::value || Condition5::value || Condition6::value || Condition7::value || Condition8::value || Condition9::value || Condition10::value - > -{ -}; // end or_ - -template - struct and_ - : public integral_constant -{ -}; // end and_ - -template - struct not_ - : public integral_constant -{ -}; // end not_ - -template - struct eval_if -{ -}; // end eval_if - -template - struct eval_if -{ - typedef typename Then::type type; -}; // end eval_if - -template - struct eval_if -{ - typedef typename Else::type type; -}; // end eval_if - -template -// struct identity -// XXX WAR nvcc's confusion with thrust::identity - struct identity_ -{ - typedef T type; -}; // end identity - -template struct enable_if {}; -template struct enable_if {typedef T type;}; - -template struct lazy_enable_if {}; -template struct lazy_enable_if {typedef typename T::type type;}; - -template struct disable_if : enable_if {}; -template struct lazy_disable_if : lazy_enable_if {}; - - -template - struct enable_if_convertible - : enable_if< is_convertible::value, T > -{}; - - -template - struct disable_if_convertible - : disable_if< is_convertible::value, T > -{}; - - -template - struct enable_if_different - : enable_if::value, Result> -{}; - - -template - struct is_numeric - : and_< - is_convertible, - is_convertible - > -{ -}; // end is_numeric - - -template struct is_reference_to_const : false_type {}; -template struct is_reference_to_const : true_type {}; - - -// make_unsigned follows - -namespace tt_detail -{ - -template struct make_unsigned_simple; - -template<> struct make_unsigned_simple { typedef unsigned char type; }; -template<> struct make_unsigned_simple { typedef signed char type; }; -template<> struct make_unsigned_simple { typedef unsigned char type; }; -template<> struct make_unsigned_simple { typedef unsigned short type; }; -template<> struct make_unsigned_simple { typedef unsigned short type; }; -template<> struct make_unsigned_simple { typedef unsigned int type; }; -template<> struct make_unsigned_simple { typedef unsigned int type; }; -template<> struct make_unsigned_simple { typedef unsigned long int type; }; -template<> struct make_unsigned_simple { typedef unsigned long int type; }; -template<> struct make_unsigned_simple { typedef unsigned long long int type; }; -template<> struct make_unsigned_simple { typedef unsigned long long int type; }; - -template - struct make_unsigned_base -{ - // remove cv - typedef typename remove_cv::type remove_cv_t; - - // get the simple unsigned type - typedef typename make_unsigned_simple::type unsigned_remove_cv_t; - - // add back const, volatile, both, or neither to the simple result - typedef typename eval_if< - is_const::value && is_volatile::value, - // add cv back - add_cv, - // check const & volatile individually - eval_if< - is_const::value, - // add c back - add_const, - eval_if< - is_volatile::value, - // add v back - add_volatile, - // original type was neither cv, return the simple unsigned result - identity_ - > - > - >::type type; -}; - -} // end tt_detail - -template - struct make_unsigned - : tt_detail::make_unsigned_base -{}; - -struct largest_available_float -{ -#if defined(__CUDA_ARCH__) -# if (__CUDA_ARCH__ < 130) - typedef float type; -# else - typedef double type; -# endif -#else - typedef double type; -#endif -}; - -// T1 wins if they are both the same size -template - struct larger_type - : thrust::detail::eval_if< - (sizeof(T2) > sizeof(T1)), - thrust::detail::identity_, - thrust::detail::identity_ - > -{}; - - -namespace is_base_of_ns -{ - -typedef char yes; -typedef struct { char two_chars[2]; } no; - -template - struct host -{ - operator Base*() const; - operator Derived*(); -}; // end host - -template - struct impl -{ - template static yes check(Derived *, T); - static no check(Base*, int); - - static const bool value = sizeof(check(host(), int())) == sizeof(yes); -}; // end impl - -} // end is_base_of_ns - - -template - struct is_base_of - : integral_constant< - bool, - is_base_of_ns::impl::value - > -{}; - -template - struct enable_if_base_of - : enable_if< - is_base_of::value, - Result - > -{}; - - -namespace is_assignable_ns -{ - -template - class is_assignable -{ - typedef char yes_type; - typedef struct { char array[2]; } no_type; - - template static typename add_reference::type declval(); - - template struct helper { typedef void * type; }; - - template static yes_type test(typename helper() = declval())>::type); - - template static no_type test(...); - - public: - static const bool value = sizeof(test(0)) == 1; -}; // end is_assignable - -} // end is_assignable_ns - - -template - struct is_assignable - : integral_constant< - bool, - is_assignable_ns::is_assignable::value - > -{}; - - -template - struct is_copy_assignable - : is_assignable< - typename add_reference::type, - typename add_reference::type>::type - > -{}; - - -} // end detail - -} // end thrust - -#include - diff --git a/compat/thrust/detail/type_traits/algorithm/intermediate_type_from_function_and_iterators.h b/compat/thrust/detail/type_traits/algorithm/intermediate_type_from_function_and_iterators.h deleted file mode 100644 index 92767b5..0000000 --- a/compat/thrust/detail/type_traits/algorithm/intermediate_type_from_function_and_iterators.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -// this trait reports what type should be used as a temporary in certain algorithms -// which aggregate intermediate results from a function before writing to an output iterator - -// the pseudocode for deducing the type of the temporary used below: -// -// if Function is an AdaptableFunction -// result = Function::result_type -// else if OutputIterator2 is a "pure" output iterator -// result = InputIterator2::value_type -// else -// result = OutputIterator2::value_type -// -// XXX upon c++0x, TemporaryType needs to be: -// result_of::type -template - struct intermediate_type_from_function_and_iterators - : eval_if< - has_result_type::value, - result_type, - eval_if< - is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - > -{ -}; // end intermediate_type_from_function_and_iterators - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/type_traits/function_traits.h b/compat/thrust/detail/type_traits/function_traits.h deleted file mode 100644 index 39015c6..0000000 --- a/compat/thrust/detail/type_traits/function_traits.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -// forward definitions for is_commutative -template struct plus; -template struct multiplies; -template struct minimum; -template struct maximum; -template struct logical_or; -template struct logical_and; -template struct bit_or; -template struct bit_and; -template struct bit_xor; - -namespace detail -{ - - -// some metafunctions which check for the nested types of the adaptable functions - -__THRUST_DEFINE_HAS_NESTED_TYPE(has_result_type, result_type) - -__THRUST_DEFINE_HAS_NESTED_TYPE(has_argument_type, argument_type) - -__THRUST_DEFINE_HAS_NESTED_TYPE(has_first_argument_type, first_argument_type) - -__THRUST_DEFINE_HAS_NESTED_TYPE(has_second_argument_type, second_argument_type) - - -template - struct result_type -{ - typedef typename AdaptableBinaryFunction::result_type type; -}; - - -template - struct is_adaptable_unary_function - : thrust::detail::and_< - has_result_type, - has_argument_type - > -{}; - - -template - struct is_adaptable_binary_function - : thrust::detail::and_< - has_result_type, - thrust::detail::and_< - has_first_argument_type, - has_second_argument_type - > - > -{}; - - -template - struct is_commutative - : public thrust::detail::false_type -{}; - -template struct is_commutative< typename thrust::plus > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::multiplies > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::minimum > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::maximum > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::logical_or > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::logical_and > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::bit_or > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::bit_and > : public thrust::detail::is_arithmetic {}; -template struct is_commutative< typename thrust::bit_xor > : public thrust::detail::is_arithmetic {}; - -} // end namespace detail -} // end namespace thrust - diff --git a/compat/thrust/detail/type_traits/has_member_function.h b/compat/thrust/detail/type_traits/has_member_function.h deleted file mode 100644 index 117f4cb..0000000 --- a/compat/thrust/detail/type_traits/has_member_function.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#define __THRUST_DEFINE_HAS_MEMBER_FUNCTION(trait_name, member_function_name) \ -template class trait_name; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(); \ - }; \ - struct base : public T, public base_mixin {}; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ - typedef thrust::detail::integral_constant type; \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg); \ - }; \ - struct base : public T, public base_mixin {}; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ - typedef thrust::detail::integral_constant type; \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg1,Arg2); \ - }; \ - struct base : public T, public base_mixin {}; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ - typedef thrust::detail::integral_constant type; \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg1,Arg2,Arg3); \ - }; \ - struct base : public T, public base_mixin {}; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ - typedef thrust::detail::integral_constant type; \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg1,Arg2,Arg3,Arg4); \ - }; \ - struct base : public T, public base_mixin {}; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ - typedef thrust::detail::integral_constant type; \ -}; - diff --git a/compat/thrust/detail/type_traits/has_nested_type.h b/compat/thrust/detail/type_traits/has_nested_type.h deleted file mode 100644 index 98c9460..0000000 --- a/compat/thrust/detail/type_traits/has_nested_type.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#define __THRUST_DEFINE_HAS_NESTED_TYPE(trait_name, nested_type_name) \ -template \ - struct trait_name \ -{ \ - typedef char yes_type; \ - typedef int no_type; \ - template static yes_type test(typename S::nested_type_name *); \ - template static no_type test(...); \ - static bool const value = sizeof(test(0)) == sizeof(yes_type);\ - typedef thrust::detail::integral_constant type;\ -}; - diff --git a/compat/thrust/detail/type_traits/has_trivial_assign.h b/compat/thrust/detail/type_traits/has_trivial_assign.h deleted file mode 100644 index d248245..0000000 --- a/compat/thrust/detail/type_traits/has_trivial_assign.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file type_traits.h - * \brief Temporarily define some type traits - * until nvcc can compile tr1::type_traits. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace detail -{ - -template struct has_trivial_assign - : public integral_constant< - bool, - (is_pod::value && !is_const::value) -#if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC - || __has_trivial_assign(T) -#elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC -// only use the intrinsic for >= 4.3 -#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) - || __has_trivial_assign(T) -#endif // GCC VERSION -#endif // THRUST_HOST_COMPILER - > -{}; - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/type_traits/is_call_possible.h b/compat/thrust/detail/type_traits/is_call_possible.h deleted file mode 100644 index 41b9539..0000000 --- a/compat/thrust/detail/type_traits/is_call_possible.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -// inspired by Roman Perepelitsa's presentation from comp.lang.c++.moderated -// based on the implementation here: http://www.rsdn.ru/forum/cpp/2759773.1.aspx - -namespace thrust -{ -namespace detail -{ -namespace is_call_possible_detail -{ - -template class void_exp_result {}; - -template -U const& operator,(U const&, void_exp_result); - -template -U& operator,(U&, void_exp_result); - -template -struct clone_constness -{ - typedef dest_type type; -}; - -template -struct clone_constness -{ - typedef const dest_type type; -}; - -} // end is_call_possible_detail -} // end detail -} // end thrust - -#define __THRUST_DEFINE_IS_CALL_POSSIBLE(trait_name, member_function_name) \ -__THRUST_DEFINE_HAS_MEMBER_FUNCTION(trait_name##_has_member, member_function_name) \ - \ -template \ -struct trait_name \ -{ \ - private: \ - struct yes {}; \ - struct no { yes m[2]; }; \ - struct derived : public T \ - { \ - using T::member_function_name; \ - no member_function_name(...) const; \ - }; \ - \ - typedef typename thrust::detail::is_call_possible_detail::clone_constness::type derived_type; \ - \ - template \ - struct return_value_check \ - { \ - static yes deduce(Result); \ - static no deduce(...); \ - static no deduce(no); \ - static no deduce(thrust::detail::is_call_possible_detail::void_exp_result); \ - }; \ - \ - template \ - struct return_value_check \ - { \ - static yes deduce(...); \ - static no deduce(no); \ - }; \ - \ - template \ - struct impl \ - { \ - static const bool value = false; \ - }; \ - \ - template \ - struct impl \ - { \ - static typename add_reference::type test_me; \ - static typename add_reference::type arg; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg), thrust::detail::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename add_reference::type test_me; \ - static typename add_reference::type arg1; \ - static typename add_reference::type arg2; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg1,arg2), thrust::detail::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename add_reference::type test_me; \ - static typename add_reference::type arg1; \ - static typename add_reference::type arg2; \ - static typename add_reference::type arg3; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg1,arg2,arg3), thrust::detail::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename add_reference::type test_me; \ - static typename add_reference::type arg1; \ - static typename add_reference::type arg2; \ - static typename add_reference::type arg3; \ - static typename add_reference::type arg4; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg1,arg2,arg3,arg4), thrust::detail::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - public: \ - static const bool value = impl::value, Signature>::value; \ - typedef thrust::detail::integral_constant type; \ -}; - diff --git a/compat/thrust/detail/type_traits/is_metafunction_defined.h b/compat/thrust/detail/type_traits/is_metafunction_defined.h deleted file mode 100644 index fba0811..0000000 --- a/compat/thrust/detail/type_traits/is_metafunction_defined.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace detail -{ - -__THRUST_DEFINE_HAS_NESTED_TYPE(is_metafunction_defined, type) - -template - struct enable_if_defined - : thrust::detail::lazy_enable_if< - is_metafunction_defined::value, - Metafunction - > -{}; - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/type_traits/iterator/is_discard_iterator.h b/compat/thrust/detail/type_traits/iterator/is_discard_iterator.h deleted file mode 100644 index cca59da..0000000 --- a/compat/thrust/detail/type_traits/iterator/is_discard_iterator.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template -struct is_discard_iterator - : public thrust::detail::false_type -{}; - -template -struct is_discard_iterator< thrust::discard_iterator > - : public thrust::detail::true_type -{}; - -} // end namespace detail -} // end namespace thrust - diff --git a/compat/thrust/detail/type_traits/iterator/is_output_iterator.h b/compat/thrust/detail/type_traits/iterator/is_output_iterator.h deleted file mode 100644 index 4cefe63..0000000 --- a/compat/thrust/detail/type_traits/iterator/is_output_iterator.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - - -template - struct is_void_like - : thrust::detail::or_< - thrust::detail::is_void, - thrust::detail::is_same - > -{}; // end is_void_like - - -template - struct lazy_is_void_like - : is_void_like -{}; // end lazy_is_void_like - - -// XXX this meta function should first check that T is actually an iterator -// -// if thrust::iterator_value is defined and thrust::iterator_value::type == void -// return false -// else -// return true -template - struct is_output_iterator - : eval_if< - is_metafunction_defined >::value, - lazy_is_void_like >, - thrust::detail::true_type - >::type -{ -}; // end is_output_iterator - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/type_traits/minimum_type.h b/compat/thrust/detail/type_traits/minimum_type.h deleted file mode 100644 index aaa011e..0000000 --- a/compat/thrust/detail/type_traits/minimum_type.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ - -namespace detail -{ - -namespace minimum_type_detail -{ - -// -// Returns the minimum type or is empty -// if T1 and T2 are unrelated. -// -template struct minimum_type_impl {}; - -template -struct minimum_type_impl -{ - typedef T2 type; -}; // end minimum_type_impl - -template -struct minimum_type_impl -{ - typedef T1 type; -}; // end minimum_type_impl - -template -struct minimum_type_impl -{ - typedef T1 type; -}; // end minimum_type_impl - -template -struct primitive_minimum_type - : minimum_type_detail::minimum_type_impl< - T1, - T2, - ::thrust::detail::is_convertible::value, - ::thrust::detail::is_convertible::value - > -{ -}; // end primitive_minimum_type - -// because some types are not convertible (even to themselves) -// specialize primitive_minimum_type for when both types are identical -template -struct primitive_minimum_type -{ - typedef T type; -}; // end primitive_minimum_type - -// XXX this belongs somewhere more general -struct any_conversion -{ - template operator T (void); -}; - -} // end minimum_type_detail - -template - struct minimum_type; - -// base case -template - struct minimum_type - : minimum_type_detail::primitive_minimum_type -{}; - -template - struct lazy_minimum_type - : minimum_type< - typename T1::type, - typename T2::type - > -{}; - -// carefully avoid referring to a nested ::type which may not exist -template - struct minimum_type - : lazy_minimum_type< - lazy_minimum_type< - lazy_minimum_type< - minimum_type< - T1,T2 - >, - minimum_type< - T3,T4 - > - >, - lazy_minimum_type< - minimum_type< - T5,T6 - >, - minimum_type< - T7,T8 - > - > - >, - lazy_minimum_type< - lazy_minimum_type< - minimum_type< - T9,T10 - >, - minimum_type< - T11,T12 - > - >, - lazy_minimum_type< - minimum_type< - T13,T14 - >, - minimum_type< - T15,T16 - > - > - > - > -{}; - -} // end detail - -} // end thrust - diff --git a/compat/thrust/detail/type_traits/pointer_traits.h b/compat/thrust/detail/type_traits/pointer_traits.h deleted file mode 100644 index a0b5dc6..0000000 --- a/compat/thrust/detail/type_traits/pointer_traits.h +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template struct pointer_element; - -template class Ptr, typename Arg> - struct pointer_element > -{ - typedef Arg type; -}; - -template class Ptr, typename Arg1, typename Arg2> - struct pointer_element > -{ - typedef Arg1 type; -}; - -template class Ptr, typename Arg1, typename Arg2, typename Arg3> - struct pointer_element > -{ - typedef Arg1 type; -}; - -template class Ptr, typename Arg1, typename Arg2, typename Arg3, typename Arg4> - struct pointer_element > -{ - typedef Arg1 type; -}; - -template class Ptr, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> - struct pointer_element > -{ - typedef Arg1 type; -}; - -template - struct pointer_element -{ - typedef T type; -}; - -template - struct pointer_difference -{ - typedef typename Ptr::difference_type type; -}; - -template - struct pointer_difference -{ - typedef std::ptrdiff_t type; -}; - -template struct rebind_pointer; - -template - struct rebind_pointer -{ - typedef U* type; -}; - -template class Ptr, typename Arg, typename T> - struct rebind_pointer,T> -{ - typedef Ptr type; -}; - -template class Ptr, typename Arg1, typename Arg2, typename T> - struct rebind_pointer,T> -{ - typedef Ptr type; -}; - -template class Ptr, typename Arg1, typename Arg2, typename Arg3, typename T> - struct rebind_pointer,T> -{ - typedef Ptr type; -}; - -template class Ptr, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename T> - struct rebind_pointer,T> -{ - typedef Ptr type; -}; - -// XXX this should probably be renamed native_type or similar -__THRUST_DEFINE_HAS_NESTED_TYPE(has_raw_pointer, raw_pointer) - -namespace pointer_traits_detail -{ - -template struct pointer_raw_pointer_impl {}; - -template - struct pointer_raw_pointer_impl -{ - typedef T* type; -}; - -template - struct pointer_raw_pointer_impl::value>::type> -{ - typedef typename Ptr::raw_pointer type; -}; - -} // end pointer_traits_detail - -template - struct pointer_raw_pointer - : pointer_traits_detail::pointer_raw_pointer_impl -{}; - -namespace pointer_traits_detail -{ - -template - struct capture_address -{ - template - __host__ __device__ - capture_address(T &r) - : m_addr(&r) - {} - - inline __host__ __device__ - Void *operator&() const - { - return m_addr; - } - - Void *m_addr; -}; - -// metafunction to compute the type of pointer_to's parameter below -template - struct pointer_to_param - : thrust::detail::eval_if< - thrust::detail::is_void::value, - thrust::detail::identity_ >, - thrust::detail::add_reference - > -{}; - -} - -template - struct pointer_traits -{ - typedef Ptr pointer; - typedef typename pointer_element::type element_type; - typedef typename pointer_difference::type difference_type; - - template - struct rebind - { - typedef typename rebind_pointer::type other; - }; - - __host__ __device__ - inline static pointer pointer_to(typename pointer_traits_detail::pointer_to_param::type r) - { - // XXX this is supposed to be pointer::pointer_to(&r); (i.e., call a static member function of pointer called pointer_to) - // assume that pointer has a constructor from raw pointer instead - - return pointer(&r); - } - - // thrust additions follow - typedef typename pointer_raw_pointer::type raw_pointer; - - __host__ __device__ - inline static raw_pointer get(pointer ptr) - { - return ptr.get(); - } -}; - -template - struct pointer_traits -{ - typedef T* pointer; - typedef T element_type; - typedef typename pointer_difference::type difference_type; - - template - struct rebind - { - typedef U* other; - }; - - __host__ __device__ - inline static pointer pointer_to(typename pointer_traits_detail::pointer_to_param::type r) - { - return &r; - } - - // thrust additions follow - typedef typename pointer_raw_pointer::type raw_pointer; - - __host__ __device__ - inline static raw_pointer get(pointer ptr) - { - return ptr; - } -}; - -template - struct is_pointer_convertible - : thrust::detail::and_< - thrust::detail::is_convertible< - typename pointer_element::type *, - typename pointer_element::type * - >, - thrust::detail::is_convertible< - typename iterator_system::type, - typename iterator_system::type - > - > -{}; - -// this could be a lot better, but for our purposes, it's probably -// sufficient just to check if pointer_raw_pointer has meaning -template - struct is_thrust_pointer - : is_metafunction_defined > -{}; - -// avoid inspecting traits of the arguments if they aren't known to be pointers -template - struct lazy_is_pointer_convertible - : thrust::detail::eval_if< - is_thrust_pointer::value && is_thrust_pointer::value, - is_pointer_convertible, - thrust::detail::identity_ - > -{}; - -template - struct enable_if_pointer_is_convertible - : thrust::detail::enable_if< - lazy_is_pointer_convertible::type::value, - T - > -{}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/type_traits/result_of.h b/compat/thrust/detail/type_traits/result_of.h deleted file mode 100644 index e30b4fd..0000000 --- a/compat/thrust/detail/type_traits/result_of.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template struct result_of; - -// specialization for unary invocations of things which have result_type -template - struct result_of< - Functor(Arg1), - typename thrust::detail::enable_if::value>::type - > -{ - typedef typename Functor::result_type type; -}; // end result_of - -// specialization for binary invocations of things which have result_type -template - struct result_of< - Functor(Arg1,Arg2), - typename thrust::detail::enable_if::value>::type - > -{ - typedef typename Functor::result_type type; -}; - -} // end detail -} // end thrust - diff --git a/compat/thrust/detail/uninitialized_copy.inl b/compat/thrust/detail/uninitialized_copy.inl deleted file mode 100644 index a01dca5..0000000 --- a/compat/thrust/detail/uninitialized_copy.inl +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file uninitialized_copy.inl - * \brief Inline file for uninitialized_copy.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - ForwardIterator uninitialized_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - ForwardIterator result) -{ - using thrust::system::detail::generic::uninitialized_copy; - return uninitialized_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result); -} // end uninitialized_copy() - - -template - ForwardIterator uninitialized_copy_n(const thrust::detail::execution_policy_base &exec, - InputIterator first, - Size n, - ForwardIterator result) -{ - using thrust::system::detail::generic::uninitialized_copy_n; - return uninitialized_copy_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, result); -} // end uninitialized_copy_n() - - -template - ForwardIterator uninitialized_copy(InputIterator first, - InputIterator last, - ForwardIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::uninitialized_copy(select_system(system1,system2), first, last, result); -} // end uninitialized_copy() - - -template - ForwardIterator uninitialized_copy_n(InputIterator first, - Size n, - ForwardIterator result) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::uninitialized_copy_n(select_system(system1,system2), first, n, result); -} // end uninitialized_copy_n() - - -} // end thrust - - diff --git a/compat/thrust/detail/uninitialized_fill.inl b/compat/thrust/detail/uninitialized_fill.inl deleted file mode 100644 index 3545de5..0000000 --- a/compat/thrust/detail/uninitialized_fill.inl +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file uninitialized_fill.inl - * \brief Inline file for uninitialized_fill.h. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template - void uninitialized_fill(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &x) -{ - using thrust::system::detail::generic::uninitialized_fill; - return uninitialized_fill(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, x); -} // end uninitialized_fill() - - -template - ForwardIterator uninitialized_fill_n(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - Size n, - const T &x) -{ - using thrust::system::detail::generic::uninitialized_fill_n; - return uninitialized_fill_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, x); -} // end uninitialized_fill_n() - - -template - void uninitialized_fill(ForwardIterator first, - ForwardIterator last, - const T &x) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - thrust::uninitialized_fill(select_system(system), first, last, x); -} // end uninitialized_fill() - - -template - ForwardIterator uninitialized_fill_n(ForwardIterator first, - Size n, - const T &x) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::uninitialized_fill_n(select_system(system), first, n, x); -} // end uninitialized_fill_n() - - -} // end thrust - diff --git a/compat/thrust/detail/unique.inl b/compat/thrust/detail/unique.inl deleted file mode 100644 index e90187d..0000000 --- a/compat/thrust/detail/unique.inl +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file unique.inl - * \brief Inline file for unique.h. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -template -ForwardIterator unique(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::unique; - return unique(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last); -} // end unique() - - -template -ForwardIterator unique(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::unique; - return unique(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, binary_pred); -} // end unique() - - -template -OutputIterator unique_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator output) -{ - using thrust::system::detail::generic::unique_copy; - return unique_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output); -} // end unique_copy() - - -template -OutputIterator unique_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::unique_copy; - return unique_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output, binary_pred); -} // end unique_copy() - - -template - thrust::pair - unique_by_key(const thrust::detail::execution_policy_base &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first) -{ - using thrust::system::detail::generic::unique_by_key; - return unique_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key(const thrust::detail::execution_policy_base &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::unique_by_key; - return unique_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, binary_pred); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output) -{ - using thrust::system::detail::generic::unique_by_key_copy; - return unique_by_key_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output); -} // end unique_by_key_copy() - - -template - thrust::pair - unique_by_key_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::unique_by_key_copy; - return unique_by_key_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output, binary_pred); -} // end unique_by_key_copy() - - -template - ForwardIterator unique(ForwardIterator first, - ForwardIterator last) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::unique(select_system(system), first, last); -} // end unique() - - -template - ForwardIterator unique(ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System; - - System system; - - return thrust::unique(select_system(system), first, last, binary_pred); -} // end unique() - - -template - OutputIterator unique_copy(InputIterator first, - InputIterator last, - OutputIterator output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::unique_copy(select_system(system1,system2), first, last, output); -} // end unique_copy() - - -template - OutputIterator unique_copy(InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::unique_copy(select_system(system1,system2), first, last, output, binary_pred); -} // end unique_copy() - - -template - thrust::pair - unique_by_key(ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::unique_by_key(select_system(system1,system2), keys_first, keys_last, values_first); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key(ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - System1 system1; - System2 system2; - - return thrust::unique_by_key(select_system(system1,system2), keys_first, keys_last, values_first, binary_pred); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key_copy(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::unique_by_key_copy(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output); -} // end unique_by_key_copy() - - -template - thrust::pair - unique_by_key_copy(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - using thrust::system::detail::generic::select_system; - - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - typedef typename thrust::iterator_system::type System3; - typedef typename thrust::iterator_system::type System4; - - System1 system1; - System2 system2; - System3 system3; - System4 system4; - - return thrust::unique_by_key_copy(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output, binary_pred); -} // end unique_by_key_copy() - - -} // end namespace thrust - diff --git a/compat/thrust/detail/use_default.h b/compat/thrust/detail/use_default.h deleted file mode 100644 index c6eb66e..0000000 --- a/compat/thrust/detail/use_default.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ - -struct use_default {}; - -} // end thrust - diff --git a/compat/thrust/detail/util/align.h b/compat/thrust/detail/util/align.h deleted file mode 100644 index 10f107a..0000000 --- a/compat/thrust/detail/util/align.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -// functions to handle memory alignment - -namespace thrust -{ -namespace detail -{ -namespace util -{ - -template -T * align_up(T * ptr, detail::uintptr_t bytes) -{ - return (T *) ( bytes * (((detail::uintptr_t) ptr + (bytes - 1)) / bytes) ); -} - -template -T * align_down(T * ptr, detail::uintptr_t bytes) -{ - return (T *) ( bytes * (detail::uintptr_t(ptr) / bytes) ); -} - -template -bool is_aligned(T * ptr, detail::uintptr_t bytes = sizeof(T)) -{ - return detail::uintptr_t(ptr) % bytes == 0; -} - -} // end namespace util -} // end namespace detail -} // end namespace thrust - diff --git a/compat/thrust/detail/util/blocking.h b/compat/thrust/detail/util/blocking.h deleted file mode 100644 index 3bb78a6..0000000 --- a/compat/thrust/detail/util/blocking.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -//functions to support blocking - -namespace thrust -{ - -namespace detail -{ - -namespace util -{ - -// x/y rounding towards +infinity for integers, used to determine # of blocks/warps etc. -template - inline __host__ __device__ L divide_ri(const L x, const R y) -{ - return (x + (y - 1)) / y; -} - -// x/y rounding towards zero for integers, used to determine # of blocks/warps etc. -template - inline __host__ __device__ L divide_rz(const L x, const R y) -{ - return x / y; -} - -// round x towards infinity to the next multiple of y -template - inline __host__ __device__ L round_i(const L x, const R y){ return y * divide_ri(x, y); } - -// round x towards zero to the next multiple of y -template - inline __host__ __device__ L round_z(const L x, const R y){ return y * divide_rz(x, y); } - -} // end namespace util - -} // end namespace detail - -} // end namespace thrust - diff --git a/compat/thrust/detail/vector_base.h b/compat/thrust/detail/vector_base.h deleted file mode 100644 index 6974eab..0000000 --- a/compat/thrust/detail/vector_base.h +++ /dev/null @@ -1,534 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file vector_base.h - * \brief Defines the interface to a base class for - * host_vector & device_vector. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -template - class vector_base -{ - private: - typedef thrust::detail::contiguous_storage storage_type; - - public: - // typedefs - typedef typename storage_type::value_type value_type; - typedef typename storage_type::pointer pointer; - typedef typename storage_type::const_pointer const_pointer; - typedef typename storage_type::reference reference; - typedef typename storage_type::const_reference const_reference; - typedef typename storage_type::size_type size_type; - typedef typename storage_type::difference_type difference_type; - typedef typename storage_type::allocator_type allocator_type; - - typedef typename storage_type::iterator iterator; - typedef typename storage_type::const_iterator const_iterator; - - typedef thrust::reverse_iterator reverse_iterator; - typedef thrust::reverse_iterator const_reverse_iterator; - - /*! This constructor creates an empty vector_base. - */ - vector_base(void); - - /*! This constructor creates a vector_base with default-constructed - * elements. - * \param n The number of elements to create. - */ - explicit vector_base(size_type n); - - /*! This constructor creates a vector_base with copies - * of an exemplar element. - * \param n The number of elements to initially create. - * \param value An element to copy. - */ - explicit vector_base(size_type n, const value_type &value); - - /*! Copy constructor copies from an exemplar vector_base. - * \param v The vector_base to copy. - */ - vector_base(const vector_base &v); - - /*! assign operator makes a copy of an exemplar vector_base. - * \param v The vector_base to copy. - */ - vector_base &operator=(const vector_base &v); - - /*! Copy constructor copies from an exemplar vector_base with different - * type. - * \param v The vector_base to copy. - */ - template - vector_base(const vector_base &v); - - /*! assign operator makes a copy of an exemplar vector_base with different - * type. - * \param v The vector_base to copy. - */ - template - vector_base &operator=(const vector_base &v); - - /*! Copy constructor copies from an exemplar std::vector. - * \param v The std::vector to copy. - * XXX TODO: Make this method redundant with a properly templatized constructor. - * We would like to copy from a vector whose element type is anything - * assignable to value_type. - */ - template - vector_base(const std::vector &v); - - /*! assign operator makes a copy of an exemplar std::vector. - * \param v The vector to copy. - * XXX TODO: Templatize this assign on the type of the vector to copy from. - * We would like to copy from a vector whose element type is anything - * assignable to value_type. - */ - template - vector_base &operator=(const std::vector &v); - - /*! This constructor builds a vector_base from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - vector_base(InputIterator first, InputIterator last); - - /*! The destructor erases the elements. - */ - ~vector_base(void); - - /*! \brief Resizes this vector_base to the specified number of elements. - * \param new_size Number of elements this vector_base should contain. - * \throw std::length_error If n exceeds max_size9). - * - * This method will resize this vector_base to the specified number of - * elements. If the number is smaller than this vector_base's current - * size this vector_base is truncated, otherwise this vector_base is - * extended and new elements are default constructed. - */ - void resize(size_type new_size); - - /*! \brief Resizes this vector_base to the specified number of elements. - * \param new_size Number of elements this vector_base should contain. - * \param x Data with which new elements should be populated. - * \throw std::length_error If n exceeds max_size(). - * - * This method will resize this vector_base to the specified number of - * elements. If the number is smaller than this vector_base's current - * size this vector_base is truncated, otherwise this vector_base is - * extended and new elements are populated with given data. - */ - void resize(size_type new_size, const value_type &x); - - /*! Returns the number of elements in this vector_base. - */ - size_type size(void) const; - - /*! Returns the size() of the largest possible vector_base. - * \return The largest possible return value of size(). - */ - size_type max_size(void) const; - - /*! \brief If n is less than or equal to capacity(), this call has no effect. - * Otherwise, this method is a request for allocation of additional memory. If - * the request is successful, then capacity() is greater than or equal to - * n; otherwise, capacity() is unchanged. In either case, size() is unchanged. - * \throw std::length_error If n exceeds max_size(). - */ - void reserve(size_type n); - - /*! Returns the number of elements which have been reserved in this - * vector_base. - */ - size_type capacity(void) const; - - /*! This method shrinks the capacity of this vector_base to exactly - * fit its elements. - */ - void shrink_to_fit(void); - - /*! \brief Subscript access to the data contained in this vector_dev. - * \param n The index of the element for which data should be accessed. - * \return Read/write reference to data. - * - * This operator allows for easy, array-style, data access. - * Note that data access with this operator is unchecked and - * out_of_range lookups are not defined. - */ - reference operator[](size_type n); - - /*! \brief Subscript read access to the data contained in this vector_dev. - * \param n The index of the element for which data should be accessed. - * \return Read reference to data. - * - * This operator allows for easy, array-style, data access. - * Note that data access with this operator is unchecked and - * out_of_range lookups are not defined. - */ - const_reference operator[](size_type n) const; - - /*! This method returns an iterator pointing to the beginning of - * this vector_base. - * \return mStart - */ - iterator begin(void); - - /*! This method returns a const_iterator pointing to the beginning - * of this vector_base. - * \return mStart - */ - const_iterator begin(void) const; - - /*! This method returns a const_iterator pointing to the beginning - * of this vector_base. - * \return mStart - */ - const_iterator cbegin(void) const; - - /*! This method returns a reverse_iterator pointing to the beginning of - * this vector_base's reversed sequence. - * \return A reverse_iterator pointing to the beginning of this - * vector_base's reversed sequence. - */ - reverse_iterator rbegin(void); - - /*! This method returns a const_reverse_iterator pointing to the beginning of - * this vector_base's reversed sequence. - * \return A const_reverse_iterator pointing to the beginning of this - * vector_base's reversed sequence. - */ - const_reverse_iterator rbegin(void) const; - - /*! This method returns a const_reverse_iterator pointing to the beginning of - * this vector_base's reversed sequence. - * \return A const_reverse_iterator pointing to the beginning of this - * vector_base's reversed sequence. - */ - const_reverse_iterator crbegin(void) const; - - /*! This method returns an iterator pointing to one element past the - * last of this vector_base. - * \return begin() + size(). - */ - iterator end(void); - - /*! This method returns a const_iterator pointing to one element past the - * last of this vector_base. - * \return begin() + size(). - */ - const_iterator end(void) const; - - /*! This method returns a const_iterator pointing to one element past the - * last of this vector_base. - * \return begin() + size(). - */ - const_iterator cend(void) const; - - /*! This method returns a reverse_iterator pointing to one element past the - * last of this vector_base's reversed sequence. - * \return rbegin() + size(). - */ - reverse_iterator rend(void); - - /*! This method returns a const_reverse_iterator pointing to one element past the - * last of this vector_base's reversed sequence. - * \return rbegin() + size(). - */ - const_reverse_iterator rend(void) const; - - /*! This method returns a const_reverse_iterator pointing to one element past the - * last of this vector_base's reversed sequence. - * \return rbegin() + size(). - */ - const_reverse_iterator crend(void) const; - - /*! This method returns a const_reference referring to the first element of this - * vector_base. - * \return The first element of this vector_base. - */ - const_reference front(void) const; - - /*! This method returns a reference pointing to the first element of this - * vector_base. - * \return The first element of this vector_base. - */ - reference front(void); - - /*! This method returns a const reference pointing to the last element of - * this vector_base. - * \return The last element of this vector_base. - */ - const_reference back(void) const; - - /*! This method returns a reference referring to the last element of - * this vector_dev. - * \return The last element of this vector_base. - */ - reference back(void); - - /*! This method returns a pointer to this vector_base's first element. - * \return A pointer to the first element of this vector_base. - */ - pointer data(void); - - /*! This method returns a const_pointer to this vector_base's first element. - * \return a const_pointer to the first element of this vector_base. - */ - const_pointer data(void) const; - - /*! This method resizes this vector_base to 0. - */ - void clear(void); - - /*! This method returns true iff size() == 0. - * \return true if size() == 0; false, otherwise. - */ - bool empty(void) const; - - /*! This method appends the given element to the end of this vector_base. - * \param x The element to append. - */ - void push_back(const value_type &x); - - /*! This method erases the last element of this vector_base, invalidating - * all iterators and references to it. - */ - void pop_back(void); - - /*! This method swaps the contents of this vector_base with another vector_base. - * \param v The vector_base with which to swap. - */ - void swap(vector_base &v); - - /*! This method removes the element at position pos. - * \param pos The position of the element of interest. - * \return An iterator pointing to the new location of the element that followed the element - * at position pos. - */ - iterator erase(iterator pos); - - /*! This method removes the range of elements [first,last) from this vector_base. - * \param first The beginning of the range of elements to remove. - * \param last The end of the range of elements to remove. - * \return An iterator pointing to the new location of the element that followed the last - * element in the sequence [first,last). - */ - iterator erase(iterator first, iterator last); - - /*! This method inserts a single copy of a given exemplar value at the - * specified position in this vector_base. - * \param position The insertion position. - * \param x The exemplar element to copy & insert. - * \return An iterator pointing to the newly inserted element. - */ - iterator insert(iterator position, const T &x); - - /*! This method inserts a copy of an exemplar value to a range at the - * specified position in this vector_base. - * \param position The insertion position - * \param n The number of insertions to perform. - * \param x The value to replicate and insert. - */ - void insert(iterator position, size_type n, const T &x); - - /*! This method inserts a copy of an input range at the specified position - * in this vector_base. - * \param position The insertion position. - * \param first The beginning of the range to copy. - * \param last The end of the range to copy. - * - * \tparam InputIterator is a model of Assignable. - */ - template - void insert(iterator position, InputIterator first, InputIterator last); - - /*! This version of \p assign replicates a given exemplar - * \p n times into this vector_base. - * \param n The number of times to copy \p x. - * \param x The exemplar element to replicate. - */ - void assign(size_type n, const T &x); - - /*! This version of \p assign makes this vector_base a copy of a given input range. - * \param first The beginning of the range to copy. - * \param last The end of the range to copy. - * - * \tparam InputIterator is a model of Input Iterator. - */ - template - void assign(InputIterator first, InputIterator last); - - /*! This method returns a copy of this vector's allocator. - * \return A copy of the alloctor used by this vector. - */ - allocator_type get_allocator(void) const; - - protected: - // Our storage - storage_type m_storage; - - // The size of this vector_base, in number of elements. - size_type m_size; - - private: - // these methods resolve the ambiguity of the constructor template of form (Iterator, Iterator) - template - void init_dispatch(IteratorOrIntegralType begin, IteratorOrIntegralType end, false_type); - - template - void init_dispatch(IteratorOrIntegralType n, IteratorOrIntegralType value, true_type); - - template - void range_init(InputIterator first, InputIterator last); - - template - void range_init(InputIterator first, InputIterator last, thrust::incrementable_traversal_tag); - - template - void range_init(ForwardIterator first, ForwardIterator last, thrust::random_access_traversal_tag); - - void default_init(size_type n); - - void fill_init(size_type n, const T &x); - - // these methods resolve the ambiguity of the insert() template of form (iterator, InputIterator, InputIterator) - template - void insert_dispatch(iterator position, InputIteratorOrIntegralType first, InputIteratorOrIntegralType last, false_type); - - // these methods resolve the ambiguity of the insert() template of form (iterator, InputIterator, InputIterator) - template - void insert_dispatch(iterator position, InputIteratorOrIntegralType n, InputIteratorOrIntegralType x, true_type); - - // this method appends n default-constructed elements at the end - void append(size_type n); - - // this method performs insertion from a fill value - void fill_insert(iterator position, size_type n, const T &x); - - // this method performs insertion from a range - template - void copy_insert(iterator position, InputIterator first, InputIterator last); - - // these methods resolve the ambiguity of the assign() template of form (InputIterator, InputIterator) - template - void assign_dispatch(InputIterator first, InputIterator last, false_type); - - // these methods resolve the ambiguity of the assign() template of form (InputIterator, InputIterator) - template - void assign_dispatch(Integral n, Integral x, true_type); - - // this method performs assignment from a range - template - void range_assign(InputIterator first, InputIterator last); - - // this method performs assignment from a range of RandomAccessIterators - template - void range_assign(RandomAccessIterator first, RandomAccessIterator last, thrust::random_access_traversal_tag); - - // this method performs assignment from a range of InputIterators - template - void range_assign(InputIterator first, InputIterator last, thrust::incrementable_traversal_tag); - - // this method performs assignment from a fill value - void fill_assign(size_type n, const T &x); - - // this method allocates new storage and construct copies the given range - template - void allocate_and_copy(size_type requested_size, - ForwardIterator first, ForwardIterator last, - storage_type &new_storage); -}; // end vector_base - -} // end detail - -/*! This function assigns the contents of vector a to vector b and the - * contents of vector b to vector a. - * - * \param a The first vector of interest. After completion, the contents - * of b will be returned here. - * \param b The second vector of interest. After completion, the contents - * of a will be returned here. - */ -template - void swap(detail::vector_base &a, - detail::vector_base &b); - - -/*! This operator allows comparison between two vectors. - * \param lhs The first \p vector to compare. - * \param rhs The second \p vector to compare. - * \return \c true if and only if each corresponding element in either - * \p vector equals the other; \c false, otherwise. - */ -template -bool operator==(const detail::vector_base& lhs, - const detail::vector_base& rhs); - -template -bool operator==(const detail::vector_base& lhs, - const std::vector& rhs); - -template -bool operator==(const std::vector& lhs, - const detail::vector_base& rhs); - -/*! This operator allows comparison between two vectors. - * \param lhs The first \p vector to compare. - * \param rhs The second \p vector to compare. - * \return \c false if and only if each corresponding element in either - * \p vector equals the other; \c true, otherwise. - */ -template -bool operator!=(const detail::vector_base& lhs, - const detail::vector_base& rhs); - -template -bool operator!=(const detail::vector_base& lhs, - const std::vector& rhs); - -template -bool operator!=(const std::vector& lhs, - const detail::vector_base& rhs); - -} // end thrust - -#include - diff --git a/compat/thrust/detail/vector_base.inl b/compat/thrust/detail/vector_base.inl deleted file mode 100644 index 24e6466..0000000 --- a/compat/thrust/detail/vector_base.inl +++ /dev/null @@ -1,1203 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file vector_base.inl - * \brief Inline file for vector_base.h. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace thrust -{ - -namespace detail -{ - -template - vector_base - ::vector_base(void) - :m_storage(), - m_size(0) -{ - ; -} // end vector_base::vector_base() - -template - vector_base - ::vector_base(size_type n) - :m_storage(), - m_size(0) -{ - default_init(n); -} // end vector_base::vector_base() - -template - vector_base - ::vector_base(size_type n, const value_type &value) - :m_storage(), - m_size(0) -{ - fill_init(n,value); -} // end vector_base::vector_base() - -template - vector_base - ::vector_base(const vector_base &v) - :m_storage(), - m_size(0) -{ - range_init(v.begin(), v.end()); -} // end vector_base::vector_base() - -template - vector_base & - vector_base - ::operator=(const vector_base &v) -{ - if(this != &v) - { - assign(v.begin(), v.end()); - } // end if - - return *this; -} // end vector_base::operator=() - -template - template - vector_base - ::vector_base(const vector_base &v) - :m_storage(), - m_size(0) -{ - range_init(v.begin(), v.end()); -} // end vector_base::vector_base() - -template - template - vector_base & - vector_base - ::operator=(const vector_base &v) -{ - assign(v.begin(), v.end()); - - return *this; -} // end vector_base::operator=() - -template - template - vector_base - ::vector_base(const std::vector &v) - :m_storage(), - m_size(0) -{ - range_init(v.begin(), v.end()); -} // end vector_base::vector_base() - -template - template - vector_base & - vector_base - ::operator=(const std::vector &v) -{ - assign(v.begin(), v.end()); - - return *this; -} // end vector_base::operator=() - -template - template - void vector_base - ::init_dispatch(IteratorOrIntegralType n, - IteratorOrIntegralType value, - true_type) -{ - fill_init(n,value); -} // end vector_base::init_dispatch() - -template - void vector_base - ::default_init(size_type n) -{ - if(n > 0) - { - m_storage.allocate(n); - m_size = n; - - m_storage.default_construct_n(begin(), size()); - } // end if -} // end vector_base::default_init() - -template - void vector_base - ::fill_init(size_type n, const T &x) -{ - if(n > 0) - { - m_storage.allocate(n); - m_size = n; - - m_storage.uninitialized_fill_n(begin(), size(), x); - } // end if -} // end vector_base::fill_init() - -template - template - void vector_base - ::init_dispatch(InputIterator first, - InputIterator last, - false_type) -{ - range_init(first, last); -} // end vector_base::init_dispatch() - -template - template - void vector_base - ::range_init(InputIterator first, - InputIterator last) -{ - range_init(first, last, - typename thrust::iterator_traversal::type()); -} // end vector_base::range_init() - -template - template - void vector_base - ::range_init(InputIterator first, - InputIterator last, - thrust::incrementable_traversal_tag) -{ - for(; first != last; ++first) - push_back(*first); -} // end vector_base::range_init() - -template - template - void vector_base - ::range_init(ForwardIterator first, - ForwardIterator last, - thrust::random_access_traversal_tag) -{ - size_type new_size = thrust::distance(first, last); - - allocate_and_copy(new_size, first, last, m_storage); - m_size = new_size; -} // end vector_base::range_init() - -template - template - vector_base - ::vector_base(InputIterator first, - InputIterator last) - :m_storage(), - m_size(0) -{ - // check the type of InputIterator: if it's an integral type, - // we need to interpret this call as (size_type, value_type) - typedef thrust::detail::is_integral Integer; - - init_dispatch(first, last, Integer()); -} // end vector_basee::vector_base() - -template - void vector_base - ::resize(size_type new_size) -{ - if(new_size < size()) - { - iterator new_end = begin(); - thrust::advance(new_end, new_size); - erase(new_end, end()); - } // end if - else - { - append(new_size - size()); - } // end else -} // end vector_base::resize() - -template - void vector_base - ::resize(size_type new_size, const value_type &x) -{ - if(new_size < size()) - { - iterator new_end = begin(); - thrust::advance(new_end, new_size); - erase(new_end, end()); - } // end if - else - { - insert(end(), new_size - size(), x); - } // end else -} // end vector_base::resize() - -template - typename vector_base::size_type - vector_base - ::size(void) const -{ - return m_size; -} // end vector_base::size() - -template - typename vector_base::size_type - vector_base - ::max_size(void) const -{ - return m_storage.max_size(); -} // end vector_base::max_size() - -template - void vector_base - ::reserve(size_type n) -{ - if(n > capacity()) - { - allocate_and_copy(n, begin(), end(), m_storage); - } // end if -} // end vector_base::reserve() - -template - typename vector_base::size_type - vector_base - ::capacity(void) const -{ - return m_storage.size(); -} // end vector_base::capacity() - -template - void vector_base - ::shrink_to_fit(void) -{ - // use the swap trick - vector_base(*this).swap(*this); -} // end vector_base::shrink_to_fit() - -template - typename vector_base::reference - vector_base - ::operator[](const size_type n) -{ - return m_storage[n]; -} // end vector_base::operator[] - -template - typename vector_base::const_reference - vector_base - ::operator[](const size_type n) const -{ - return m_storage[n]; -} // end vector_base::operator[] - -template - typename vector_base::iterator - vector_base - ::begin(void) -{ - return m_storage.begin(); -} // end vector_base::begin() - -template - typename vector_base::const_iterator - vector_base - ::begin(void) const -{ - return m_storage.begin(); -} // end vector_base::begin() - -template - typename vector_base::const_iterator - vector_base - ::cbegin(void) const -{ - return begin(); -} // end vector_base::cbegin() - -template - typename vector_base::reverse_iterator - vector_base - ::rbegin(void) -{ - return reverse_iterator(end()); -} // end vector_base::rbegin() - -template - typename vector_base::const_reverse_iterator - vector_base - ::rbegin(void) const -{ - return const_reverse_iterator(end()); -} // end vector_base::rbegin() - -template - typename vector_base::const_reverse_iterator - vector_base - ::crbegin(void) const -{ - return rbegin(); -} // end vector_base::crbegin() - -template - typename vector_base::iterator - vector_base - ::end(void) -{ - iterator result = begin(); - thrust::advance(result, size()); - return result; -} // end vector_base::end() - -template - typename vector_base::const_iterator - vector_base - ::end(void) const -{ - const_iterator result = begin(); - thrust::advance(result, size()); - return result; -} // end vector_base::end() - -template - typename vector_base::const_iterator - vector_base - ::cend(void) const -{ - return end(); -} // end vector_base::cend() - -template - typename vector_base::reverse_iterator - vector_base - ::rend(void) -{ - return reverse_iterator(begin()); -} // end vector_base::rend() - -template - typename vector_base::const_reverse_iterator - vector_base - ::rend(void) const -{ - return const_reverse_iterator(begin()); -} // end vector_base::rend() - -template - typename vector_base::const_reverse_iterator - vector_base - ::crend(void) const -{ - return rend(); -} // end vector_base::crend() - -template - typename vector_base::const_reference - vector_base - ::front(void) const -{ - return *begin(); -} // end vector_base::front() - -template - typename vector_base::reference - vector_base - ::front(void) -{ - return *begin(); -} // end vector_base::front() - -template - typename vector_base::const_reference - vector_base - ::back(void) const -{ - const_iterator ptr_to_back = end(); - --ptr_to_back; - return *ptr_to_back; -} // end vector_base::vector_base - -template - typename vector_base::reference - vector_base - ::back(void) -{ - iterator ptr_to_back = end(); - --ptr_to_back; - return *ptr_to_back; -} // end vector_base::vector_base - -template - typename vector_base::pointer - vector_base - ::data(void) -{ - return &front(); -} // end vector_base::data() - -template - typename vector_base::const_pointer - vector_base - ::data(void) const -{ - return &front(); -} // end vector_base::data() - -template - vector_base - ::~vector_base(void) -{ - // destroy every living thing - m_storage.destroy(begin(),end()); -} // end vector_base::~vector_base() - -template - void vector_base - ::clear(void) -{ - resize(0); -} // end vector_base::~vector_dev() - -template - bool vector_base - ::empty(void) const -{ - return size() == 0; -} // end vector_base::empty(); - -template - void vector_base - ::push_back(const value_type &x) -{ - insert(end(), x); -} // end vector_base::push_back() - -template - void vector_base - ::pop_back(void) -{ - iterator e = end(); - iterator ptr_to_back = e; - --ptr_to_back; - m_storage.destroy(ptr_to_back, e); - --m_size; -} // end vector_base::pop_back() - -template - typename vector_base::iterator vector_base - ::erase(iterator pos) -{ - iterator end = pos; - ++end; - return erase(pos,end); -} // end vector_base::erase() - -template - typename vector_base::iterator vector_base - ::erase(iterator first, iterator last) -{ - // overlap copy the range [last,end()) to first - // XXX this copy only potentially overlaps - iterator i = thrust::detail::overlapped_copy(last, end(), first); - - // destroy everything after i - m_storage.destroy(i, end()); - - // modify our size - m_size -= (last - first); - - // return an iterator pointing to the position of the first element - // following the erased range - return first; -} // end vector_base::erase() - -template - void vector_base - ::swap(vector_base &v) -{ - thrust::swap(m_storage, v.m_storage); - thrust::swap(m_size, v.m_size); -} // end vector_base::swap() - -template - void vector_base - ::assign(size_type n, const T &x) -{ - fill_assign(n, x); -} // end vector_base::assign() - -template - template - void vector_base - ::assign(InputIterator first, InputIterator last) -{ - // we could have received assign(n, x), so disambiguate on the - // type of InputIterator - typedef typename thrust::detail::is_integral integral; - - assign_dispatch(first, last, integral()); -} // end vector_base::assign() - -template - typename vector_base::allocator_type - vector_base - ::get_allocator(void) const -{ - return m_storage.get_allocator(); -} // end vector_base::get_allocator() - -template - typename vector_base::iterator - vector_base - ::insert(iterator position, const T &x) -{ - // find the index of the insertion - size_type index = thrust::distance(begin(), position); - - // make the insertion - insert(position, 1, x); - - // return an iterator pointing back to position - iterator result = begin(); - thrust::advance(result, index); - return result; -} // end vector_base::insert() - -template - void vector_base - ::insert(iterator position, size_type n, const T &x) -{ - fill_insert(position, n, x); -} // end vector_base::insert() - -template - template - void vector_base - ::insert(iterator position, InputIterator first, InputIterator last) -{ - // we could have received insert(position, n, x), so disambiguate on the - // type of InputIterator - typedef typename thrust::detail::is_integral integral; - - insert_dispatch(position, first, last, integral()); -} // end vector_base::insert() - -template - template - void vector_base - ::assign_dispatch(InputIterator first, InputIterator last, false_type) -{ - range_assign(first, last); -} // end vector_base::assign_dispatch() - -template - template - void vector_base - ::assign_dispatch(Integral n, Integral x, true_type) -{ - fill_assign(n, x); -} // end vector_base::assign_dispatch() - -template - template - void vector_base - ::insert_dispatch(iterator position, InputIterator first, InputIterator last, false_type) -{ - copy_insert(position, first, last); -} // end vector_base::insert_dispatch() - -template - template - void vector_base - ::insert_dispatch(iterator position, Integral n, Integral x, true_type) -{ - fill_insert(position, n, x); -} // end vector_base::insert_dispatch() - -template - template - void vector_base - ::copy_insert(iterator position, - ForwardIterator first, - ForwardIterator last) -{ - if(first != last) - { - // how many new elements will we create? - const size_type num_new_elements = thrust::distance(first, last); - if(capacity() - size() >= num_new_elements) - { - // we've got room for all of them - // how many existing elements will we displace? - const size_type num_displaced_elements = end() - position; - iterator old_end = end(); - - if(num_displaced_elements > num_new_elements) - { - // construct copy n displaced elements to new elements - // following the insertion - m_storage.uninitialized_copy(end() - num_new_elements, end(), end()); - - // extend the size - m_size += num_new_elements; - - // copy num_displaced_elements - num_new_elements elements to existing elements - // this copy overlaps - const size_type copy_length = (old_end - num_new_elements) - position; - thrust::detail::overlapped_copy(position, old_end - num_new_elements, old_end - copy_length); - - // finally, copy the range to the insertion point - thrust::copy(first, last, position); - } // end if - else - { - ForwardIterator mid = first; - thrust::advance(mid, num_displaced_elements); - - // construct copy new elements at the end of the vector - m_storage.uninitialized_copy(mid, last, end()); - - // extend the size - m_size += num_new_elements - num_displaced_elements; - - // construct copy the displaced elements - m_storage.uninitialized_copy(position, old_end, end()); - - // extend the size - m_size += num_displaced_elements; - - // copy to elements which already existed - thrust::copy(first, mid, position); - } // end else - } // end if - else - { - const size_type old_size = size(); - - // compute the new capacity after the allocation - size_type new_capacity = old_size + thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (old_size, num_new_elements); - - // allocate exponentially larger new storage - new_capacity = thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (new_capacity, 2 * capacity()); - - // do not exceed maximum storage - new_capacity = thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (new_capacity, max_size()); - - if(new_capacity > max_size()) - { - throw std::length_error("insert(): insertion exceeds max_size()."); - } // end if - - storage_type new_storage(new_capacity); - - // record how many constructors we invoke in the try block below - iterator new_end = new_storage.begin(); - - try - { - // construct copy elements before the insertion to the beginning of the newly - // allocated storage - new_end = m_storage.uninitialized_copy(begin(), position, new_storage.begin()); - - // construct copy elements to insert - new_end = m_storage.uninitialized_copy(first, last, new_end); - - // construct copy displaced elements from the old storage to the new storage - // remember [position, end()) refers to the old storage - new_end = m_storage.uninitialized_copy(position, end(), new_end); - } // end try - catch(...) - { - // something went wrong, so destroy & deallocate the new storage - m_storage.destroy(new_storage.begin(), new_end); - new_storage.deallocate(); - - // rethrow - throw; - } // end catch - - // call destructors on the elements in the old storage - m_storage.destroy(begin(), end()); - - // record the vector's new state - m_storage.swap(new_storage); - m_size = old_size + num_new_elements; - } // end else - } // end if -} // end vector_base::copy_insert() - -template - void vector_base - ::append(size_type n) -{ - if(n != 0) - { - if(capacity() - size() >= n) - { - // we've got room for all of them - - // default construct new elements at the end of the vector - m_storage.default_construct_n(end(), n); - - // extend the size - m_size += n; - } // end if - else - { - const size_type old_size = size(); - - // compute the new capacity after the allocation - size_type new_capacity = old_size + thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (old_size, n); - - // allocate exponentially larger new storage - new_capacity = thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (new_capacity, 2 * capacity()); - - // do not exceed maximum storage - new_capacity = thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (new_capacity, max_size()); - - // create new storage - storage_type new_storage(new_capacity); - - // record how many constructors we invoke in the try block below - iterator new_end = new_storage.begin(); - - try - { - // construct copy all elements into the newly allocated storage - new_end = m_storage.uninitialized_copy(begin(), end(), new_storage.begin()); - - // construct new elements to insert - m_storage.default_construct_n(new_end, n); - new_end += n; - } // end try - catch(...) - { - // something went wrong, so destroy & deallocate the new storage - m_storage.destroy(new_storage.begin(), new_end); - new_storage.deallocate(); - - // rethrow - throw; - } // end catch - - // call destructors on the elements in the old storage - m_storage.destroy(begin(), end()); - - // record the vector's new state - m_storage.swap(new_storage); - m_size = old_size + n; - } // end else - } // end if -} // end vector_base::append() - -template - void vector_base - ::fill_insert(iterator position, size_type n, const T &x) -{ - if(n != 0) - { - if(capacity() - size() >= n) - { - // we've got room for all of them - // how many existing elements will we displace? - const size_type num_displaced_elements = end() - position; - iterator old_end = end(); - - if(num_displaced_elements > n) - { - // construct copy n displaced elements to new elements - // following the insertion - m_storage.uninitialized_copy(end() - n, end(), end()); - - // extend the size - m_size += n; - - // copy num_displaced_elements - n elements to existing elements - // this copy overlaps - const size_type copy_length = (old_end - n) - position; - thrust::detail::overlapped_copy(position, old_end - n, old_end - copy_length); - - // finally, fill the range to the insertion point - thrust::fill_n(position, n, x); - } // end if - else - { - // construct new elements at the end of the vector - m_storage.uninitialized_fill_n(end(), n - num_displaced_elements, x); - - // extend the size - m_size += n - num_displaced_elements; - - // construct copy the displaced elements - m_storage.uninitialized_copy(position, old_end, end()); - - // extend the size - m_size += num_displaced_elements; - - // fill to elements which already existed - thrust::fill(position, old_end, x); - } // end else - } // end if - else - { - const size_type old_size = size(); - - // compute the new capacity after the allocation - size_type new_capacity = old_size + thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (old_size, n); - - // allocate exponentially larger new storage - new_capacity = thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (new_capacity, 2 * capacity()); - - // do not exceed maximum storage - new_capacity = thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (new_capacity, max_size()); - - if(new_capacity > max_size()) - { - throw std::length_error("insert(): insertion exceeds max_size()."); - } // end if - - storage_type new_storage(new_capacity); - - // record how many constructors we invoke in the try block below - iterator new_end = new_storage.begin(); - - try - { - // construct copy elements before the insertion to the beginning of the newly - // allocated storage - new_end = m_storage.uninitialized_copy(begin(), position, new_storage.begin()); - - // construct new elements to insert - m_storage.uninitialized_fill_n(new_end, n, x); - new_end += n; - - // construct copy displaced elements from the old storage to the new storage - // remember [position, end()) refers to the old storage - new_end = m_storage.uninitialized_copy(position, end(), new_end); - } // end try - catch(...) - { - // something went wrong, so destroy & deallocate the new storage - m_storage.destroy(new_storage.begin(), new_end); - new_storage.deallocate(); - - // rethrow - throw; - } // end catch - - // call destructors on the elements in the old storage - m_storage.destroy(begin(), end()); - - // record the vector's new state - m_storage.swap(new_storage); - m_size = old_size + n; - } // end else - } // end if -} // end vector_base::fill_insert() - -template - template - void vector_base - ::range_assign(InputIterator first, - InputIterator last) -{ - // dispatch on traversal - range_assign(first, last, - typename thrust::iterator_traversal::type()); -} // end range_assign() - -template - template - void vector_base - ::range_assign(InputIterator first, - InputIterator last, - thrust::incrementable_traversal_tag) -{ - iterator current(begin()); - - // assign to elements which already exist - for(; first != last && current != end(); ++current, ++first) - { - *current = *first; - } // end for - - // either just the input was exhausted or both - // the input and vector elements were exhausted - if(first == last) - { - // if we exhausted the input, erase leftover elements - erase(current, end()); - } // end if - else - { - // insert the rest of the input at the end of the vector - insert(end(), first, last); - } // end else -} // end vector_base::range_assign() - -template - template - void vector_base - ::range_assign(RandomAccessIterator first, - RandomAccessIterator last, - thrust::random_access_traversal_tag) -{ - const size_type n = thrust::distance(first, last); - - if(n > capacity()) - { - storage_type new_storage; - allocate_and_copy(n, first, last, new_storage); - - // call destructors on the elements in the old storage - m_storage.destroy(begin(), end()); - - // record the vector's new state - m_storage.swap(new_storage); - m_size = n; - } // end if - else if(size() >= n) - { - // we can already accomodate the new range - iterator new_end = thrust::copy(first, last, begin()); - - // destroy the elements we don't need - m_storage.destroy(new_end, end()); - - // update size - m_size = n; - } // end else if - else - { - // range fits inside allocated storage, but some elements - // have not been constructed yet - - // XXX TODO we could possibly implement this with one call - // to transform rather than copy + uninitialized_copy - - // copy to elements which already exist - RandomAccessIterator mid = first; - thrust::advance(mid, size()); - thrust::copy(first, mid, begin()); - - // uninitialize_copy to elements which must be constructed - m_storage.uninitialized_copy(mid, last, end()); - - // update size - m_size = n; - } // end else -} // end vector_base::assign() - -template - void vector_base - ::fill_assign(size_type n, const T &x) -{ - if(n > capacity()) - { - // XXX we should also include a copy of the allocator: - // vector_base temp(n, x, get_allocator()); - vector_base temp(n, x); - temp.swap(*this); - } // end if - else if(n > size()) - { - // fill to existing elements - thrust::fill(begin(), end(), x); - - // construct uninitialized elements - m_storage.uninitialized_fill_n(end(), n - size(), x); - - // adjust size - m_size += (n - size()); - } // end else if - else - { - // fill to existing elements - iterator new_end = thrust::fill_n(begin(), n, x); - - // erase the elements after the fill - erase(new_end, end()); - } // end else -} // end vector_base::fill_assign() - -template - template - void vector_base - ::allocate_and_copy(size_type requested_size, - ForwardIterator first, ForwardIterator last, - storage_type &new_storage) -{ - if(requested_size == 0) - { - new_storage.deallocate(); - return; - } // end if - - // allocate exponentially larger new storage - size_type allocated_size = thrust::max(requested_size, 2 * capacity()); - - // do not exceed maximum storage - allocated_size = thrust::min(allocated_size, max_size()); - - if(requested_size > allocated_size) - { - throw std::length_error("assignment exceeds max_size()."); - } // end if - - new_storage.allocate(allocated_size); - - try - { - // construct the range to the newly allocated storage - m_storage.uninitialized_copy(first, last, new_storage.begin()); - } // end try - catch(...) - { - // something went wrong, so destroy & deallocate the new storage - // XXX seems like this destroys too many elements -- should just be last - first instead of requested_size - iterator new_storage_end = new_storage.begin(); - thrust::advance(new_storage_end, requested_size); - m_storage.destroy(new_storage.begin(), new_storage_end); - new_storage.deallocate(); - - // rethrow - throw; - } // end catch -} // end vector_base::allocate_and_copy() - - -} // end detail - -template - void swap(detail::vector_base &a, - detail::vector_base &b) -{ - a.swap(b); -} // end swap() - - - -namespace detail -{ - -// iterator tags match -template -bool vector_equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - thrust::detail::true_type) -{ - return thrust::equal(first1, last1, first2); -} - -// iterator tags differ -template -bool vector_equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - thrust::detail::false_type) -{ - typename thrust::iterator_difference::type n = thrust::distance(first1,last1); - - typedef typename thrust::iterator_system::type FromSystem1; - typedef typename thrust::iterator_system::type FromSystem2; - - // bring both ranges to the host system - // note that these copies are no-ops if the range is already convertible to the host system - FromSystem1 from_system1; - FromSystem2 from_system2; - thrust::host_system_tag to_system; - thrust::detail::move_to_system rng1(from_system1, to_system, first1, last1); - thrust::detail::move_to_system rng2(from_system2, to_system, first2, first2 + n); - - return thrust::equal(rng1.begin(), rng1.end(), rng2.begin()); -} - -template -bool vector_equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2) -{ - typedef typename thrust::iterator_system::type system1; - typedef typename thrust::iterator_system::type system2; - - // dispatch on the sameness of the two systems - return vector_equal(first1, last1, first2, - thrust::detail::is_same()); -} - -} // end namespace detail - - - - -template -bool operator==(const detail::vector_base& lhs, - const detail::vector_base& rhs) -{ - return lhs.size() == rhs.size() && detail::vector_equal(lhs.begin(), lhs.end(), rhs.begin()); -} - -template -bool operator==(const detail::vector_base& lhs, - const std::vector& rhs) -{ - return lhs.size() == rhs.size() && detail::vector_equal(lhs.begin(), lhs.end(), rhs.begin()); -} - -template -bool operator==(const std::vector& lhs, - const detail::vector_base& rhs) -{ - return lhs.size() == rhs.size() && detail::vector_equal(lhs.begin(), lhs.end(), rhs.begin()); -} - -template -bool operator!=(const detail::vector_base& lhs, - const detail::vector_base& rhs) -{ - return !(lhs == rhs); -} - -template -bool operator!=(const detail::vector_base& lhs, - const std::vector& rhs) -{ - return !(lhs == rhs); -} - -template -bool operator!=(const std::vector& lhs, - const detail::vector_base& rhs) -{ - return !(lhs == rhs); -} - -} // end thrust - diff --git a/compat/thrust/device_allocator.h b/compat/thrust/device_allocator.h deleted file mode 100644 index a5462d1..0000000 --- a/compat/thrust/device_allocator.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_allocator.h - * \brief An allocator which creates new elements in device memory - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup memory_management_classes Memory Management Classes - * \{ - */ - -template class device_allocator; - -/*! \p device_allocator is a device memory allocator. - * This class is a specialization for \c void. - * - * \see device_ptr - * \see http://www.sgi.com/tech/stl/Allocators.html - */ -template<> - class device_allocator -{ - public: - /*! Type of element allocated, \c void. */ - typedef void value_type; - - /*! Pointer to allocation, \c device_ptr. */ - typedef device_ptr pointer; - - /*! \c const pointer to allocation, \c device_ptr. */ - typedef device_ptr const_pointer; - - /*! Type of allocation size, \c std::size_t. */ - typedef std::size_t size_type; - - /*! Type of allocation difference, \c pointer::difference_type. */ - typedef pointer::difference_type difference_type; - - /*! The \p rebind metafunction provides the type of a \p device_allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p device_allocator. - */ - typedef device_allocator other; - }; // end rebind -}; // end device_allocator - -/*! \p device_allocator is a device memory allocator. - * This implementation inherits from \p device_new_allocator. - * - * \see device_ptr - * \see device_new_allocator - * \see http://www.sgi.com/tech/stl/Allocators.html - */ -template - class device_allocator - : public device_new_allocator -{ - public: - /*! The \p rebind metafunction provides the type of a \p device_allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p device_allocator. - */ - typedef device_allocator other; - }; // end rebind - - /*! No-argument constructor has no effect. - */ - __host__ __device__ - inline device_allocator() {} - - /*! Copy constructor has no effect. - */ - __host__ __device__ - inline device_allocator(device_allocator const&) {} - - /*! Constructor from other \p allocator has no effect. - */ - template - __host__ __device__ - inline device_allocator(device_allocator const&) {} -}; // end device_allocator - -/*! \} - */ - -} // end thrust - diff --git a/compat/thrust/device_delete.h b/compat/thrust/device_delete.h deleted file mode 100644 index 1df3bb6..0000000 --- a/compat/thrust/device_delete.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_delete.h - * \brief Deletes variables in device memory - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -/*! \addtogroup deallocation_functions Deallocation Functions - * \ingroup memory_management_functions - * \{ - */ - -/*! \p device_delete deletes a \p device_ptr allocated with - * \p device_new. - * - * \param ptr The \p device_ptr to delete, assumed to have - * been allocated with \p device_new. - * \param n The number of objects to destroy at \p ptr. Defaults to \c 1 - * similar to \p device_new. - * - * \see device_ptr - * \see device_new - */ -template - inline void device_delete(thrust::device_ptr ptr, - const size_t n = 1); - -/*! \} - */ - -} // end thrust - -#include - diff --git a/compat/thrust/device_free.h b/compat/thrust/device_free.h deleted file mode 100644 index a734418..0000000 --- a/compat/thrust/device_free.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_free.h - * \brief Deallocates storage allocated by \p device_malloc - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -/*! \addtogroup deallocation_functions Deallocation Functions - * \ingroup memory_management_functions - * \{ - */ - -/*! \p device_free deallocates memory allocated by the function \p device_malloc. - * - * \param ptr A \p device_ptr pointing to memory to be deallocated. - * - * The following code snippet demonstrates how to use \p device_free to - * deallocate memory allocated by \p device_malloc. - * - * \code - * #include - * #include - * ... - * // allocate some integers with device_malloc - * const int N = 100; - * thrust::device_ptr int_array = thrust::device_malloc(N); - * - * // manipulate integers - * ... - * - * // deallocate with device_free - * thrust::device_free(int_array); - * \endcode - * - * \see device_ptr - * \see device_malloc - */ -inline void device_free(thrust::device_ptr ptr); - -/*! \} - */ - -} // end thrust - -#include - diff --git a/compat/thrust/device_malloc.h b/compat/thrust/device_malloc.h deleted file mode 100644 index a3b0723..0000000 --- a/compat/thrust/device_malloc.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_malloc.h - * \brief Allocates storage in device memory - */ - -#pragma once - -#include -#include -#include // for std::size_t - -namespace thrust -{ - -/*! \addtogroup allocation_functions Allocation Functions - * \ingroup memory_management_functions - * \{ - */ - -/*! This version of \p device_malloc allocates sequential device storage - * for bytes. - * - * \param n The number of bytes to allocate sequentially - * in device memory. - * \return A \p device_ptr to the newly allocated memory. - * - * The following code snippet demonstrates how to use \p device_malloc to - * allocate a range of device memory. - * - * \code - * #include - * #include - * ... - * // allocate some memory with device_malloc - * const int N = 100; - * thrust::device_ptr void_ptr = thrust::device_malloc(N); - * - * // manipulate memory - * ... - * - * // deallocate with device_free - * thrust::device_free(void_ptr); - * \endcode - * - * \see device_ptr - * \see device_free - */ -inline thrust::device_ptr device_malloc(const std::size_t n); - -/*! This version of \p device_malloc allocates sequential device storage for - * new objects of the given type. - * - * \param n The number of objects of type T to allocate - * sequentially in device memory. - * \return A \p device_ptr to the newly allocated memory. - * - * The following code snippet demonstrates how to use \p device_malloc to - * allocate a range of device memory. - * - * \code - * #include - * #include - * ... - * // allocate some integers with device_malloc - * const int N = 100; - * thrust::device_ptr int_array = thrust::device_malloc(N); - * - * // manipulate integers - * ... - * - * // deallocate with device_free - * thrust::device_free(int_array); - * \endcode - * - * \see device_ptr - * \see device_free - */ -template - inline thrust::device_ptr device_malloc(const std::size_t n); - -/*! \} - */ - -} // end thrust - -#include - diff --git a/compat/thrust/device_malloc_allocator.h b/compat/thrust/device_malloc_allocator.h deleted file mode 100644 index 404a6d2..0000000 --- a/compat/thrust/device_malloc_allocator.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_malloc_allocator.h - * \brief An allocator which allocates storage with \p device_malloc - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -// forward declarations to WAR circular #includes -template class device_ptr; -template device_ptr device_malloc(const std::size_t n); - -/*! \addtogroup memory_management Memory Management - * \addtogroup memory_management_classes Memory Management Classes - * \ingroup memory_management - * \{ - */ - -/*! \p device_malloc_allocator is a device memory allocator that employs the - * \p device_malloc function for allocation. - * - * \see device_malloc - * \see device_ptr - * \see http://www.sgi.com/tech/stl/Allocators.html - */ -template - class device_malloc_allocator -{ - public: - /*! Type of element allocated, \c T. */ - typedef T value_type; - - /*! Pointer to allocation, \c device_ptr. */ - typedef device_ptr pointer; - - /*! \c const pointer to allocation, \c device_ptr. */ - typedef device_ptr const_pointer; - - /*! Reference to allocated element, \c device_reference. */ - typedef device_reference reference; - - /*! \c const reference to allocated element, \c device_reference. */ - typedef device_reference const_reference; - - /*! Type of allocation size, \c std::size_t. */ - typedef std::size_t size_type; - - /*! Type of allocation difference, \c pointer::difference_type. */ - typedef typename pointer::difference_type difference_type; - - /*! The \p rebind metafunction provides the type of a \p device_malloc_allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p device_malloc_allocator. - */ - typedef device_malloc_allocator other; - }; // end rebind - - /*! No-argument constructor has no effect. */ - __host__ __device__ - inline device_malloc_allocator() {} - - /*! No-argument destructor has no effect. */ - __host__ __device__ - inline ~device_malloc_allocator() {} - - /*! Copy constructor has no effect. */ - __host__ __device__ - inline device_malloc_allocator(device_malloc_allocator const&) {} - - /*! Constructor from other \p device_malloc_allocator has no effect. */ - template - __host__ __device__ - inline device_malloc_allocator(device_malloc_allocator const&) {} - - /*! Returns the address of an allocated object. - * \return &r. - */ - __host__ __device__ - inline pointer address(reference r) { return &r; } - - /*! Returns the address an allocated object. - * \return &r. - */ - __host__ __device__ - inline const_pointer address(const_reference r) { return &r; } - - /*! Allocates storage for \p cnt objects. - * \param cnt The number of objects to allocate. - * \return A \p pointer to uninitialized storage for \p cnt objects. - * \note Memory allocated by this function must be deallocated with \p deallocate. - */ - __host__ - inline pointer allocate(size_type cnt, - const_pointer = const_pointer(static_cast(0))) - { - if(cnt > this->max_size()) - { - throw std::bad_alloc(); - } // end if - - return pointer(device_malloc(cnt)); - } // end allocate() - - /*! Deallocates storage for objects allocated with \p allocate. - * \param p A \p pointer to the storage to deallocate. - * \param cnt The size of the previous allocation. - * \note Memory deallocated by this function must previously have been - * allocated with \p allocate. - */ - __host__ - inline void deallocate(pointer p, size_type cnt) - { - device_free(p); - } // end deallocate() - - /*! Returns the largest value \c n for which allocate(n) might succeed. - * \return The largest value \c n for which allocate(n) might succeed. - */ - inline size_type max_size() const - { - return (std::numeric_limits::max)() / sizeof(T); - } // end max_size() - - /*! Compares against another \p device_malloc_allocator for equality. - * \return \c true - */ - __host__ __device__ - inline bool operator==(device_malloc_allocator const&) { return true; } - - /*! Compares against another \p device_malloc_allocator for inequality. - * \return \c false - */ - __host__ __device__ - inline bool operator!=(device_malloc_allocator const &a) {return !operator==(a); } -}; // end device_malloc_allocator - -/*! \} - */ - -} // end thrust - - diff --git a/compat/thrust/device_new.h b/compat/thrust/device_new.h deleted file mode 100644 index 001d476..0000000 --- a/compat/thrust/device_new.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_new.h - * \brief Constructs new elements in device memory - */ - -#pragma once - -#include - -// #include this for size_t -#include -#include - -namespace thrust -{ - -/*! - * \addtogroup allocation_functions Allocation Functions - * \{ - */ - -/*! \p device_new implements the placement \c new operator for types - * resident in device memory. \p device_new calls T's null - * constructor on a array of objects in device memory. - * No memory is allocated by this function. - * - * \param p A \p device_ptr to a region of device memory into which - * to construct one or many Ts. - * \param n The number of objects to construct at \p p. - * \return p, casted to T's type. - * - * \see device_ptr - */ -template - device_ptr device_new(device_ptr p, - const size_t n = 1); - -/*! \p device_new implements the placement new operator for types - * resident in device memory. \p device_new calls T's copy - * constructor on a array of objects in device memory. No memory is - * allocated by this function. - * - * \param p A \p device_ptr to a region of device memory into which to - * construct one or many Ts. - * \param exemplar The value from which to copy. - * \param n The number of objects to construct at \p p. - * \return p, casted to T's type. - * - * \see device_ptr - * \see fill - */ -template - device_ptr device_new(device_ptr p, - const T &exemplar, - const size_t n = 1); - -/*! \p device_new implements the new operator for types resident in device memory. - * It allocates device memory large enough to hold \p n new objects of type \c T. - * - * \param n The number of objects to allocate. Defaults to \c 1. - * \return A \p device_ptr to the newly allocated region of device memory. - */ -template - device_ptr device_new(const size_t n = 1); - -/*! \} - */ - -} // end thrust - -#include - diff --git a/compat/thrust/device_new_allocator.h b/compat/thrust/device_new_allocator.h deleted file mode 100644 index 527d1fd..0000000 --- a/compat/thrust/device_new_allocator.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_new_allocator.h - * \brief An allocator which allocates storage with \p device_new - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup memory_management Memory Management - * \addtogroup memory_management_classes Memory Management Classes - * \ingroup memory_management - * \{ - */ - -/*! \p device_new_allocator is a device memory allocator that employs the - * \p device_new function for allocation. - * - * \see device_new - * \see device_ptr - * \see http://www.sgi.com/tech/stl/Allocators.html - */ -template - class device_new_allocator -{ - public: - /*! Type of element allocated, \c T. */ - typedef T value_type; - - /*! Pointer to allocation, \c device_ptr. */ - typedef device_ptr pointer; - - /*! \c const pointer to allocation, \c device_ptr. */ - typedef device_ptr const_pointer; - - /*! Reference to allocated element, \c device_reference. */ - typedef device_reference reference; - - /*! \c const reference to allocated element, \c device_reference. */ - typedef device_reference const_reference; - - /*! Type of allocation size, \c std::size_t. */ - typedef std::size_t size_type; - - /*! Type of allocation difference, \c pointer::difference_type. */ - typedef typename pointer::difference_type difference_type; - - /*! The \p rebind metafunction provides the type of a \p device_new_allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p device_new_allocator. - */ - typedef device_new_allocator other; - }; // end rebind - - /*! No-argument constructor has no effect. */ - __host__ __device__ - inline device_new_allocator() {} - - /*! No-argument destructor has no effect. */ - __host__ __device__ - inline ~device_new_allocator() {} - - /*! Copy constructor has no effect. */ - __host__ __device__ - inline device_new_allocator(device_new_allocator const&) {} - - /*! Constructor from other \p device_malloc_allocator has no effect. */ - template - __host__ __device__ - inline device_new_allocator(device_new_allocator const&) {} - - /*! Returns the address of an allocated object. - * \return &r. - */ - __host__ __device__ - inline pointer address(reference r) { return &r; } - - /*! Returns the address an allocated object. - * \return &r. - */ - __host__ __device__ - inline const_pointer address(const_reference r) { return &r; } - - /*! Allocates storage for \p cnt objects. - * \param cnt The number of objects to allocate. - * \return A \p pointer to uninitialized storage for \p cnt objects. - * \note Memory allocated by this function must be deallocated with \p deallocate. - */ - __host__ - inline pointer allocate(size_type cnt, - const_pointer = const_pointer(static_cast(0))) - { - if(cnt > this->max_size()) - { - throw std::bad_alloc(); - } // end if - - // use "::operator new" rather than keyword new - return pointer(device_new(cnt)); - } // end allocate() - - /*! Deallocates storage for objects allocated with \p allocate. - * \param p A \p pointer to the storage to deallocate. - * \param cnt The size of the previous allocation. - * \note Memory deallocated by this function must previously have been - * allocated with \p allocate. - */ - __host__ - inline void deallocate(pointer p, size_type cnt) - { - // use "::operator delete" rather than keyword delete - device_delete(p); - } // end deallocate() - - /*! Returns the largest value \c n for which allocate(n) might succeed. - * \return The largest value \c n for which allocate(n) might succeed. - */ - __host__ __device__ - inline size_type max_size() const - { - return std::numeric_limits::max THRUST_PREVENT_MACRO_SUBSTITUTION () / sizeof(T); - } // end max_size() - - /*! Compares against another \p device_malloc_allocator for equality. - * \return \c true - */ - __host__ __device__ - inline bool operator==(device_new_allocator const&) { return true; } - - /*! Compares against another \p device_malloc_allocator for inequality. - * \return \c false - */ - __host__ __device__ - inline bool operator!=(device_new_allocator const &a) {return !operator==(a); } -}; // end device_new_allocator - -/*! \} - */ - -} // end thrust - diff --git a/compat/thrust/device_ptr.h b/compat/thrust/device_ptr.h deleted file mode 100644 index dfc7e90..0000000 --- a/compat/thrust/device_ptr.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_ptr.h - * \brief A pointer to a variable which resides in the "device" system's memory space - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup memory_management Memory Management - * \addtogroup memory_management_classes Memory Management Classes - * \ingroup memory_management - * \{ - */ - -// forward declarations -template class device_reference; - -/*! \p device_ptr stores a pointer to an object allocated in device memory. This type - * provides type safety when dispatching standard algorithms on ranges resident in - * device memory. - * - * \p device_ptr has pointer semantics: it may be dereferenced safely from the host and - * may be manipulated with pointer arithmetic. - * - * \p device_ptr can be created with the functions device_malloc, device_new, or - * device_pointer_cast, or by explicitly calling its constructor with a raw pointer. - * - * The raw pointer encapsulated by a \p device_ptr may be obtained by either its get - * method or the \p raw_pointer_cast free function. - * - * \note \p device_ptr is not a smart pointer; it is the programmer's responsibility to - * deallocate memory pointed to by \p device_ptr. - * - * \see device_malloc - * \see device_new - * \see device_pointer_cast - * \see raw_pointer_cast - */ -template - class device_ptr - : public thrust::pointer< - T, - thrust::device_system_tag, - thrust::device_reference, - thrust::device_ptr - > -{ - private: - typedef thrust::pointer< - T, - thrust::device_system_tag, - thrust::device_reference, - thrust::device_ptr - > super_t; - - public: - /*! \p device_ptr's null constructor initializes its raw pointer to \c 0. - */ - __host__ __device__ - device_ptr() : super_t() {} - - /*! \p device_ptr's copy constructor is templated to allow copying to a - * device_ptr from a T *. - * - * \param ptr A raw pointer to copy from, presumed to point to a location in - * device memory. - */ - template - __host__ __device__ - explicit device_ptr(OtherT *ptr) : super_t(ptr) {} - - /*! \p device_ptr's copy constructor allows copying from another device_ptr with related type. - * \param other The \p device_ptr to copy from. - */ - template - __host__ __device__ - device_ptr(const device_ptr &other) : super_t(other) {} - - /*! \p device_ptr's assignment operator allows assigning from another \p device_ptr with related type. - * \param other The other \p device_ptr to copy from. - * \return *this - */ - template - __host__ __device__ - device_ptr &operator=(const device_ptr &other) - { - super_t::operator=(other); - return *this; - } - -// declare these members for the purpose of Doxygenating them -// they actually exist in a derived-from class -#if 0 - /*! This method returns this \p device_ptr's raw pointer. - * \return This \p device_ptr's raw pointer. - */ - __host__ __device__ - T *get(void) const; -#endif // end doxygen-only members -}; // end device_ptr - -/*! This operator outputs the value of a \p device_ptr's raw pointer to a \p std::basic_ostream. - * - * \param os The std::basic_ostream of interest. - * \param p The device_ptr of interest. - * \return os. - */ -template -inline std::basic_ostream &operator<<(std::basic_ostream &os, const device_ptr &p); - -/*! \} - */ - - -/*! - * \addtogroup memory_management_functions Memory Management Functions - * \ingroup memory_management - * \{ - */ - -/*! \p device_pointer_cast creates a device_ptr from a raw pointer which is presumed to point - * to a location in device memory. - * - * \param ptr A raw pointer, presumed to point to a location in device memory. - * \return A device_ptr wrapping ptr. - */ -template -__host__ __device__ -inline device_ptr device_pointer_cast(T *ptr); - -/*! This version of \p device_pointer_cast creates a copy of a device_ptr from another device_ptr. - * This version is included for symmetry with \p raw_pointer_cast. - * - * \param ptr A device_ptr. - * \return A copy of \p ptr. - */ -template -__host__ __device__ -inline device_ptr device_pointer_cast(const device_ptr &ptr); - -/*! \} - */ - -} // end thrust - -#include -#include - diff --git a/compat/thrust/device_reference.h b/compat/thrust/device_reference.h deleted file mode 100644 index edae2b5..0000000 --- a/compat/thrust/device_reference.h +++ /dev/null @@ -1,969 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_reference.h - * \brief A reference to a variable which resides in the "device" system's memory space - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup memory_management_classes Memory Management Classes - * \ingroup memory_management - * \{ - */ - -/*! \p device_reference acts as a reference-like object to an object stored in device memory. - * \p device_reference is not intended to be used directly; rather, this type - * is the result of deferencing a \p device_ptr. Similarly, taking the address of - * a \p device_reference yields a \p device_ptr. - * - * \p device_reference may often be used from host code in place of operations defined on - * its associated \c value_type. For example, when \p device_reference refers to an - * arithmetic type, arithmetic operations on it are legal: - * - * \code - * #include - * - * int main(void) - * { - * thrust::device_vector vec(1, 13); - * - * thrust::device_reference ref_to_thirteen = vec[0]; - * - * int x = ref_to_thirteen + 1; - * - * // x is 14 - * - * return 0; - * } - * \endcode - * - * Similarly, we can print the value of \c ref_to_thirteen in the above code by using an - * \c iostream: - * - * \code - * #include - * #include - * - * int main(void) - * { - * thrust::device_vector vec(1, 13); - * - * thrust::device_reference ref_to_thirteen = vec[0]; - * - * std::cout << ref_to_thirteen << std::endl; - * - * // 13 is printed - * - * return 0; - * } - * \endcode - * - * Of course, we needn't explicitly create a \p device_reference in the previous - * example, because one is returned by \p device_vector's bracket operator. A more natural - * way to print the value of a \p device_vector element might be: - * - * \code - * #include - * #include - * - * int main(void) - * { - * thrust::device_vector vec(1, 13); - * - * std::cout << vec[0] << std::endl; - * - * // 13 is printed - * - * return 0; - * } - * \endcode - * - * These kinds of operations should be used sparingly in performance-critical code, because - * they imply a potentially expensive copy between host and device space. - * - * Some operations which are possible with regular objects are impossible with their - * corresponding \p device_reference objects due to the requirements of the C++ language. For - * example, because the member access operator cannot be overloaded, member variables and functions - * of a referent object cannot be directly accessed through its \p device_reference. - * - * The following code, which generates a compiler error, illustrates: - * - * \code - * #include - * - * struct foo - * { - * int x; - * }; - * - * int main(void) - * { - * thrust::device_vector foo_vec(1); - * - * thrust::device_reference foo_ref = foo_vec[0]; - * - * foo_ref.x = 13; // ERROR: x cannot be accessed through foo_ref - * - * return 0; - * } - * \endcode - * - * Instead, a host space copy must be created to access \c foo's \c x member: - * - * \code - * #include - * - * struct foo - * { - * int x; - * }; - * - * int main(void) - * { - * thrust::device_vector foo_vec(1); - * - * // create a local host-side foo object - * foo host_foo; - * host_foo.x = 13; - * - * thrust::device_reference foo_ref = foo_vec[0]; - * - * foo_ref = host_foo; - * - * // foo_ref's x member is 13 - * - * return 0; - * } - * \endcode - * - * Another common case where a \p device_reference cannot directly be used in place of - * its referent object occurs when passing them as parameters to functions like \c printf - * which have varargs parameters. Because varargs parameters must be Plain Old Data, a - * \p device_reference to a POD type requires a cast when passed to \c printf: - * - * \code - * #include - * #include - * - * int main(void) - * { - * thrust::device_vector vec(1,13); - * - * // vec[0] must be cast to int when passing to printf - * printf("%d\n", (int) vec[0]); - * - * return 0; - * } - * \endcode - * - * \see device_ptr - * \see device_vector - */ -template - class device_reference - : public thrust::reference< - T, - thrust::device_ptr, - thrust::device_reference - > -{ - private: - typedef thrust::reference< - T, - thrust::device_ptr, - thrust::device_reference - > super_t; - - public: - /*! The type of the value referenced by this type of \p device_reference. - */ - typedef typename super_t::value_type value_type; - - /*! The type of the expression &ref, where ref is a \p device_reference. - */ - typedef typename super_t::pointer pointer; - - /*! This copy constructor accepts a const reference to another - * \p device_reference. After this \p device_reference is constructed, - * it shall refer to the same object as \p other. - * - * \param other A \p device_reference to copy from. - * - * The following code snippet demonstrates the semantics of this - * copy constructor. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_reference ref = v[0]; - * - * // ref equals the object at v[0] - * assert(ref == v[0]); - * - * // the address of ref equals the address of v[0] - * assert(&ref == &v[0]); - * - * // modifying v[0] modifies ref - * v[0] = 13; - * assert(ref == 13); - * \endcode - * - * \note This constructor is templated primarily to allow initialization of - * device_reference from device_reference. - */ - template - __host__ __device__ - device_reference(const device_reference &other, - typename thrust::detail::enable_if_convertible< - typename device_reference::pointer, - pointer - >::type * = 0) - : super_t(other) - {} - - /*! This copy constructor initializes this \p device_reference - * to refer to an object pointed to by the given \p device_ptr. After - * this \p device_reference is constructed, it shall refer to the - * object pointed to by \p ptr. - * - * \param ptr A \p device_ptr to copy from. - * - * The following code snippet demonstrates the semantic of this - * copy constructor. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals the object pointed to by ptr - * assert(ref == *ptr); - * - * // the address of ref equals ptr - * assert(&ref == ptr); - * - * // modifying *ptr modifies ref - * *ptr = 13; - * assert(ref == 13); - * \endcode - */ - __host__ __device__ - explicit device_reference(const pointer &ptr) - : super_t(ptr) - {} - - /*! This assignment operator assigns the value of the object referenced by - * the given \p device_reference to the object referenced by this - * \p device_reference. - * - * \param other The \p device_reference to assign from. - * \return *this - */ - template - __host__ __device__ - device_reference &operator=(const device_reference &other); - - /*! Assignment operator assigns the value of the given value to the - * value referenced by this \p device_reference. - * - * \param x The value to assign from. - * \return *this - */ - __host__ __device__ - device_reference &operator=(const value_type &x); - -// declare these members for the purpose of Doxygenating them -// they actually exist in a derived-from class -#if 0 - /*! Address-of operator returns a \p device_ptr pointing to the object - * referenced by this \p device_reference. It does not return the - * address of this \p device_reference. - * - * \return A \p device_ptr pointing to the object this - * \p device_reference references. - */ - __host__ __device__ - pointer operator&(void) const; - - /*! Conversion operator converts this \p device_reference to T - * by returning a copy of the object referenced by this - * \p device_reference. - * - * \return A copy of the object referenced by this \p device_reference. - */ - __host__ __device__ - operator value_type (void) const; - - /*! swaps the value this \p device_reference references with another. - * \p other The other \p device_reference with which to swap. - */ - __host__ __device__ - void swap(device_reference &other); - - /*! Prefix increment operator increments the object referenced by this - * \p device_reference. - * - * \return *this - * - * The following code snippet demonstrates the semantics of - * \p device_reference's prefix increment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * - * // increment ref - * ++ref; - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * \endcode - * - * \note The increment executes as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator++(void); - - /*! Postfix increment operator copies the object referenced by this - * \p device_reference, increments the object referenced by this - * \p device_reference, and returns the copy. - * - * \return A copy of the object referenced by this \p device_reference - * before being incremented. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's postfix increment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * - * // increment ref - * int x = ref++; - * - * // x equals 0 - * assert(x == 0) - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * \endcode - * - * \note The increment executes as if it were executed on the host. - * This may change in a later version. - */ - value_type operator++(int); - - /*! Addition assignment operator add-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the add-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's addition assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * - * // add-assign ref - * ref += 5; - * - * // ref equals 5 - * assert(ref == 5); - * - * // the object pointed to by ptr equals 5 - * assert(*ptr == 5); - * - * // v[0] equals 5 - * assert(v[0] == 5); - * \endcode - * - * \note The add-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator+=(const T &rhs); - - /*! Prefix decrement operator decrements the object referenced by this - * \p device_reference. - * - * \return *this - * - * The following code snippet demonstrates the semantics of - * \p device_reference's prefix decrement operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * - * // decrement ref - * --ref; - * - * // ref equals -1 - * assert(ref == -1); - * - * // the object pointed to by ptr equals -1 - * assert(*ptr == -1); - * - * // v[0] equals -1 - * assert(v[0] == -1); - * \endcode - * - * \note The decrement executes as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator--(void); - - /*! Postfix decrement operator copies the object referenced by this - * \p device_reference, decrements the object referenced by this - * \p device_reference, and returns the copy. - * - * \return A copy of the object referenced by this \p device_reference - * before being decremented. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's postfix decrement operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * - * // decrement ref - * int x = ref--; - * - * // x equals 0 - * assert(x == 0) - * - * // ref equals -1 - * assert(ref == -1); - * - * // the object pointed to by ptr equals -1 - * assert(*ptr == -1); - * - * // v[0] equals -1 - * assert(v[0] == -1); - * \endcode - * - * \note The decrement executes as if it were executed on the host. - * This may change in a later version. - */ - value_type operator--(int); - - /*! Subtraction assignment operator subtract-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the subtraction-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's addition assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * - * // subtract-assign ref - * ref -= 5; - * - * // ref equals -5 - * assert(ref == -5); - * - * // the object pointed to by ptr equals -5 - * assert(*ptr == -5); - * - * // v[0] equals -5 - * assert(v[0] == -5); - * \endcode - * - * \note The subtract-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator-=(const T &rhs); - - /*! Multiplication assignment operator multiply-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the multiply-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's multiply assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,1); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * - * // multiply-assign ref - * ref *= 5; - * - * // ref equals 5 - * assert(ref == 5); - * - * // the object pointed to by ptr equals 5 - * assert(*ptr == 5); - * - * // v[0] equals 5 - * assert(v[0] == 5); - * \endcode - * - * \note The multiply-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator*=(const T &rhs); - - /*! Division assignment operator divide-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the divide-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's divide assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,5); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 5 - * assert(ref == 5); - * - * // the object pointed to by ptr equals 5 - * assert(*ptr == 5); - * - * // v[0] equals 5 - * assert(v[0] == 5); - * - * // divide-assign ref - * ref /= 5; - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * \endcode - * - * \note The divide-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator/=(const T &rhs); - - /*! Modulation assignment operator modulus-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the divide-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's divide assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,5); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 5 - * assert(ref == 5); - * - * // the object pointed to by ptr equals 5 - * assert(*ptr == 5); - * - * // v[0] equals 5 - * assert(v[0] == 5); - * - * // modulus-assign ref - * ref %= 5; - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * \endcode - * - * \note The modulus-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator%=(const T &rhs); - - /*! Bitwise left shift assignment operator left shift-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the left shift-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's left shift assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,1); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * - * // left shift-assign ref - * ref <<= 1; - * - * // ref equals 2 - * assert(ref == 2); - * - * // the object pointed to by ptr equals 2 - * assert(*ptr == 2); - * - * // v[0] equals 2 - * assert(v[0] == 2); - * \endcode - * - * \note The left shift-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator<<=(const T &rhs); - - /*! Bitwise right shift assignment operator right shift-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the right shift-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's right shift assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,2); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 2 - * assert(ref == 2); - * - * // the object pointed to by ptr equals 2 - * assert(*ptr == 2); - * - * // v[0] equals 2 - * assert(v[0] == 2); - * - * // right shift-assign ref - * ref >>= 1; - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * \endcode - * - * \note The right shift-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator>>=(const T &rhs); - - /*! Bitwise AND assignment operator AND-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the AND-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's AND assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,1); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * - * // right AND-assign ref - * ref &= 0; - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * \endcode - * - * \note The AND-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator&=(const T &rhs); - - /*! Bitwise OR assignment operator OR-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the OR-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's OR assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,0); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * - * // right OR-assign ref - * ref |= 1; - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * \endcode - * - * \note The OR-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator|=(const T &rhs); - - /*! Bitwise XOR assignment operator XOR-assigns the object referenced by this - * \p device_reference and returns this \p device_reference. - * - * \param rhs The right hand side of the XOR-assignment. - * \return *this. - * - * The following code snippet demonstrates the semantics of - * \p device_reference's XOR assignment operator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(1,1); - * thrust::device_ptr ptr = &v[0]; - * thrust::device_reference ref(ptr); - * - * // ref equals 1 - * assert(ref == 1); - * - * // the object pointed to by ptr equals 1 - * assert(*ptr == 1); - * - * // v[0] equals 1 - * assert(v[0] == 1); - * - * // right XOR-assign ref - * ref ^= 1; - * - * // ref equals 0 - * assert(ref == 0); - * - * // the object pointed to by ptr equals 0 - * assert(*ptr == 0); - * - * // v[0] equals 0 - * assert(v[0] == 0); - * \endcode - * - * \note The XOR-assignment executes as as if it were executed on the host. - * This may change in a later version. - */ - device_reference &operator^=(const T &rhs); -#endif // end doxygen-only members -}; // end device_reference - -/*! swaps the value of one \p device_reference with another. - * \p x The first \p device_reference of interest. - * \p y The second \p device_reference of interest. - */ -template -__host__ __device__ -void swap(device_reference &x, device_reference &y); - -/*! \} - */ - -} // end thrust - -#include - diff --git a/compat/thrust/device_vector.h b/compat/thrust/device_vector.h deleted file mode 100644 index 8c9d005..0000000 --- a/compat/thrust/device_vector.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file device_vector.h - * \brief A dynamically-sizable array of elements which reside in the "device" memory space - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -// forward declaration of host_vector -template class host_vector; - -/*! \addtogroup container_classes Container Classes - * \addtogroup device_containers Device Containers - * \ingroup container_classes - * \{ - */ - -/*! A \p device_vector is a container that supports random access to elements, - * constant time removal of elements at the end, and linear time insertion - * and removal of elements at the beginning or in the middle. The number of - * elements in a \p device_vector may vary dynamically; memory management is - * automatic. The memory associated with a \p device_vector resides in the memory - * space of a parallel device. - * - * \see http://www.sgi.com/tech/stl/Vector.html - * \see host_vector - */ -template > - class device_vector - : public detail::vector_base -{ - private: - typedef detail::vector_base Parent; - - public: - /*! \cond */ - typedef typename Parent::size_type size_type; - typedef typename Parent::value_type value_type; - /*! \endcond */ - - /*! This constructor creates an empty \p device_vector. - */ - __host__ - device_vector(void) - :Parent() {} - - /*! This constructor creates a \p device_vector with the given - * size. - * \param n The number of elements to initially craete. - */ - __host__ - explicit device_vector(size_type n) - :Parent(n) {} - - /*! This constructor creates a \p device_vector with copies - * of an exemplar element. - * \param n The number of elements to initially create. - * \param value An element to copy. - */ - __host__ - explicit device_vector(size_type n, const value_type &value) - :Parent(n,value) {} - - /*! Copy constructor copies from an exemplar \p device_vector. - * \param v The \p device_vector to copy. - */ - __host__ - device_vector(const device_vector &v) - :Parent(v) {} - - /*! Copy constructor copies from an exemplar \p device_vector with different type. - * \param v The \p device_vector to copy. - */ - template - __device__ - device_vector(const device_vector &v) - :Parent(v) {} - - /*! Assign operator copies from an exemplar \p device_vector with different type. - * \param v The \p device_vector to copy. - */ - template - __device__ - device_vector &operator=(const device_vector &v) - { Parent::operator=(v); return *this; } - - /*! Copy constructor copies from an exemplar \c std::vector. - * \param v The std::vector to copy. - */ - template - __host__ - device_vector(const std::vector &v) - :Parent(v) {} - - /*! Assign operator copies from an exemplar std::vector. - * \param v The std::vector to copy. - */ - template - __host__ - device_vector &operator=(const std::vector &v) - { Parent::operator=(v); return *this;} - - /*! Copy constructor copies from an exemplar \p host_vector with possibly different type. - * \param v The \p host_vector to copy. - */ - template - __host__ - device_vector(const host_vector &v); - - /*! Assign operator copies from an examplar \p host_vector. - * \param v The \p host_vector to copy. - */ - template - __host__ - device_vector &operator=(const host_vector &v) - { Parent::operator=(v); return *this; } - - /*! This constructor builds a \p device_vector from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - __host__ - device_vector(InputIterator first, InputIterator last) - :Parent(first,last) {} - -// declare these members for the purpose of Doxygenating them -// they actually exist in a derived-from class -#if 0 - /*! \brief Resizes this vector to the specified number of elements. - * \param new_size Number of elements this vector should contain. - * \param x Data with which new elements should be populated. - * \throw std::length_error If n exceeds max_size(). - * - * This method will resize this vector to the specified number of - * elements. If the number is smaller than this vector's current - * size this vector is truncated, otherwise this vector is - * extended and new elements are populated with given data. - */ - void resize(size_type new_size, const value_type &x = value_type()); - - /*! Returns the number of elements in this vector. - */ - size_type size(void) const; - - /*! Returns the size() of the largest possible vector. - * \return The largest possible return value of size(). - */ - size_type max_size(void) const; - - /*! \brief If n is less than or equal to capacity(), this call has no effect. - * Otherwise, this method is a request for allocation of additional memory. If - * the request is successful, then capacity() is greater than or equal to - * n; otherwise, capacity() is unchanged. In either case, size() is unchanged. - * \throw std::length_error If n exceeds max_size(). - */ - void reserve(size_type n); - - /*! Returns the number of elements which have been reserved in this - * vector. - */ - size_type capacity(void) const; - - /*! This method shrinks the capacity of this vector to exactly - * fit its elements. - */ - void shrink_to_fit(void); - - /*! \brief Subscript access to the data contained in this vector_dev. - * \param n The index of the element for which data should be accessed. - * \return Read/write reference to data. - * - * This operator allows for easy, array-style, data access. - * Note that data access with this operator is unchecked and - * out_of_range lookups are not defined. - */ - reference operator[](size_type n); - - /*! \brief Subscript read access to the data contained in this vector_dev. - * \param n The index of the element for which data should be accessed. - * \return Read reference to data. - * - * This operator allows for easy, array-style, data access. - * Note that data access with this operator is unchecked and - * out_of_range lookups are not defined. - */ - const_reference operator[](size_type n) const; - - /*! This method returns an iterator pointing to the beginning of - * this vector. - * \return mStart - */ - iterator begin(void); - - /*! This method returns a const_iterator pointing to the beginning - * of this vector. - * \return mStart - */ - const_iterator begin(void) const; - - /*! This method returns a const_iterator pointing to the beginning - * of this vector. - * \return mStart - */ - const_iterator cbegin(void) const; - - /*! This method returns a reverse_iterator pointing to the beginning of - * this vector's reversed sequence. - * \return A reverse_iterator pointing to the beginning of this - * vector's reversed sequence. - */ - reverse_iterator rbegin(void); - - /*! This method returns a const_reverse_iterator pointing to the beginning of - * this vector's reversed sequence. - * \return A const_reverse_iterator pointing to the beginning of this - * vector's reversed sequence. - */ - const_reverse_iterator rbegin(void) const; - - /*! This method returns a const_reverse_iterator pointing to the beginning of - * this vector's reversed sequence. - * \return A const_reverse_iterator pointing to the beginning of this - * vector's reversed sequence. - */ - const_reverse_iterator crbegin(void) const; - - /*! This method returns an iterator pointing to one element past the - * last of this vector. - * \return begin() + size(). - */ - iterator end(void); - - /*! This method returns a const_iterator pointing to one element past the - * last of this vector. - * \return begin() + size(). - */ - const_iterator end(void) const; - - /*! This method returns a const_iterator pointing to one element past the - * last of this vector. - * \return begin() + size(). - */ - const_iterator cend(void) const; - - /*! This method returns a reverse_iterator pointing to one element past the - * last of this vector's reversed sequence. - * \return rbegin() + size(). - */ - reverse_iterator rend(void); - - /*! This method returns a const_reverse_iterator pointing to one element past the - * last of this vector's reversed sequence. - * \return rbegin() + size(). - */ - const_reverse_iterator rend(void) const; - - /*! This method returns a const_reverse_iterator pointing to one element past the - * last of this vector's reversed sequence. - * \return rbegin() + size(). - */ - const_reverse_iterator crend(void) const; - - /*! This method returns a const_reference referring to the first element of this - * vector. - * \return The first element of this vector. - */ - const_reference front(void) const; - - /*! This method returns a reference pointing to the first element of this - * vector. - * \return The first element of this vector. - */ - reference front(void); - - /*! This method returns a const reference pointing to the last element of - * this vector. - * \return The last element of this vector. - */ - const_reference back(void) const; - - /*! This method returns a reference referring to the last element of - * this vector_dev. - * \return The last element of this vector. - */ - reference back(void); - - /*! This method returns a pointer to this vector's first element. - * \return A pointer to the first element of this vector. - */ - pointer data(void); - - /*! This method returns a const_pointer to this vector's first element. - * \return a const_pointer to the first element of this vector. - */ - const_pointer data(void) const; - - /*! This method resizes this vector to 0. - */ - void clear(void); - - /*! This method returns true iff size() == 0. - * \return true if size() == 0; false, otherwise. - */ - bool empty(void) const; - - /*! This method appends the given element to the end of this vector. - * \param x The element to append. - */ - void push_back(const value_type &x); - - /*! This method erases the last element of this vector, invalidating - * all iterators and references to it. - */ - void pop_back(void); - - /*! This method swaps the contents of this vector_base with another vector. - * \param v The vector with which to swap. - */ - void swap(device_vector &v); - - /*! This method removes the element at position pos. - * \param pos The position of the element of interest. - * \return An iterator pointing to the new location of the element that followed the element - * at position pos. - */ - iterator erase(iterator pos); - - /*! This method removes the range of elements [first,last) from this vector. - * \param first The beginning of the range of elements to remove. - * \param last The end of the range of elements to remove. - * \return An iterator pointing to the new location of the element that followed the last - * element in the sequence [first,last). - */ - iterator erase(iterator first, iterator last); - - /*! This method inserts a single copy of a given exemplar value at the - * specified position in this vector. - * \param position The insertion position. - * \param x The exemplar element to copy & insert. - * \return An iterator pointing to the newly inserted element. - */ - iterator insert(iterator position, const T &x); - - /*! This method inserts a copy of an exemplar value to a range at the - * specified position in this vector. - * \param position The insertion position - * \param n The number of insertions to perform. - * \param x The value to replicate and insert. - */ - void insert(iterator position, size_type n, const T &x); - - /*! This method inserts a copy of an input range at the specified position - * in this vector. - * \param position The insertion position. - * \param first The beginning of the range to copy. - * \param last The end of the range to copy. - * - * \tparam InputIterator is a model of Assignable. - */ - template - void insert(iterator position, InputIterator first, InputIterator last); - - /*! This version of \p assign replicates a given exemplar - * \p n times into this vector. - * \param n The number of times to copy \p x. - * \param x The exemplar element to replicate. - */ - void assign(size_type n, const T &x); - - /*! This version of \p assign makes this vector a copy of a given input range. - * \param first The beginning of the range to copy. - * \param last The end of the range to copy. - * - * \tparam InputIterator is a model of Input Iterator. - */ - template - void assign(InputIterator first, InputIterator last); - - /*! This method returns a copy of this vector's allocator. - * \return A copy of the alloctor used by this vector. - */ - allocator_type get_allocator(void) const; -#endif // end doxygen-only members -}; // end device_vector - -/*! \} - */ - -} // end thrust - -#include - - diff --git a/compat/thrust/distance.h b/compat/thrust/distance.h deleted file mode 100644 index 67b4194..0000000 --- a/compat/thrust/distance.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file distance.h - * \brief Computes the size of a range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup iterators - * \{ - */ - -/*! \p distance finds the distance between \p first and \p last, i.e. the - * number of times that \p first must be incremented until it is equal to - * \p last. - * - * \param first The beginning of an input range of interest. - * \param last The end of an input range of interest. - * \return The distance between the beginning and end of the input range. - * - * \tparam InputIterator is a model of Input Iterator. - * - * \pre If \c InputIterator meets the requirements of random access iterator, \p last shall be reachable from \p first or - * \p first shall be reachable from \p last; otherwise, \p last shall be reachable from \p first. - * - * The following code snippet demonstrates how to use \p distance to compute - * the distance to one iterator from another. - * - * \code - * #include - * #include - * ... - * thrust::device_vector vec(13); - * thrust::device_vector::iterator iter1 = vec.begin(); - * thrust::device_vector::iterator iter2 = iter1 + 7; - * - * int d = thrust::distance(iter1, iter2); - * - * // d is 7 - * \endcode - * - * \see http://www.sgi.com/tech/stl/distance.html - */ -template - inline typename thrust::iterator_traits::difference_type - distance(InputIterator first, InputIterator last); - -/*! \} // end iterators - */ - -} // end thrust - -#include - diff --git a/compat/thrust/equal.h b/compat/thrust/equal.h deleted file mode 100644 index e96946f..0000000 --- a/compat/thrust/equal.h +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file equal.h - * \brief Equality between ranges - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reductions - * \{ - * \addtogroup comparisons - * \ingroup reductions - * \{ - */ - - -/*! \p equal returns \c true if the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) are identical when - * compared element-by-element, and otherwise returns \c false. - * - * This version of \p equal returns \c true if and only if for every - * iterator \c i in [first1, last1), *i == *(first2 + (i - first1)). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \return \c true, if the sequences are equal; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator1's \c value_type is a model of Equality Comparable, - * and \p InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is a model of Equality Comparable, - * and \p InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type. - * - * The following code snippet demonstrates how to use \p equal to test - * two ranges for equality using the \p thrust::host execution policy: - * - * \code - * #include - * #include - * ... - * int A1[7] = {3, 1, 4, 1, 5, 9, 3}; - * int A2[7] = {3, 1, 4, 2, 8, 5, 7}; - * ... - * bool result = thrust::equal(thrust::host, A1, A1 + 7, A2); - * - * // result == false - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal.html - */ -template -bool equal(const thrust::detail::execution_policy_base &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); - - -/*! \p equal returns \c true if the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) are identical when - * compared element-by-element, and otherwise returns \c false. - * - * This version of \p equal returns \c true if and only if for every - * iterator \c i in [first1, last1), *i == *(first2 + (i - first1)). - * - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \return \c true, if the sequences are equal; \c false, otherwise. - * - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator1's \c value_type is a model of Equality Comparable, - * and \p InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is a model of Equality Comparable, - * and \p InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type. - * - * The following code snippet demonstrates how to use \p equal to test - * two ranges for equality. - * - * \code - * #include - * ... - * int A1[7] = {3, 1, 4, 1, 5, 9, 3}; - * int A2[7] = {3, 1, 4, 2, 8, 5, 7}; - * ... - * bool result = thrust::equal(A1, A1 + 7, A2); - * - * // result == false - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal.html - */ -template -bool equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2); - - -/*! \p equal returns \c true if the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) are identical when - * compared element-by-element, and otherwise returns \c false. - * - * This version of \p equal returns \c true if and only if for every - * iterator \c i in [first1, last1), - * binary_pred(*i, *(first2 + (i - first1))) is \c true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param binary_pred Binary predicate used to test element equality. - * \return \c true, if the sequences are equal; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p equal to compare the - * elements in two ranges modulo 2 using the \p thrust::host execution policy. - * - * \code - * #include - * #include - * ... - * - * __host__ __device__ - * struct compare_modulo_two - * { - * bool operator()(int x, int y) - * { - * return (x % 2) == (y % 2); - * } - * }; - * ... - * int x[5] = {0, 2, 4, 6, 8, 10}; - * int y[5] = {1, 3, 5, 7, 9, 11}; - * - * bool result = thrust::equal(x, x + 5, y, compare_modulo_two()); - * - * // result is true - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal.html - */ -template -bool equal(const thrust::detail::execution_policy_base &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred); - - -/*! \p equal returns \c true if the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) are identical when - * compared element-by-element, and otherwise returns \c false. - * - * This version of \p equal returns \c true if and only if for every - * iterator \c i in [first1, last1), - * binary_pred(*i, *(first2 + (i - first1))) is \c true. - * - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param binary_pred Binary predicate used to test element equality. - * \return \c true, if the sequences are equal; \c false, otherwise. - * - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p equal to compare the - * elements in two ranges modulo 2. - * - * \code - * #include - * - * __host__ __device__ - * struct compare_modulo_two - * { - * bool operator()(int x, int y) - * { - * return (x % 2) == (y % 2); - * } - * }; - * ... - * int x[5] = {0, 2, 4, 6, 8, 10}; - * int y[5] = {1, 3, 5, 7, 9, 11}; - * - * bool result = thrust::equal(x, x + 5, y, compare_modulo_two()); - * - * // result is true - * \endcode - * - * \see http://www.sgi.com/tech/stl/equal.html - */ -template -bool equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, BinaryPredicate binary_pred); - - -/*! \} // end comparisons - * \} // end reductions - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/execution_policy.h b/compat/thrust/execution_policy.h deleted file mode 100644 index a5b61e9..0000000 --- a/compat/thrust/execution_policy.h +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/execution_policy.h - * \brief Thrust execution policies. - */ - -#pragma once - -#include - -// get the definition of thrust::execution_policy -#include - -// #include the host system's execution_policy header -#define __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER <__THRUST_HOST_SYSTEM_ROOT/execution_policy.h> -#include __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER -#undef __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER - -// #include the device system's execution_policy.h header -#define __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/execution_policy.h> -#include __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER -#undef __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER - -namespace thrust -{ - - -/*! \cond - */ - - -namespace detail -{ - - -typedef thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::detail::par_t host_t; - - -typedef thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::detail::par_t device_t; - - -} // end detail - - -/*! \endcond - */ - - -/*! \addtogroup execution_policies Parallel Execution Policies - * \{ - */ - - -// define execution_policy for the purpose of Doxygenating it -// it is actually defined elsewhere -#if 0 -/*! \p execution_policy is the base class for all Thrust parallel execution policies - * like \p thrust::host, \p thrust::device, and each backend system's tag type. - * - * Custom user-defined backends should derive a policy from this type in order to - * interoperate with Thrust algorithm dispatch. - * - * The following code snippet demonstrates how to derive a standalone custom execution policy - * from \p thrust::execution_policy to implement a backend which only implements \p for_each: - * - * \code - * #include - * #include - * - * // define a type derived from thrust::execution_policy to distinguish our custom execution policy: - * struct my_policy : thrust::execution_policy {}; - * - * // overload for_each on my_policy - * template - * Iterator for_each(my_policy, Iterator first, Iterator last, Function f) - * { - * std::cout << "Hello, world from for_each(my_policy)!" << std::endl; - * - * for(; first < last; ++first) - * { - * f(*first); - * } - * - * return first; - * } - * - * struct ignore_argument - * { - * void operator()(int) {} - * }; - * - * int main() - * { - * int data[4]; - * - * // dispatch thrust::for_each using our custom policy: - * my_policy exec; - * thrust::for_each(exec, data, data + 4, ignore_argument()); - * - * // can't dispatch thrust::transform because no overload exists for my_policy: - * //thrust::transform(exec, data, data, + 4, data, thrust::identity()); // error! - * - * return 0; - * } - * \endcode - * - * \see host_execution_policy - * \see device_execution_policy - */ -template -struct execution_policy : thrust::detail::execution_policy_base -{}; -#endif - - -/*! \p host_execution_policy is the base class for all Thrust parallel execution policies - * which are derived from Thrust's default host backend system configured with the \p THRUST_HOST_SYSTEM - * macro. - * - * Custom user-defined backends which wish to inherit the functionality of Thrust's host backend system - * should derive a policy from this type in order to interoperate with Thrust algorithm dispatch. - * - * The following code snippet demonstrates how to derive a standalone custom execution policy from - * \p thrust::host_execution_policy to implement a backend which specializes \p for_each while inheriting - * the behavior of every other algorithm from the host system: - * - * \code - * #include - * #include - * - * // define a type derived from thrust::host_execution_policy to distinguish our custom execution policy: - * struct my_policy : thrust::host_execution_policy {}; - * - * // overload for_each on my_policy - * template - * Iterator for_each(my_policy, Iterator first, Iterator last, Function f) - * { - * std::cout << "Hello, world from for_each(my_policy)!" << std::endl; - * - * for(; first < last; ++first) - * { - * f(*first); - * } - * - * return first; - * } - * - * struct ignore_argument - * { - * void operator()(int) {} - * }; - * - * int main() - * { - * int data[4]; - * - * // dispatch thrust::for_each using our custom policy: - * my_policy exec; - * thrust::for_each(exec, data, data + 4, ignore_argument()); - * - * // dispatch thrust::transform whose behavior our policy inherits - * thrust::transform(exec, data, data, + 4, data, thrust::identity()); - * - * return 0; - * } - * \endcode - * - * \see execution_policy - * \see device_execution_policy - */ -template - struct host_execution_policy - : thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::execution_policy -{}; - - -/*! \p device_execution_policy is the base class for all Thrust parallel execution policies - * which are derived from Thrust's default device backend system configured with the \p THRUST_DEVICE_SYSTEM - * macro. - * - * Custom user-defined backends which wish to inherit the functionality of Thrust's device backend system - * should derive a policy from this type in order to interoperate with Thrust algorithm dispatch. - * - * The following code snippet demonstrates how to derive a standalone custom execution policy from - * \p thrust::device_execution_policy to implement a backend which specializes \p for_each while inheriting - * the behavior of every other algorithm from the device system: - * - * \code - * #include - * #include - * - * // define a type derived from thrust::device_execution_policy to distinguish our custom execution policy: - * struct my_policy : thrust::device_execution_policy {}; - * - * // overload for_each on my_policy - * template - * Iterator for_each(my_policy, Iterator first, Iterator last, Function f) - * { - * std::cout << "Hello, world from for_each(my_policy)!" << std::endl; - * - * for(; first < last; ++first) - * { - * f(*first); - * } - * - * return first; - * } - * - * struct ignore_argument - * { - * void operator()(int) {} - * }; - * - * int main() - * { - * int data[4]; - * - * // dispatch thrust::for_each using our custom policy: - * my_policy exec; - * thrust::for_each(exec, data, data + 4, ignore_argument()); - * - * // dispatch thrust::transform whose behavior our policy inherits - * thrust::transform(exec, data, data, + 4, data, thrust::identity()); - * - * return 0; - * } - * \endcode - * - * \see execution_policy - * \see host_execution_policy - */ -template - struct device_execution_policy - : thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::execution_policy -{}; - - -/*! \p thrust::host is the default parallel execution policy associated with Thrust's host backend system - * configured by the \p THRUST_HOST_SYSTEM macro. - * - * Instead of relying on implicit algorithm dispatch through iterator system tags, users may directly target - * algorithm dispatch at Thrust's host system by providing \p thrust::host as an algorithm parameter. - * - * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such as - * \p thrust::host_vector. - * - * Note that even though \p thrust::host targets the host CPU, it is a parallel execution policy. That is, - * the order that an algorithm invokes functors or dereferences iterators is not defined. - * - * The type of \p thrust::host is implementation-defined. - * - * The following code snippet demonstrates how to use \p thrust::host to explicitly dispatch an invocation - * of \p thrust::for_each to the host backend system: - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * printf("%d\n"); - * } - * }; - * ... - * int vec[3]; - * vec[0] = 0; vec[1] = 1; vec[2] = 2; - * - * thrust::for_each(thrust::host, vec.begin(), vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - * - * \see host_execution_policy - * \see thrust::device - */ -static const detail::host_t host; - - -/*! \p thrust::device is the default parallel execution policy associated with Thrust's device backend system - * configured by the \p THRUST_DEVICE_SYSTEM macro. - * - * Instead of relying on implicit algorithm dispatch through iterator system tags, users may directly target - * algorithm dispatch at Thrust's device system by providing \p thrust::device as an algorithm parameter. - * - * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such as - * \p thrust::device_vector or to avoid wrapping e.g. raw pointers allocated by the CUDA API with types - * such as \p thrust::device_ptr. - * - * The user must take care to guarantee that the iterators provided to an algorithm are compatible with - * the device backend system. For example, raw pointers allocated by std::malloc typically - * cannot be dereferenced by a GPU. For this reason, raw pointers allocated by host APIs should not be mixed - * with a \p thrust::device algorithm invocation when the device backend is CUDA. - * - * The type of \p thrust::device is implementation-defined. - * - * The following code snippet demonstrates how to use \p thrust::device to explicitly dispatch an invocation - * of \p thrust::for_each to the device backend system: - * - * \code - * #include - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * printf("%d\n"); - * } - * }; - * ... - * thrust::device_vector d_vec[3]; - * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; - * - * thrust::for_each(thrust::device, vec.begin(), vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - * - * \see host_execution_policy - * \see thrust::device - */ -static const detail::device_t device; - - -/*! \} - */ - - -} // end thrust - diff --git a/compat/thrust/extrema.h b/compat/thrust/extrema.h deleted file mode 100644 index 335bcd1..0000000 --- a/compat/thrust/extrema.h +++ /dev/null @@ -1,798 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file extrema.h - * \brief Functions for computing computing extremal values - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! This version of \p min returns the smaller of two values, given a comparison operation. - * \param lhs The first value to compare. - * \param rhs The second value to compare. - * \param comp A comparison operation. - * \return The smaller element. - * - * \tparam T is convertible to \p BinaryPredicate's first argument type and to its second argument type. - * \tparam BinaryPredicate is a model of BinaryPredicate. - * - * The following code snippet demonstrates how to use \p min to compute the smaller of two - * key-value objects. - * - * \code - * #include - * ... - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value a = {13, 0}; - * key_value b = { 7, 1); - * - * key_value smaller = thrust::min(a, b, compare_key_value()); - * - * // smaller is {7, 1} - * \endcode - * - * \note Returns the first argument when the arguments are equivalent. - * \see max - */ -template -__host__ __device__ - T min THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs, BinaryPredicate comp); - - -/*! This version of \p min returns the smaller of two values. - * \param lhs The first value to compare. - * \param rhs The second value to compare. - * \return The smaller element. - * - * \tparam T is a model of LessThan Comparable. - * - * The following code snippet demonstrates how to use \p min to compute the smaller of two - * integers. - * - * \code - * #include - * ... - * int a = 13; - * int b = 7; - * - * int smaller = thrust::min(a, b); - * - * // smaller is 7 - * \endcode - * - * \note Returns the first argument when the arguments are equivalent. - * \see max - */ -template -__host__ __device__ - T min THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs); - - -/*! This version of \p max returns the larger of two values, given a comparison operation. - * \param lhs The first value to compare. - * \param rhs The second value to compare. - * \param comp A comparison operation. - * \return The larger element. - * - * \tparam T is convertible to \p BinaryPredicate's first argument type and to its second argument type. - * \tparam BinaryPredicate is a model of BinaryPredicate. - * - * The following code snippet demonstrates how to use \p max to compute the larger of two - * key-value objects. - * - * \code - * #include - * ... - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value a = {13, 0}; - * key_value b = { 7, 1); - * - * key_value larger = thrust::max(a, b, compare_key_value()); - * - * // larger is {13, 0} - * \endcode - * - * \note Returns the first argument when the arguments are equivalent. - * \see min - */ -template -__host__ __device__ - T max THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs, BinaryPredicate comp); - - -/*! This version of \p max returns the larger of two values. - * \param lhs The first value to compare. - * \param rhs The second value to compare. - * \return The larger element. - * - * \tparam T is a model of LessThan Comparable. - * - * The following code snippet demonstrates how to use \p max to compute the larger of two - * integers. - * - * \code - * #include - * ... - * int a = 13; - * int b = 7; - * - * int larger = thrust::min(a, b); - * - * // larger is 13 - * \endcode - * - * \note Returns the first argument when the arguments are equivalent. - * \see min - */ -template -__host__ __device__ - T max THRUST_PREVENT_MACRO_SUBSTITUTION (const T &lhs, const T &rhs); - - -/*! \addtogroup reductions - * \{ - * \addtogroup extrema - * \ingroup reductions - * \{ - */ - -/*! \p min_element finds the smallest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value smaller - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p min_element differ in how they define whether one element is - * less than another. This version compares objects using \c operator<. Specifically, - * this version of \p min_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), *j < *i is - * \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return An iterator pointing to the smallest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \c ForwardIterator's \c value_type is a model of - * LessThan Comparable. - * - * \code - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int *result = thrust::min_element(thrust::host, data, data + 6); - * - * // result is data + 1 - * // *result is 0 - * \endcode - * - * \see http://www.sgi.com/tech/stl/min_element.html - */ -template -ForwardIterator min_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last); - - -/*! \p min_element finds the smallest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value smaller - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p min_element differ in how they define whether one element is - * less than another. This version compares objects using \c operator<. Specifically, - * this version of \p min_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), *j < *i is - * \c false. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return An iterator pointing to the smallest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \c ForwardIterator's \c value_type is a model of - * LessThan Comparable. - * - * \code - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int *result = thrust::min_element(data, data + 6); - * - * // result is data + 1 - * // *result is 0 - * \endcode - * - * \see http://www.sgi.com/tech/stl/min_element.html - */ -template -ForwardIterator min_element(ForwardIterator first, ForwardIterator last); - - -/*! \p min_element finds the smallest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value smaller - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p min_element differ in how they define whether one element is - * less than another. This version compares objects using a function object \p comp. - * Specifically, this version of \p min_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), comp(*j, *i) is - * \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp A binary predicate used for comparison. - * \return An iterator pointing to the smallest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \p comp's - * \c first_argument_type and \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p min_element to find the smallest element - * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; - * - * key_value *smallest = thrust::min_element(thrust::host, data, data + 4, compare_key_value()); - * - * // smallest == data + 1 - * // *smallest == {0,7} - * \endcode - * - * \see http://www.sgi.com/tech/stl/min_element.html - */ -template -ForwardIterator min_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp); - - -/*! \p min_element finds the smallest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value smaller - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p min_element differ in how they define whether one element is - * less than another. This version compares objects using a function object \p comp. - * Specifically, this version of \p min_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), comp(*j, *i) is - * \c false. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp A binary predicate used for comparison. - * \return An iterator pointing to the smallest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \p comp's - * \c first_argument_type and \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p min_element to find the smallest element - * of a collection of key-value pairs. - * - * \code - * #include - * - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; - * - * key_value *smallest = thrust::min_element(data, data + 4, compare_key_value()); - * - * // smallest == data + 1 - * // *smallest == {0,7} - * \endcode - * - * \see http://www.sgi.com/tech/stl/min_element.html - */ -template -ForwardIterator min_element(ForwardIterator first, ForwardIterator last, - BinaryPredicate comp); - - -/*! \p max_element finds the largest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value larger - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p max_element differ in how they define whether one element is - * greater than another. This version compares objects using \c operator<. Specifically, - * this version of \p max_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), *i < *j is - * \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return An iterator pointing to the largest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam A Thrust backend system. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \c ForwardIterator's \c value_type is a model of - * LessThan Comparable. - * - * \code - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int *result = thrust::max_element(thrust::host, data, data + 6); - * - * // *result == 3 - * \endcode - * - * \see http://www.sgi.com/tech/stl/max_element.html - */ -template -ForwardIterator max_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last); - - -/*! \p max_element finds the largest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value larger - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p max_element differ in how they define whether one element is - * greater than another. This version compares objects using \c operator<. Specifically, - * this version of \p max_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), *i < *j is - * \c false. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return An iterator pointing to the largest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \c ForwardIterator's \c value_type is a model of - * LessThan Comparable. - * - * \code - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int *result = thrust::max_element(data, data + 6); - * - * // *result == 3 - * \endcode - * - * \see http://www.sgi.com/tech/stl/max_element.html - */ -template -ForwardIterator max_element(ForwardIterator first, ForwardIterator last); - - -/*! \p max_element finds the largest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value larger - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p max_element differ in how they define whether one element is - * less than another. This version compares objects using a function object \p comp. - * Specifically, this version of \p max_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), comp(*i, *j) is - * \c false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp A binary predicate used for comparison. - * \return An iterator pointing to the largest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \p comp's - * \c first_argument_type and \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p max_element to find the largest element - * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization. - * - * \code - * #include - * #include - * ... - * - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; - * - * key_value *largest = thrust::max_element(thrust::host, data, data + 4, compare_key_value()); - * - * // largest == data + 3 - * // *largest == {6,1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/max_element.html - */ -template -ForwardIterator max_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp); - - -/*! \p max_element finds the largest element in the range [first, last). - * It returns the first iterator \c i in [first, last) - * such that no other iterator in [first, last) points to a value larger - * than \c *i. The return value is \p last if and only if [first, last) is an - * empty range. - * - * The two versions of \p max_element differ in how they define whether one element is - * less than another. This version compares objects using a function object \p comp. - * Specifically, this version of \p max_element returns the first iterator \c i in [first, last) - * such that, for every iterator \c j in [first, last), comp(*i, *j) is - * \c false. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp A binary predicate used for comparison. - * \return An iterator pointing to the largest element of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \p comp's - * \c first_argument_type and \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p max_element to find the largest element - * of a collection of key-value pairs. - * - * \code - * #include - * - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; - * - * key_value *largest = thrust::max_element(data, data + 4, compare_key_value()); - * - * // largest == data + 3 - * // *largest == {6,1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/max_element.html - */ -template -ForwardIterator max_element(ForwardIterator first, ForwardIterator last, - BinaryPredicate comp); - - -/*! \p minmax_element finds the smallest and largest elements in the range [first, last). - * It returns a pair of iterators (imin, imax) where \c imin is the same iterator - * returned by \p min_element and \c imax is the same iterator returned by \p max_element. - * This function is potentially more efficient than separate calls to \p min_element and \p max_element. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \c ForwardIterator's \c value_type is a model of - * LessThan Comparable. - * - * \code - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * thrust::pair result = thrust::minmax_element(thrust::host, data, data + 6); - * - * // result.first is data + 1 - * // result.second is data + 5 - * // *result.first is 0 - * // *result.second is 3 - * \endcode - * - * \see min_element - * \see max_element - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf - */ -template -thrust::pair minmax_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last); - - -/*! \p minmax_element finds the smallest and largest elements in the range [first, last). - * It returns a pair of iterators (imin, imax) where \c imin is the same iterator - * returned by \p min_element and \c imax is the same iterator returned by \p max_element. - * This function is potentially more efficient than separate calls to \p min_element and \p max_element. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \c ForwardIterator's \c value_type is a model of - * LessThan Comparable. - * - * \code - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * thrust::pair result = thrust::minmax_element(data, data + 6); - * - * // result.first is data + 1 - * // result.second is data + 5 - * // *result.first is 0 - * // *result.second is 3 - * \endcode - * - * \see min_element - * \see max_element - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf - */ -template -thrust::pair minmax_element(ForwardIterator first, - ForwardIterator last); - - -/*! \p minmax_element finds the smallest and largest elements in the range [first, last). - * It returns a pair of iterators (imin, imax) where \c imin is the same iterator - * returned by \p min_element and \c imax is the same iterator returned by \p max_element. - * This function is potentially more efficient than separate calls to \p min_element and \p max_element. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp A binary predicate used for comparison. - * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \p comp's - * \c first_argument_type and \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p minmax_element to find the smallest and largest elements - * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; - * - * thrust::pair extrema = thrust::minmax_element(thrust::host, data, data + 4, compare_key_value()); - * - * // extrema.first == data + 1 - * // *extrema.first == {0,7} - * // extrema.second == data + 3 - * // *extrema.second == {6,1} - * \endcode - * - * \see min_element - * \see max_element - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf - */ -template -thrust::pair minmax_element(const thrust::detail::execution_policy_base &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp); - - -/*! \p minmax_element finds the smallest and largest elements in the range [first, last). - * It returns a pair of iterators (imin, imax) where \c imin is the same iterator - * returned by \p min_element and \c imax is the same iterator returned by \p max_element. - * This function is potentially more efficient than separate calls to \p min_element and \p max_element. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp A binary predicate used for comparison. - * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), - * if it is not an empty range; \p last, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \p comp's - * \c first_argument_type and \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p minmax_element to find the smallest and largest elements - * of a collection of key-value pairs. - * - * \code - * #include - * #include - * - * struct key_value - * { - * int key; - * int value; - * }; - * - * struct compare_key_value - * { - * __host__ __device__ - * bool operator()(key_value lhs, key_value rhs) - * { - * return lhs.key < rhs.key; - * } - * }; - * - * ... - * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; - * - * thrust::pair extrema = thrust::minmax_element(data, data + 4, compare_key_value()); - * - * // extrema.first == data + 1 - * // *extrema.first == {0,7} - * // extrema.second == data + 3 - * // *extrema.second == {6,1} - * \endcode - * - * \see min_element - * \see max_element - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf - */ -template -thrust::pair minmax_element(ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp); - -/*! \} // end extrema - * \} // end reductions - */ - -} // end thrust - -#include -#include - diff --git a/compat/thrust/fill.h b/compat/thrust/fill.h deleted file mode 100644 index b492cec..0000000 --- a/compat/thrust/fill.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file fill.h - * \brief Fills a range with a constant value - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup transformations - * \addtogroup filling - * \ingroup transformations - * \{ - */ - - -/*! \p fill assigns the value \p value to every element in - * the range [first, last). That is, for every - * iterator \c i in [first, last), it performs - * the assignment *i = value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param value The value to be copied. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam T is a model of Assignable, - * and \p T's \c value_type is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's - * elements to a given value using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector v(4); - * thrust::fill(thrust::device, v.begin(), v.end(), 137); - * - * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 - * \endcode - * - * \see http://www.sgi.com/tech/stl/fill.html - * \see \c fill_n - * \see \c uninitialized_fill - */ -template - void fill(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value); - - -/*! \p fill assigns the value \p value to every element in - * the range [first, last). That is, for every - * iterator \c i in [first, last), it performs - * the assignment *i = value. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param value The value to be copied. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam T is a model of Assignable, - * and \p T's \c value_type is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's - * elements to a given value. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(4); - * thrust::fill(v.begin(), v.end(), 137); - * - * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 - * \endcode - * - * \see http://www.sgi.com/tech/stl/fill.html - * \see \c fill_n - * \see \c uninitialized_fill - */ -template - void fill(ForwardIterator first, - ForwardIterator last, - const T &value); - - -/*! \p fill_n assigns the value \p value to every element in - * the range [first, first+n). That is, for every - * iterator \c i in [first, first+n), it performs - * the assignment *i = value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param n The size of the sequence. - * \param value The value to be copied. - * \return first + n - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam T is a model of Assignable, - * and \p T's \c value_type is convertible to a type in \p OutputIterator's set of \c value_type. - * - * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's - * elements to a given value using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector v(4); - * thrust::fill_n(thrust::device, v.begin(), v.size(), 137); - * - * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 - * \endcode - * - * \see http://www.sgi.com/tech/stl/fill_n.html - * \see \c fill - * \see \c uninitialized_fill_n - */ -template - OutputIterator fill_n(const thrust::detail::execution_policy_base &exec, - OutputIterator first, - Size n, - const T &value); - - -/*! \p fill_n assigns the value \p value to every element in - * the range [first, first+n). That is, for every - * iterator \c i in [first, first+n), it performs - * the assignment *i = value. - * - * \param first The beginning of the sequence. - * \param n The size of the sequence. - * \param value The value to be copied. - * \return first + n - * - * \tparam OutputIterator is a model of Output Iterator. - * \tparam T is a model of Assignable, - * and \p T's \c value_type is convertible to a type in \p OutputIterator's set of \c value_type. - * - * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's - * elements to a given value. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(4); - * thrust::fill_n(v.begin(), v.size(), 137); - * - * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 - * \endcode - * - * \see http://www.sgi.com/tech/stl/fill_n.html - * \see \c fill - * \see \c uninitialized_fill_n - */ -template - OutputIterator fill_n(OutputIterator first, - Size n, - const T &value); - - -/*! \} // end filling - * \} // transformations - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/find.h b/compat/thrust/find.h deleted file mode 100644 index fa01ded..0000000 --- a/compat/thrust/find.h +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file find.h - * \brief Locating values in (unsorted) ranges - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - -/*! \addtogroup searching - * \ingroup algorithms - * \{ - */ - - -/*! \p find returns the first iterator \c i in the range - * [first, last) such that *i == value - * or \c last if no such iterator exists. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first Beginning of the sequence to search. - * \param last End of the sequence to search. - * \param value The value to find. - * \return The first iterator \c i such that *i == value or \c last. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \p InputIterator's \c value_type is equality comparable to type \c T. - * \tparam T is a model of EqualityComparable. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector input(4); - * - * input[0] = 0; - * input[1] = 5; - * input[2] = 3; - * input[3] = 7; - * - * thrust::device_vector::iterator iter; - * - * iter = thrust::find(thrust::device, input.begin(), input.end(), 3); // returns input.first() + 2 - * iter = thrust::find(thrust::device, input.begin(), input.end(), 5); // returns input.first() + 1 - * iter = thrust::find(thrust::device, input.begin(), input.end(), 9); // returns input.end() - * \endcode - * - * \see find_if - * \see mismatch - */ -template -InputIterator find(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - const T& value); - - -/*! \p find returns the first iterator \c i in the range - * [first, last) such that *i == value - * or \c last if no such iterator exists. - * - * \param first Beginning of the sequence to search. - * \param last End of the sequence to search. - * \param value The value to find. - * \return The first iterator \c i such that *i == value or \c last. - * - * \tparam InputIterator is a model of Input Iterator - * and \p InputIterator's \c value_type is equality comparable to type \c T. - * \tparam T is a model of EqualityComparable. - * - * \code - * #include - * #include - * ... - * thrust::device_vector input(4); - * - * input[0] = 0; - * input[1] = 5; - * input[2] = 3; - * input[3] = 7; - * - * thrust::device_vector::iterator iter; - * - * iter = thrust::find(input.begin(), input.end(), 3); // returns input.first() + 2 - * iter = thrust::find(input.begin(), input.end(), 5); // returns input.first() + 1 - * iter = thrust::find(input.begin(), input.end(), 9); // returns input.end() - * \endcode - * - * \see find_if - * \see mismatch - */ -template -InputIterator find(InputIterator first, - InputIterator last, - const T& value); - - -/*! \p find_if returns the first iterator \c i in the range - * [first, last) such that pred(*i) is \c true - * or \c last if no such iterator exists. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first Beginning of the sequence to search. - * \param last End of the sequence to search. - * \param pred A predicate used to test range elements. - * \return The first iterator \c i such that pred(*i) is \c true, or \c last. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator. - * \tparam Predicate is a model of Predicate. - * - * \code - * #include - * #include - * #include - * ... - * - * struct greater_than_four - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 4; - * } - * }; - * - * struct greater_than_ten - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 10; - * } - * }; - * - * ... - * thrust::device_vector input(4); - * - * input[0] = 0; - * input[1] = 5; - * input[2] = 3; - * input[3] = 7; - * - * thrust::device_vector::iterator iter; - * - * iter = thrust::find_if(thrust::device, input.begin(), input.end(), greater_than_four()); // returns input.first() + 1 - * - * iter = thrust::find_if(thrust::device, input.begin(), input.end(), greater_than_ten()); // returns input.end() - * \endcode - * - * \see find - * \see find_if_not - * \see mismatch - */ -template -InputIterator find_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - Predicate pred); - - -/*! \p find_if returns the first iterator \c i in the range - * [first, last) such that pred(*i) is \c true - * or \c last if no such iterator exists. - * - * \param first Beginning of the sequence to search. - * \param last End of the sequence to search. - * \param pred A predicate used to test range elements. - * \return The first iterator \c i such that pred(*i) is \c true, or \c last. - * - * \tparam InputIterator is a model of Input Iterator. - * \tparam Predicate is a model of Predicate. - * - * \code - * #include - * #include - * - * struct greater_than_four - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 4; - * } - * }; - * - * struct greater_than_ten - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 10; - * } - * }; - * - * ... - * thrust::device_vector input(4); - * - * input[0] = 0; - * input[1] = 5; - * input[2] = 3; - * input[3] = 7; - * - * thrust::device_vector::iterator iter; - * - * iter = thrust::find_if(input.begin(), input.end(), greater_than_four()); // returns input.first() + 1 - * - * iter = thrust::find_if(input.begin(), input.end(), greater_than_ten()); // returns input.end() - * \endcode - * - * \see find - * \see find_if_not - * \see mismatch - */ -template -InputIterator find_if(InputIterator first, - InputIterator last, - Predicate pred); - - -/*! \p find_if_not returns the first iterator \c i in the range - * [first, last) such that pred(*i) is \c false - * or \c last if no such iterator exists. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first Beginning of the sequence to search. - * \param last End of the sequence to search. - * \param pred A predicate used to test range elements. - * \return The first iterator \c i such that pred(*i) is \c false, or \c last. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator. - * \tparam Predicate is a model of Predicate. - * - * \code - * #include - * #include - * #include - * ... - * - * struct greater_than_four - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 4; - * } - * }; - * - * struct greater_than_ten - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 10; - * } - * }; - * - * ... - * thrust::device_vector input(4); - * - * input[0] = 0; - * input[1] = 5; - * input[2] = 3; - * input[3] = 7; - * - * thrust::device_vector::iterator iter; - * - * iter = thrust::find_if_not(thrust::device, input.begin(), input.end(), greater_than_four()); // returns input.first() - * - * iter = thrust::find_if_not(thrust::device, input.begin(), input.end(), greater_than_ten()); // returns input.first() - * \endcode - * - * \see find - * \see find_if - * \see mismatch - */ -template -InputIterator find_if_not(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - Predicate pred); - - -/*! \p find_if_not returns the first iterator \c i in the range - * [first, last) such that pred(*i) is \c false - * or \c last if no such iterator exists. - * - * \param first Beginning of the sequence to search. - * \param last End of the sequence to search. - * \param pred A predicate used to test range elements. - * \return The first iterator \c i such that pred(*i) is \c false, or \c last. - * - * \tparam InputIterator is a model of Input Iterator. - * \tparam Predicate is a model of Predicate. - * - * \code - * #include - * #include - * - * struct greater_than_four - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 4; - * } - * }; - * - * struct greater_than_ten - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x > 10; - * } - * }; - * - * ... - * thrust::device_vector input(4); - * - * input[0] = 0; - * input[1] = 5; - * input[2] = 3; - * input[3] = 7; - * - * thrust::device_vector::iterator iter; - * - * iter = thrust::find_if_not(input.begin(), input.end(), greater_than_four()); // returns input.first() - * - * iter = thrust::find_if_not(input.begin(), input.end(), greater_than_ten()); // returns input.first() - * \endcode - * - * \see find - * \see find_if - * \see mismatch - */ -template -InputIterator find_if_not(InputIterator first, - InputIterator last, - Predicate pred); - -/*! \} // end searching - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/for_each.h b/compat/thrust/for_each.h deleted file mode 100644 index efab9d8..0000000 --- a/compat/thrust/for_each.h +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.h - * \brief Applies a function to each element in a range - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup modifying - * \ingroup transformations - * \{ - */ - - -/*! \p for_each applies the function object \p f to each element - * in the range [first, last); \p f's return value, if any, - * is ignored. Unlike the C++ Standard Template Library function - * std::for_each, this version offers no guarantee on - * order of execution. For this reason, this version of \p for_each - * does not return a copy of the function object. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param f The function object to apply to the range [first, last). - * \return last - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. - * \tparam UnaryFunction is a model of Unary Function, - * and \p UnaryFunction does not apply any non-constant operation through its argument. - * - * The following code snippet demonstrates how to use \p for_each to print the elements - * of a \p std::device_vector using the \p thrust::device parallelization policy: - * - * \code - * #include - * #include - * #include - * #include - * ... - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * // note that using printf in a __device__ function requires - * // code compiled for a GPU with compute capability 2.0 or - * // higher (nvcc --arch=sm_20) - * printf("%d\n"); - * } - * }; - * ... - * thrust::device_vector d_vec(3); - * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; - * - * thrust::for_each(thrust::device, d_vec.begin(), d_vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - * - * \see for_each_n - * \see http://www.sgi.com/tech/stl/for_each.html - */ -template -InputIterator for_each(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - UnaryFunction f); - - -/*! \p for_each_n applies the function object \p f to each element - * in the range [first, first + n); \p f's return value, if any, - * is ignored. Unlike the C++ Standard Template Library function - * std::for_each, this version offers no guarantee on - * order of execution. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param n The size of the input sequence. - * \param f The function object to apply to the range [first, first + n). - * \return first + n - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. - * \tparam Size is an integral type. - * \tparam UnaryFunction is a model of Unary Function, - * and \p UnaryFunction does not apply any non-constant operation through its argument. - * - * The following code snippet demonstrates how to use \p for_each_n to print the elements - * of a \p device_vector using the \p thrust::device parallelization policy. - * - * \code - * #include - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * // note that using printf in a __device__ function requires - * // code compiled for a GPU with compute capability 2.0 or - * // higher (nvcc --arch=sm_20) - * printf("%d\n"); - * } - * }; - * ... - * thrust::device_vector d_vec(3); - * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; - * - * thrust::for_each_n(thrust::device, d_vec.begin(), d_vec.size(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - * - * \see for_each - * \see http://www.sgi.com/tech/stl/for_each.html - */ -template -InputIterator for_each_n(const thrust::detail::execution_policy_base &exec, - InputIterator first, - Size n, - UnaryFunction f); - -/*! \p for_each applies the function object \p f to each element - * in the range [first, last); \p f's return value, if any, - * is ignored. Unlike the C++ Standard Template Library function - * std::for_each, this version offers no guarantee on - * order of execution. For this reason, this version of \p for_each - * does not return a copy of the function object. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param f The function object to apply to the range [first, last). - * \return last - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. - * \tparam UnaryFunction is a model of Unary Function, - * and \p UnaryFunction does not apply any non-constant operation through its argument. - * - * The following code snippet demonstrates how to use \p for_each to print the elements - * of a \p device_vector. - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * // note that using printf in a __device__ function requires - * // code compiled for a GPU with compute capability 2.0 or - * // higher (nvcc --arch=sm_20) - * printf("%d\n"); - * } - * }; - * ... - * thrust::device_vector d_vec(3); - * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; - * - * thrust::for_each(d_vec.begin(), d_vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - * - * \see for_each_n - * \see http://www.sgi.com/tech/stl/for_each.html - */ -template -InputIterator for_each(InputIterator first, - InputIterator last, - UnaryFunction f); - - -/*! \p for_each_n applies the function object \p f to each element - * in the range [first, first + n); \p f's return value, if any, - * is ignored. Unlike the C++ Standard Template Library function - * std::for_each, this version offers no guarantee on - * order of execution. - * - * \param first The beginning of the sequence. - * \param n The size of the input sequence. - * \param f The function object to apply to the range [first, first + n). - * \return first + n - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. - * \tparam Size is an integral type. - * \tparam UnaryFunction is a model of Unary Function, - * and \p UnaryFunction does not apply any non-constant operation through its argument. - * - * The following code snippet demonstrates how to use \p for_each_n to print the elements - * of a \p device_vector. - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * // note that using printf in a __device__ function requires - * // code compiled for a GPU with compute capability 2.0 or - * // higher (nvcc --arch=sm_20) - * printf("%d\n"); - * } - * }; - * ... - * thrust::device_vector d_vec(3); - * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; - * - * thrust::for_each_n(d_vec.begin(), d_vec.size(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - * - * \see for_each - * \see http://www.sgi.com/tech/stl/for_each.html - */ -template -InputIterator for_each_n(InputIterator first, - Size n, - UnaryFunction f); - -/*! \} // end modifying - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/functional.h b/compat/thrust/functional.h deleted file mode 100644 index b3d47f9..0000000 --- a/compat/thrust/functional.h +++ /dev/null @@ -1,1079 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file functional.h - * \brief Function objects and tools for manipulating them - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup function_objects Function Objects - */ - -template struct unary_traits; - -template struct binary_traits; - -/*! \addtogroup function_object_adaptors Function Object Adaptors - * \ingroup function_objects - * \{ - */ - -/*! \p unary_function is an empty base class: it contains no member functions - * or member variables, but only type information. The only reason it exists - * is to make it more convenient to define types that are models of the - * concept Adaptable Unary Function. Specifically, any model of Adaptable - * Unary Function must define nested \c typedefs. Those \c typedefs are - * provided by the base class \p unary_function. - * - * The following code snippet demonstrates how to construct an - * Adaptable Unary Function using \p unary_function. - * - * \code - * struct sine : public thrust::unary_function - * { - * __host__ __device__ - * float operator()(float x) { return sinf(x); } - * }; - * \endcode - * - * \note unary_function is currently redundant with the C++ STL type - * \c std::unary_function. We reserve it here for potential additional - * functionality at a later date. - * - * \see http://www.sgi.com/tech/stl/unary_function.html - * \see binary_function - */ -template - struct unary_function - : public std::unary_function -{ -}; // end unary_function - -/*! \p binary_function is an empty base class: it contains no member functions - * or member variables, but only type information. The only reason it exists - * is to make it more convenient to define types that are models of the - * concept Adaptable Binary Function. Specifically, any model of Adaptable - * Binary Function must define nested \c typedefs. Those \c typedefs are - * provided by the base class \p binary_function. - * - * The following code snippet demonstrates how to construct an - * Adaptable Binary Function using \p binary_function. - * - * \code - * struct exponentiate : public thrust::binary_function - * { - * __host__ __device__ - * float operator()(float x, float y) { return powf(x,y); } - * }; - * \endcode - * - * \note binary_function is currently redundant with the C++ STL type - * \c std::binary_function. We reserve it here for potential additional - * functionality at a later date. - * - * \see http://www.sgi.com/tech/stl/binary_function.html - * \see unary_function - */ -template - struct binary_function - : public std::binary_function -{ -}; // end binary_function - -/*! \} - */ - - -/*! \addtogroup predefined_function_objects Predefined Function Objects - * \ingroup function_objects - */ - -/*! \addtogroup arithmetic_operations Arithmetic Operations - * \ingroup predefined_function_objects - * \{ - */ - -/*! \p plus is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class plus, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x+y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x+y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use plus to sum two - * device_vectors of \c floats. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 75); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::plus()); - * // V3 is now {76, 77, 78, ..., 1075} - * \endcode - * - * \see http://www.sgi.com/tech/stl/plus.html - * \see binary_function - */ -template - struct plus : public binary_function -{ - /*! Function call operator. The return value is lhs + rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs + rhs;} -}; // end plus - -/*! \p minus is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class minus, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x-y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x-y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use minus to subtract - * a device_vector of \c floats from another. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 75); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::minus()); - * // V3 is now {-74, -75, -76, ..., -925} - * \endcode - * - * \see http://www.sgi.com/tech/stl/minus.html - * \see binary_function - */ -template - struct minus : public binary_function -{ - /*! Function call operator. The return value is lhs - rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs - rhs;} -}; // end minus - -/*! \p multiplies is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class minus, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x*y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x*y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use multiplies to multiply - * two device_vectors of \c floats. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 75); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::multiplies()); - * // V3 is now {75, 150, 225, ..., 75000} - * \endcode - * - * \see http://www.sgi.com/tech/stl/multiplies.html - * \see binary_function - */ -template - struct multiplies : public binary_function -{ - /*! Function call operator. The return value is lhs * rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs * rhs;} -}; // end multiplies - -/*! \p divides is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class divides, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x/y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x/y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use divides to divide - * one device_vectors of \c floats by another. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 75); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::divides()); - * // V3 is now {1/75, 2/75, 3/75, ..., 1000/75} - * \endcode - * - * \see http://www.sgi.com/tech/stl/divides.html - * \see binary_function - */ -template - struct divides : public binary_function -{ - /*! Function call operator. The return value is lhs / rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs / rhs;} -}; // end divides - -/*! \p modulus is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class divides, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x%y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x%y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use modulus to take - * the modulus of one device_vectors of \c floats by another. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 75); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::modulus()); - * // V3 is now {1%75, 2%75, 3%75, ..., 1000%75} - * \endcode - * - * \see http://www.sgi.com/tech/stl/modulus.html - * \see binary_function - */ -template - struct modulus : public binary_function -{ - /*! Function call operator. The return value is lhs % rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs % rhs;} -}; // end modulus - -/*! \p negate is a function object. Specifically, it is an Adaptable Unary Function. - * If \c f is an object of class negate, and \c x is an object - * of class \c T, then f(x) returns -x. - * - * \tparam T is a model of Assignable, - * and if \c x is an object of type \p T, then -x must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use negate to negate - * the element of a device_vector of \c floats. - * - * \code - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), - * thrust::negate()); - * // V2 is now {-1, -2, -3, ..., -1000} - * \endcode - * - * \see http://www.sgi.com/tech/stl/negate.html - * \see unary_function - */ -template - struct negate : public unary_function -{ - /*! Function call operator. The return value is -x. - */ - __host__ __device__ T operator()(const T &x) const {return -x;} -}; // end negate - -/*! \} - */ - -/*! \addtogroup comparison_operations Comparison Operations - * \ingroup predefined_function_objects - * \{ - */ - -/*! \p equal_to is a function object. Specifically, it is an Adaptable Binary - * Predicate, which means it is a function object that tests the truth or falsehood - * of some condition. If \c f is an object of class equal_to and \c x - * and \c y are objects of class \c T, then f(x,y) returns \c true if - * x == y and \c false otherwise. - * - * \tparam T is a model of Equality Comparable. - * - * \see http://www.sgi.com/tech/stl/equal_to.html - * \see binary_function - */ -template - struct equal_to : public binary_function -{ - /*! Function call operator. The return value is lhs == rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs == rhs;} -}; // end equal_to - -/*! \p not_equal_to is a function object. Specifically, it is an Adaptable Binary - * Predicate, which means it is a function object that tests the truth or falsehood - * of some condition. If \c f is an object of class not_equal_to and \c x - * and \c y are objects of class \c T, then f(x,y) returns \c true if - * x != y and \c false otherwise. - * - * \tparam T is a model of Equality Comparable. - * - * \see http://www.sgi.com/tech/stl/not_equal_to.html - * \see binary_function - */ -template - struct not_equal_to : public binary_function -{ - /*! Function call operator. The return value is lhs != rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs != rhs;} -}; // end not_equal_to - -/*! \p greater is a function object. Specifically, it is an Adaptable Binary - * Predicate, which means it is a function object that tests the truth or falsehood - * of some condition. If \c f is an object of class greater and \c x - * and \c y are objects of class \c T, then f(x,y) returns \c true if - * x > y and \c false otherwise. - * - * \tparam T is a model of LessThan Comparable. - * - * \see http://www.sgi.com/tech/stl/greater.html - * \see binary_function - */ -template - struct greater : public binary_function -{ - /*! Function call operator. The return value is lhs > rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs > rhs;} -}; // end greater - -/*! \p less is a function object. Specifically, it is an Adaptable Binary - * Predicate, which means it is a function object that tests the truth or falsehood - * of some condition. If \c f is an object of class less and \c x - * and \c y are objects of class \c T, then f(x,y) returns \c true if - * x < y and \c false otherwise. - * - * \tparam T is a model of LessThan Comparable. - * - * \see http://www.sgi.com/tech/stl/less.html - * \see binary_function - */ -template - struct less : public binary_function -{ - /*! Function call operator. The return value is lhs < rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs < rhs;} -}; // end less - -/*! \p greater_equal is a function object. Specifically, it is an Adaptable Binary - * Predicate, which means it is a function object that tests the truth or falsehood - * of some condition. If \c f is an object of class greater_equal and \c x - * and \c y are objects of class \c T, then f(x,y) returns \c true if - * x >= y and \c false otherwise. - * - * \tparam T is a model of LessThan Comparable. - * - * \see http://www.sgi.com/tech/stl/greater_equal.html - * \see binary_function - */ -template - struct greater_equal : public binary_function -{ - /*! Function call operator. The return value is lhs >= rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs >= rhs;} -}; // end greater_equal - -/*! \p less_equal is a function object. Specifically, it is an Adaptable Binary - * Predicate, which means it is a function object that tests the truth or falsehood - * of some condition. If \c f is an object of class less_equal and \c x - * and \c y are objects of class \c T, then f(x,y) returns \c true if - * x <= y and \c false otherwise. - * - * \tparam T is a model of LessThan Comparable. - * - * \see http://www.sgi.com/tech/stl/less_equal.html - * \see binary_function - */ -template - struct less_equal : public binary_function -{ - /*! Function call operator. The return value is lhs <= rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs <= rhs;} -}; // end less_equal - -/*! \} - */ - - -/*! \addtogroup logical_operations Logical Operations - * \ingroup predefined_function_objects - * \{ - */ - -/*! \p logical_and is a function object. Specifically, it is an Adaptable Binary Predicate, - * which means it is a function object that tests the truth or falsehood of some condition. - * If \c f is an object of class logical_and and \c x and \c y are objects of - * class \c T (where \c T is convertible to \c bool) then f(x,y) returns \c true - * if and only if both \c x and \c y are \c true. - * - * \tparam T must be convertible to \c bool. - * - * \see http://www.sgi.com/tech/stl/logical_and.html - * \see binary_function - */ -template - struct logical_and : public binary_function -{ - /*! Function call operator. The return value is lhs && rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs && rhs;} -}; // end logical_and - -/*! \p logical_or is a function object. Specifically, it is an Adaptable Binary Predicate, - * which means it is a function object that tests the truth or falsehood of some condition. - * If \c f is an object of class logical_or and \c x and \c y are objects of - * class \c T (where \c T is convertible to \c bool) then f(x,y) returns \c true - * if and only if either \c x or \c y are \c true. - * - * \tparam T must be convertible to \c bool. - * - * \see http://www.sgi.com/tech/stl/logical_or.html - * \see binary_function - */ -template - struct logical_or : public binary_function -{ - /*! Function call operator. The return value is lhs || rhs. - */ - __host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs || rhs;} -}; // end logical_or - -/*! \p logical_not is a function object. Specifically, it is an Adaptable Predicate, - * which means it is a function object that tests the truth or falsehood of some condition. - * If \c f is an object of class logical_not and \c x is an object of - * class \c T (where \c T is convertible to \c bool) then f(x) returns \c true - * if and only if \c x is \c false. - * - * \tparam T must be convertible to \c bool. - * - * The following code snippet demonstrates how to use \p logical_not to transform - * a device_vector of \c bools into its logical complement. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector V; - * ... - * thrust::transform(V.begin(), V.end(), V.begin(), thrust::logical_not()); - * // The elements of V are now the logical complement of what they were prior - * \endcode - * - * \see http://www.sgi.com/tech/stl/logical_not.html - * \see unary_function - */ -template - struct logical_not : public unary_function -{ - /*! Function call operator. The return value is !x. - */ - __host__ __device__ bool operator()(const T &x) const {return !x;} -}; // end logical_not - -/*! \} - */ - -/*! \addtogroup bitwise_operations Bitwise Operations - * \ingroup predefined_function_objects - * \{ - */ - -/*! \p bit_and is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class bit_and, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x&y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x&y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use bit_and to take - * the bitwise AND of one device_vector of \c ints by another. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 13); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::bit_and()); - * // V3 is now {1&13, 2&13, 3&13, ..., 1000%13} - * \endcode - * - * \see binary_function - */ -template - struct bit_and : public binary_function -{ - /*! Function call operator. The return value is lhs & rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs & rhs;} -}; // end bit_and - -/*! \p bit_or is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class bit_and, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x|y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x|y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use bit_or to take - * the bitwise OR of one device_vector of \c ints by another. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 13); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::bit_or()); - * // V3 is now {1|13, 2|13, 3|13, ..., 1000|13} - * \endcode - * - * \see binary_function - */ -template - struct bit_or : public binary_function -{ - /*! Function call operator. The return value is lhs | rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs | rhs;} -}; // end bit_or - -/*! \p bit_xor is a function object. Specifically, it is an Adaptable Binary Function. - * If \c f is an object of class bit_and, and \c x and \c y are objects - * of class \c T, then f(x,y) returns x^y. - * - * \tparam T is a model of Assignable, - * and if \c x and \c y are objects of type \p T, then x^y must be defined and must have a return type that is convertible to \c T. - * - * The following code snippet demonstrates how to use bit_xor to take - * the bitwise XOR of one device_vector of \c ints by another. - * - * \code - * #include - * #include - * #include - * #include - * #include - * ... - * const int N = 1000; - * thrust::device_vector V1(N); - * thrust::device_vector V2(N); - * thrust::device_vector V3(N); - * - * thrust::sequence(V1.begin(), V1.end(), 1); - * thrust::fill(V2.begin(), V2.end(), 13); - * - * thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), - * thrust::bit_xor()); - * // V3 is now {1^13, 2^13, 3^13, ..., 1000^13} - * \endcode - * - * \see binary_function - */ -template - struct bit_xor : public binary_function -{ - /*! Function call operator. The return value is lhs ^ rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs ^ rhs;} -}; // end bit_xor - -/*! \} - */ - -/*! \addtogroup generalized_identity_operations Generalized Identity Operations - * \ingroup predefined_function_objects - * \{ - */ - -/*! \p identity is a Unary Function that represents the identity function: it takes - * a single argument \c x, and returns \c x. - * - * \tparam T No requirements on \p T. - * - * The following code snippet demonstrates that \p identity returns its - * argument. - * - * \code - * #include - * #include - * ... - * int x = 137; - * thrust::identity id; - * assert(x == id(x)); - * \endcode - * - * \see http://www.sgi.com/tech/stl/identity.html - * \see unary_function - */ -template - struct identity : public unary_function -{ - /*! Function call operator. The return value is x. - */ - __host__ __device__ const T &operator()(const T &x) const {return x;} -}; // end identity - -/*! \p maximum is a function object that takes two arguments and returns the greater - * of the two. Specifically, it is an Adaptable Binary Function. If \c f is an - * object of class maximum and \c x and \c y are objects of class \c T - * f(x,y) returns \c x if x > y and \c y, otherwise. - * - * \tparam T is a model of LessThan Comparable. - * - * The following code snippet demonstrates that \p maximum returns its - * greater argument. - * - * \code - * #include - * #include - * ... - * int x = 137; - * int y = -137; - * thrust::maximum mx; - * assert(x == mx(x,y)); - * \endcode - * - * \see minimum - * \see min - * \see binary_function - */ -template - struct maximum : public binary_function -{ - /*! Function call operator. The return value is rhs < lhs ? lhs : rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs < rhs ? rhs : lhs;} -}; // end maximum - -/*! \p minimum is a function object that takes two arguments and returns the lesser - * of the two. Specifically, it is an Adaptable Binary Function. If \c f is an - * object of class minimum and \c x and \c y are objects of class \c T - * f(x,y) returns \c x if x < y and \c y, otherwise. - * - * \tparam T is a model of LessThan Comparable. - * - * The following code snippet demonstrates that \p minimum returns its - * lesser argument. - * - * \code - * #include - * #include - * ... - * int x = 137; - * int y = -137; - * thrust::minimum mn; - * assert(y == mn(x,y)); - * \endcode - * - * \see maximum - * \see max - * \see binary_function - */ -template - struct minimum : public binary_function -{ - /*! Function call operator. The return value is lhs < rhs ? lhs : rhs. - */ - __host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs < rhs ? lhs : rhs;} -}; // end minimum - -/*! \p project1st is a function object that takes two arguments and returns - * its first argument; the second argument is unused. It is essentially a - * generalization of identity to the case of a Binary Function. - * - * \code - * #include - * #include - * ... - * int x = 137; - * int y = -137; - * thrust::project1st pj1; - * assert(x == pj1(x,y)); - * \endcode - * - * \see identity - * \see project2nd - * \see binary_function - */ -template - struct project1st : public binary_function -{ - /*! Function call operator. The return value is lhs. - */ - __host__ __device__ const T1 &operator()(const T1 &lhs, const T2 &rhs) const {return lhs;} -}; // end project1st - -/*! \p project2nd is a function object that takes two arguments and returns - * its second argument; the first argument is unused. It is essentially a - * generalization of identity to the case of a Binary Function. - * - * \code - * #include - * #include - * ... - * int x = 137; - * int y = -137; - * thrust::project2nd pj2; - * assert(y == pj2(x,y)); - * \endcode - * - * \see identity - * \see project1st - * \see binary_function - */ -template - struct project2nd : public binary_function -{ - /*! Function call operator. The return value is rhs. - */ - __host__ __device__ const T2 &operator()(const T1 &lhs, const T2 &rhs) const {return rhs;} -}; // end project2nd - -/*! \} - */ - - -// odds and ends - -/*! \addtogroup function_object_adaptors - * \{ - */ - -/*! \p unary_negate is a function object adaptor: it is an Adaptable Predicate - * that represents the logical negation of some other Adaptable Predicate. - * That is: if \c f is an object of class unary_negate, - * then there exists an object \c pred of class \c AdaptablePredicate such - * that f(x) always returns the same value as !pred(x). - * There is rarely any reason to construct a unary_negate directly; - * it is almost always easier to use the helper function not1. - * - * \see http://www.sgi.com/tech/stl/unary_negate.html - * \see not1 - */ -template -struct unary_negate - : public thrust::unary_function -{ - /*! Constructor takes a \p Predicate object to negate. - * \param p The \p Predicate object to negate. - */ - __host__ __device__ - explicit unary_negate(Predicate p) : pred(p){} - - /*! Function call operator. The return value is !pred(x). - */ - __host__ __device__ - bool operator()(const typename Predicate::argument_type& x) { return !pred(x); } - - /*! \cond */ - Predicate pred; - /*! \endcond */ -}; // end unary_negate - -/*! \p not1 is a helper function to simplify the creation of Adaptable Predicates: - * it takes an Adaptable Predicate \p pred as an argument and returns a new Adaptable - * Predicate that represents the negation of \p pred. That is: if \c pred is an object - * of a type which models Adaptable Predicate, then the the type of the result - * \c npred of not1(pred) is also a model of Adaptable Predicate and - * npred(x) always returns the same value as !pred(x). - * - * \param pred The Adaptable Predicate to negate. - * \return A new object, npred such that npred(x) always returns - * the same value as !pred(x). - * - * \tparam Predicate is a model of Adaptable Predicate. - * - * \see unary_negate - * \see not2 - */ -template - __host__ __device__ - unary_negate not1(const Predicate &pred); - -/*! \p binary_negate is a function object adaptor: it is an Adaptable Binary - * Predicate that represents the logical negation of some other Adaptable - * Binary Predicate. That is: if \c f is an object of class binary_negate, - * then there exists an object \c pred of class \c AdaptableBinaryPredicate - * such that f(x,y) always returns the same value as !pred(x,y). - * There is rarely any reason to construct a binary_negate directly; - * it is almost always easier to use the helper function not2. - * - * \see http://www.sgi.com/tech/stl/binary_negate.html - */ -template -struct binary_negate - : public thrust::binary_function -{ - /*! Constructor takes a \p Predicate object to negate. - * \param p The \p Predicate object to negate. - */ - __host__ __device__ - explicit binary_negate(Predicate p) : pred(p){} - - /*! Function call operator. The return value is !pred(x,y). - */ - __host__ __device__ - bool operator()(const typename Predicate::first_argument_type& x, const typename Predicate::second_argument_type& y) - { - return !pred(x,y); - } - - /*! \cond */ - Predicate pred; - /*! \endcond */ -}; // end binary_negate - -/*! \p not2 is a helper function to simplify the creation of Adaptable Binary Predicates: - * it takes an Adaptable Binary Predicate \p pred as an argument and returns a new Adaptable - * Binary Predicate that represents the negation of \p pred. That is: if \c pred is an object - * of a type which models Adaptable Binary Predicate, then the the type of the result - * \c npred of not2(pred) is also a model of Adaptable Binary Predicate and - * npred(x,y) always returns the same value as !pred(x,y). - * - * \param pred The Adaptable Binary Predicate to negate. - * \return A new object, npred such that npred(x,y) always returns - * the same value as !pred(x,y). - * - * \tparam Binary Predicate is a model of Adaptable Binary Predicate. - * - * \see binary_negate - * \see not1 - */ -template - __host__ __device__ - binary_negate not2(const BinaryPredicate &pred); - -/*! \} - */ - - -/*! \addtogroup placeholder_objects Placeholder Objects - * \ingroup function_objects - * \{ - */ - - -/*! \namespace placeholders - * \brief Facilities for constructing simple functions inline. - * - * Objects in the \p thrust::placeholders namespace may be used to create simple arithmetic functions inline - * in an algorithm invocation. Combining placeholders such as \p _1 and \p _2 with arithmetic operations such as \c + - * creates an unnamed function object which applies the operation to their arguments. - * - * The type of placeholder objects is implementation-defined. - * - * The following code snippet demonstrates how to use the placeholders \p _1 and \p _2 with \p thrust::transform - * to implement the SAXPY computation: - * - * \code - * #include - * #include - * #include - * - * int main() - * { - * thrust::device_vector x(4), y(4); - * x[0] = 1; - * x[1] = 2; - * x[2] = 3; - * x[3] = 4; - * - * y[0] = 1; - * y[1] = 1; - * y[2] = 1; - * y[3] = 1; - * - * float a = 2.0f; - * - * using namespace thrust::placeholders; - * - * thrust::transform(x.begin(), x.end(), y.begin(), y.begin(), - * a * _1 + 2 - * ); - * - * // y is now {3, 5, 7, 9} - * } - * \endcode - */ -namespace placeholders -{ - - -/*! \p thrust::placeholders::_1 is the placeholder for the first function parameter. - */ -static const thrust::detail::functional::placeholder<0>::type _1; - - -/*! \p thrust::placeholders::_2 is the placeholder for the second function parameter. - */ -static const thrust::detail::functional::placeholder<1>::type _2; - - -/*! \p thrust::placeholders::_3 is the placeholder for the third function parameter. - */ -static const thrust::detail::functional::placeholder<2>::type _3; - - -/*! \p thrust::placeholders::_4 is the placeholder for the fourth function parameter. - */ -static const thrust::detail::functional::placeholder<3>::type _4; - - -/*! \p thrust::placeholders::_5 is the placeholder for the fifth function parameter. - */ -static const thrust::detail::functional::placeholder<4>::type _5; - - -/*! \p thrust::placeholders::_6 is the placeholder for the sixth function parameter. - */ -static const thrust::detail::functional::placeholder<5>::type _6; - - -/*! \p thrust::placeholders::_7 is the placeholder for the seventh function parameter. - */ -static const thrust::detail::functional::placeholder<6>::type _7; - - -/*! \p thrust::placeholders::_8 is the placeholder for the eighth function parameter. - */ -static const thrust::detail::functional::placeholder<7>::type _8; - - -/*! \p thrust::placeholders::_9 is the placeholder for the ninth function parameter. - */ -static const thrust::detail::functional::placeholder<8>::type _9; - - -/*! \p thrust::placeholders::_10 is the placeholder for the tenth function parameter. - */ -static const thrust::detail::functional::placeholder<9>::type _10; - - -} // end placeholders - - -/*! \} // placeholder_objects - */ - - -} // end thrust - -#include -#include - diff --git a/compat/thrust/gather.h b/compat/thrust/gather.h deleted file mode 100644 index f2b8233..0000000 --- a/compat/thrust/gather.h +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file gather.h - * \brief Irregular copying from a source range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup gathering - * \ingroup copying - * \{ - */ - - -/*! \p gather copies elements from a source array into a destination range according - * to a map. For each input iterator \c i in the range [map_first, map_last), the - * value input_first[\*i] is assigned to *(result + (i - map_first)). - * \p RandomAccessIterator must permit random access. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param map_first Beginning of the range of gather locations. - * \param map_last End of the range of gather locations. - * \param input_first Beginning of the source range. - * \param result Beginning of the destination range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam RandomAccessIterator must be a model of Random Access Iterator and \c RandomAccessIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre The range [map_first, map_last) shall not overlap the range [result, result + (map_last - map_first)). - * - * \remark \p gather is the inverse of thrust::scatter. - * - * The following code snippet demonstrates how to use \p gather to reorder - * a range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * // mark even indices with a 1; odd indices with a 0 - * int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * thrust::device_vector d_values(values, values + 10); - * - * // gather all even indices into the first half of the range - * // and odd indices to the last half of the range - * int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10); - * thrust::gather(thrust::device, - * d_map.begin(), d_map.end(), - * d_values.begin(), - * d_output.begin()); - * // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * \endcode - */ -template - OutputIterator gather(const thrust::detail::execution_policy_base &exec, - InputIterator map_first, - InputIterator map_last, - RandomAccessIterator input_first, - OutputIterator result); - - -/*! \p gather copies elements from a source array into a destination range according - * to a map. For each input iterator \c i in the range [map_first, map_last), the - * value input_first[\*i] is assigned to *(result + (i - map_first)). - * \p RandomAccessIterator must permit random access. - * - * \param map_first Beginning of the range of gather locations. - * \param map_last End of the range of gather locations. - * \param input_first Beginning of the source range. - * \param result Beginning of the destination range. - * - * \tparam InputIterator must be a model of Input Iterator and \c InputIterator's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam RandomAccessIterator must be a model of Random Access Iterator and \c RandomAccessIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre The range [map_first, map_last) shall not overlap the range [result, result + (map_last - map_first)). - * - * \remark \p gather is the inverse of thrust::scatter. - * - * The following code snippet demonstrates how to use \p gather to reorder - * a range. - * - * \code - * #include - * #include - * ... - * // mark even indices with a 1; odd indices with a 0 - * int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * thrust::device_vector d_values(values, values + 10); - * - * // gather all even indices into the first half of the range - * // and odd indices to the last half of the range - * int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10); - * thrust::gather(d_map.begin(), d_map.end(), - * d_values.begin(), - * d_output.begin()); - * // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * \endcode - */ -template - OutputIterator gather(InputIterator map_first, - InputIterator map_last, - RandomAccessIterator input_first, - OutputIterator result); - - -/*! \p gather_if conditionally copies elements from a source array into a destination - * range according to a map. For each input iterator \c i in the range [map_first, map_last), - * such that the value of \*(stencil + (i - map_first)) is \c true, the value - * input_first[\*i] is assigned to *(result + (i - map_first)). - * \p RandomAccessIterator must permit random access. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param map_first Beginning of the range of gather locations. - * \param map_last End of the range of gather locations. - * \param stencil Beginning of the range of predicate values. - * \param input_first Beginning of the source range. - * \param result Beginning of the destination range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c bool. - * \tparam RandomAccessIterator must be a model of Random Access iterator and \c RandomAccessIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre The range [map_first, map_last) shall not overlap the range [result, result + (map_last - map_first)). - * \pre The range [stencil, stencil + (map_last - map_first)) shall not overlap the range [result, result + (map_last - map_first)). - * - * \remark \p gather_if is the inverse of \p scatter_if. - * - * The following code snippet demonstrates how to use \p gather_if to gather selected values from - * an input range using the \p thrust::device execution policy: - * - * \code - * #include - * #include - * #include - * ... - * - * int values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - * thrust::device_vector d_values(values, values + 10); - * - * // select elements at even-indexed locations - * int stencil[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * thrust::device_vector d_stencil(stencil, stencil + 10); - * - * // map all even indices into the first half of the range - * // and odd indices to the last half of the range - * int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10, 7); - * thrust::gather_if(thrust::device, - * d_map.begin(), d_map.end(), - * d_stencil.begin(), - * d_values.begin(), - * d_output.begin()); - * // d_output is now {0, 7, 4, 7, 8, 7, 3, 7, 7, 7} - * \endcode - */ -template - OutputIterator gather_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result); - - -/*! \p gather_if conditionally copies elements from a source array into a destination - * range according to a map. For each input iterator \c i in the range [map_first, map_last), - * such that the value of \*(stencil + (i - map_first)) is \c true, the value - * input_first[\*i] is assigned to *(result + (i - map_first)). - * \p RandomAccessIterator must permit random access. - * - * \param map_first Beginning of the range of gather locations. - * \param map_last End of the range of gather locations. - * \param stencil Beginning of the range of predicate values. - * \param input_first Beginning of the source range. - * \param result Beginning of the destination range. - * - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c bool. - * \tparam RandomAccessIterator must be a model of Random Access iterator and \c RandomAccessIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * - * \pre The range [map_first, map_last) shall not overlap the range [result, result + (map_last - map_first)). - * \pre The range [stencil, stencil + (map_last - map_first)) shall not overlap the range [result, result + (map_last - map_first)). - * - * \remark \p gather_if is the inverse of \p scatter_if. - * - * The following code snippet demonstrates how to use \p gather_if to gather selected values from - * an input range. - * - * \code - * #include - * #include - * ... - * - * int values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - * thrust::device_vector d_values(values, values + 10); - * - * // select elements at even-indexed locations - * int stencil[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * thrust::device_vector d_stencil(stencil, stencil + 10); - * - * // map all even indices into the first half of the range - * // and odd indices to the last half of the range - * int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10, 7); - * thrust::gather_if(d_map.begin(), d_map.end(), - * d_stencil.begin(), - * d_values.begin(), - * d_output.begin()); - * // d_output is now {0, 7, 4, 7, 8, 7, 3, 7, 7, 7} - * \endcode - */ -template - OutputIterator gather_if(InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result); - - -/*! \p gather_if conditionally copies elements from a source array into a destination - * range according to a map. For each input iterator \c i in the range [map_first, map_last) - * such that the value of pred(\*(stencil + (i - map_first))) is \c true, - * the value input_first[\*i] is assigned to *(result + (i - map_first)). - * \p RandomAccessIterator must permit random access. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param map_first Beginning of the range of gather locations. - * \param map_last End of the range of gather locations. - * \param stencil Beginning of the range of predicate values. - * \param input_first Beginning of the source range. - * \param result Beginning of the destination range. - * \param pred Predicate to apply to the stencil values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c Predicate's \c argument_type. - * \tparam RandomAccessIterator must be a model of Random Access iterator and \c RandomAccessIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * \tparam Predicate must be a model of Predicate. - * - * \pre The range [map_first, map_last) shall not overlap the range [result, result + (map_last - map_first)). - * \pre The range [stencil, stencil + (map_last - map_first)) shall not overlap the range [result, result + (map_last - map_first)). - * - * \remark \p gather_if is the inverse of \p scatter_if. - * - * The following code snippet demonstrates how to use \p gather_if to gather selected values from - * an input range based on an arbitrary selection function using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * - * int values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - * thrust::device_vector d_values(values, values + 10); - * - * // we will select an element when our stencil is even - * int stencil[10] = {0, 3, 4, 1, 4, 1, 2, 7, 8, 9}; - * thrust::device_vector d_stencil(stencil, stencil + 10); - * - * // map all even indices into the first half of the range - * // and odd indices to the last half of the range - * int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10, 7); - * thrust::gather_if(thrust::device, - * d_map.begin(), d_map.end(), - * d_stencil.begin(), - * d_values.begin(), - * d_output.begin(), - * is_even()); - * // d_output is now {0, 7, 4, 7, 8, 7, 3, 7, 7, 7} - * \endcode - */ -template - OutputIterator gather_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result, - Predicate pred); - - -/*! \p gather_if conditionally copies elements from a source array into a destination - * range according to a map. For each input iterator \c i in the range [map_first, map_last) - * such that the value of pred(\*(stencil + (i - map_first))) is \c true, - * the value input_first[\*i] is assigned to *(result + (i - map_first)). - * \p RandomAccessIterator must permit random access. - * - * \param map_first Beginning of the range of gather locations. - * \param map_last End of the range of gather locations. - * \param stencil Beginning of the range of predicate values. - * \param input_first Beginning of the source range. - * \param result Beginning of the destination range. - * \param pred Predicate to apply to the stencil values. - * - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c Predicate's \c argument_type. - * \tparam RandomAccessIterator must be a model of Random Access iterator and \c RandomAccessIterator's \c value_type must be convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator must be a model of Output Iterator. - * \tparam Predicate must be a model of Predicate. - * - * \pre The range [map_first, map_last) shall not overlap the range [result, result + (map_last - map_first)). - * \pre The range [stencil, stencil + (map_last - map_first)) shall not overlap the range [result, result + (map_last - map_first)). - * - * \remark \p gather_if is the inverse of \p scatter_if. - * - * The following code snippet demonstrates how to use \p gather_if to gather selected values from - * an input range based on an arbitrary selection function. - * - * \code - * #include - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * - * int values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - * thrust::device_vector d_values(values, values + 10); - * - * // we will select an element when our stencil is even - * int stencil[10] = {0, 3, 4, 1, 4, 1, 2, 7, 8, 9}; - * thrust::device_vector d_stencil(stencil, stencil + 10); - * - * // map all even indices into the first half of the range - * // and odd indices to the last half of the range - * int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10, 7); - * thrust::gather_if(d_map.begin(), d_map.end(), - * d_stencil.begin(), - * d_values.begin(), - * d_output.begin(), - * is_even()); - * // d_output is now {0, 7, 4, 7, 8, 7, 3, 7, 7, 7} - * \endcode - */ -template - OutputIterator gather_if(InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result, - Predicate pred); - -/*! \} // gathering - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/generate.h b/compat/thrust/generate.h deleted file mode 100644 index 1d52721..0000000 --- a/compat/thrust/generate.h +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file generate.h - * \brief Fills a range with values "generated" from a function of no arguments - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup transformations - * \{ - */ - - -/*! \p generate assigns the result of invoking \p gen, a function object that takes no arguments, - * to each element in the range [first,last). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element in the range of interest. - * \param last The last element in the range of interest. - * \param gen A function argument, taking no parameters, used to generate values to assign to - * elements in the range [first,last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam Generator is a model of Generator, - * and \p Generator's \c result_type is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to fill a \c host_vector with random numbers, - * using the standard C library function \c rand using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::host_vector v(10); - * srand(13); - * thrust::generate(thrust::host, v.begin(), v.end(), rand); - * - * // the elements of v are now pseudo-random numbers - * \endcode - * - * \see generate_n - * \see http://www.sgi.com/tech/stl/generate.html - */ -template - void generate(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Generator gen); - - -/*! \p generate assigns the result of invoking \p gen, a function object that takes no arguments, - * to each element in the range [first,last). - * - * \param first The first element in the range of interest. - * \param last The last element in the range of interest. - * \param gen A function argument, taking no parameters, used to generate values to assign to - * elements in the range [first,last). - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam Generator is a model of Generator, - * and \p Generator's \c result_type is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to fill a \c host_vector with random numbers, - * using the standard C library function \c rand. - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::host_vector v(10); - * srand(13); - * thrust::generate(v.begin(), v.end(), rand); - * - * // the elements of v are now pseudo-random numbers - * \endcode - * - * \see generate_n - * \see http://www.sgi.com/tech/stl/generate.html - */ -template - void generate(ForwardIterator first, - ForwardIterator last, - Generator gen); - - -/*! \p generate_n assigns the result of invoking \p gen, a function object that takes no arguments, - * to each element in the range [first,first + n). The return value is first + n. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element in the range of interest. - * \param n The size of the range of interest. - * \param gen A function argument, taking no parameters, used to generate values to assign to - * elements in the range [first,first + n). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Size is an integral type (either signed or unsigned). - * \tparam Generator is a model of Generator, - * and \p Generator's \c result_type is convertible to a type in \p OutputIterator's set of \c value_types. - * - * The following code snippet demonstrates how to fill a \c host_vector with random numbers, - * using the standard C library function \c rand using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::host_vector v(10); - * srand(13); - * thrust::generate_n(thrust::host, v.begin(), 10, rand); - * - * // the elements of v are now pseudo-random numbers - * \endcode - * - * \see generate - * \see http://www.sgi.com/tech/stl/generate.html - */ -template - OutputIterator generate_n(const thrust::detail::execution_policy_base &exec, - OutputIterator first, - Size n, - Generator gen); - - -/*! \p generate_n assigns the result of invoking \p gen, a function object that takes no arguments, - * to each element in the range [first,first + n). The return value is first + n. - * - * \param first The first element in the range of interest. - * \param n The size of the range of interest. - * \param gen A function argument, taking no parameters, used to generate values to assign to - * elements in the range [first,first + n). - * - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Size is an integral type (either signed or unsigned). - * \tparam Generator is a model of Generator, - * and \p Generator's \c result_type is convertible to a type in \p OutputIterator's set of \c value_types. - * - * The following code snippet demonstrates how to fill a \c host_vector with random numbers, - * using the standard C library function \c rand. - * - * \code - * #include - * #include - * #include - * ... - * thrust::host_vector v(10); - * srand(13); - * thrust::generate_n(v.begin(), 10, rand); - * - * // the elements of v are now pseudo-random numbers - * \endcode - * - * \see generate - * \see http://www.sgi.com/tech/stl/generate.html - */ -template - OutputIterator generate_n(OutputIterator first, - Size n, - Generator gen); - - -/*! \} // end transformations - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/host_vector.h b/compat/thrust/host_vector.h deleted file mode 100644 index 11b1ae0..0000000 --- a/compat/thrust/host_vector.h +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file host_vector.h - * \brief A dynamically-sizable array of elements which reside in the "host" memory space - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -// forward declaration of device_vector -template class device_vector; - -/*! \addtogroup container_classes Container Classes - * \addtogroup host_containers Host Containers - * \ingroup container_classes - * \{ - */ - -/*! A \p host_vector is a container that supports random access to elements, - * constant time removal of elements at the end, and linear time insertion - * and removal of elements at the beginning or in the middle. The number of - * elements in a \p host_vector may vary dynamically; memory management is - * automatic. The memory associated with a \p host_vector resides in the memory - * space of the host associated with a parallel device. - * - * \see http://www.sgi.com/tech/stl/Vector.html - * \see device_vector - */ -template > - class host_vector - : public detail::vector_base -{ - private: - typedef detail::vector_base Parent; - - public: - /*! \cond */ - typedef typename Parent::size_type size_type; - typedef typename Parent::value_type value_type; - /*! \endcond */ - - /*! This constructor creates an empty \p host_vector. - */ - __host__ - host_vector(void) - :Parent() {} - - /*! This constructor creates a \p host_vector with the given - * size. - * \param n The number of elements to initially craete. - */ - __host__ - explicit host_vector(size_type n) - :Parent(n) {} - - /*! This constructor creates a \p host_vector with copies - * of an exemplar element. - * \param n The number of elements to initially create. - * \param value An element to copy. - */ - __host__ - explicit host_vector(size_type n, const value_type &value) - :Parent(n,value) {} - - /*! Copy constructor copies from an exemplar \p host_vector. - * \param v The \p host_vector to copy. - */ - __host__ - host_vector(const host_vector &v) - :Parent(v) {} - - /*! Assign operator copies from an exemplar \p host_vector. - * \param v The \p host_vector to copy. - */ - __host__ - host_vector &operator=(const host_vector &v) - { Parent::operator=(v); return *this; } - - /*! Copy constructor copies from an exemplar \p host_vector with different type. - * \param v The \p host_vector to copy. - */ - template - __host__ - host_vector(const host_vector &v) - :Parent(v) {} - - /*! Assign operator copies from an exemplar \p host_vector with different type. - * \param v The \p host_vector to copy. - */ - template - __host__ - host_vector &operator=(const host_vector &v) - { Parent::operator=(v); return *this; } - - /*! Copy constructor copies from an exemplar std::vector. - * \param v The std::vector to copy. - */ - template - __host__ - host_vector(const std::vector &v) - :Parent(v) {} - - /*! Assign operator copies from an exemplar std::vector. - * \param v The std::vector to copy. - */ - template - __host__ - host_vector &operator=(const std::vector &v) - { Parent::operator=(v); return *this;} - - /*! Copy constructor copies from an exemplar \p device_vector with possibly different type. - * \param v The \p device_vector to copy. - */ - template - __host__ - host_vector(const device_vector &v); - - /*! Assign operator copies from an exemplar \p device_vector. - * \param v The \p device_vector to copy. - */ - template - __host__ - host_vector &operator=(const device_vector &v) - { Parent::operator=(v); return *this; } - - /*! This constructor builds a \p host_vector from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - __host__ - host_vector(InputIterator first, InputIterator last) - :Parent(first, last) {} - -// declare these members for the purpose of Doxygenating them -// they actually exist in a derived-from class -#if 0 - /*! \brief Resizes this vector to the specified number of elements. - * \param new_size Number of elements this vector should contain. - * \param x Data with which new elements should be populated. - * \throw std::length_error If n exceeds max_size(). - * - * This method will resize this vector to the specified number of - * elements. If the number is smaller than this vector's current - * size this vector is truncated, otherwise this vector is - * extended and new elements are populated with given data. - */ - void resize(size_type new_size, const value_type &x = value_type()); - - /*! Returns the number of elements in this vector. - */ - size_type size(void) const; - - /*! Returns the size() of the largest possible vector. - * \return The largest possible return value of size(). - */ - size_type max_size(void) const; - - /*! \brief If n is less than or equal to capacity(), this call has no effect. - * Otherwise, this method is a request for allocation of additional memory. If - * the request is successful, then capacity() is greater than or equal to - * n; otherwise, capacity() is unchanged. In either case, size() is unchanged. - * \throw std::length_error If n exceeds max_size(). - */ - void reserve(size_type n); - - /*! Returns the number of elements which have been reserved in this - * vector. - */ - size_type capacity(void) const; - - /*! This method shrinks the capacity of this vector to exactly - * fit its elements. - */ - void shrink_to_fit(void); - - /*! \brief Subscript access to the data contained in this vector_dev. - * \param n The index of the element for which data should be accessed. - * \return Read/write reference to data. - * - * This operator allows for easy, array-style, data access. - * Note that data access with this operator is unchecked and - * out_of_range lookups are not defined. - */ - reference operator[](size_type n); - - /*! \brief Subscript read access to the data contained in this vector_dev. - * \param n The index of the element for which data should be accessed. - * \return Read reference to data. - * - * This operator allows for easy, array-style, data access. - * Note that data access with this operator is unchecked and - * out_of_range lookups are not defined. - */ - const_reference operator[](size_type n) const; - - /*! This method returns an iterator pointing to the beginning of - * this vector. - * \return mStart - */ - iterator begin(void); - - /*! This method returns a const_iterator pointing to the beginning - * of this vector. - * \return mStart - */ - const_iterator begin(void) const; - - /*! This method returns a const_iterator pointing to the beginning - * of this vector. - * \return mStart - */ - const_iterator cbegin(void) const; - - /*! This method returns a reverse_iterator pointing to the beginning of - * this vector's reversed sequence. - * \return A reverse_iterator pointing to the beginning of this - * vector's reversed sequence. - */ - reverse_iterator rbegin(void); - - /*! This method returns a const_reverse_iterator pointing to the beginning of - * this vector's reversed sequence. - * \return A const_reverse_iterator pointing to the beginning of this - * vector's reversed sequence. - */ - const_reverse_iterator rbegin(void) const; - - /*! This method returns a const_reverse_iterator pointing to the beginning of - * this vector's reversed sequence. - * \return A const_reverse_iterator pointing to the beginning of this - * vector's reversed sequence. - */ - const_reverse_iterator crbegin(void) const; - - /*! This method returns an iterator pointing to one element past the - * last of this vector. - * \return begin() + size(). - */ - iterator end(void); - - /*! This method returns a const_iterator pointing to one element past the - * last of this vector. - * \return begin() + size(). - */ - const_iterator end(void) const; - - /*! This method returns a const_iterator pointing to one element past the - * last of this vector. - * \return begin() + size(). - */ - const_iterator cend(void) const; - - /*! This method returns a reverse_iterator pointing to one element past the - * last of this vector's reversed sequence. - * \return rbegin() + size(). - */ - reverse_iterator rend(void); - - /*! This method returns a const_reverse_iterator pointing to one element past the - * last of this vector's reversed sequence. - * \return rbegin() + size(). - */ - const_reverse_iterator rend(void) const; - - /*! This method returns a const_reverse_iterator pointing to one element past the - * last of this vector's reversed sequence. - * \return rbegin() + size(). - */ - const_reverse_iterator crend(void) const; - - /*! This method returns a const_reference referring to the first element of this - * vector. - * \return The first element of this vector. - */ - const_reference front(void) const; - - /*! This method returns a reference pointing to the first element of this - * vector. - * \return The first element of this vector. - */ - reference front(void); - - /*! This method returns a const reference pointing to the last element of - * this vector. - * \return The last element of this vector. - */ - const_reference back(void) const; - - /*! This method returns a reference referring to the last element of - * this vector_dev. - * \return The last element of this vector. - */ - reference back(void); - - /*! This method returns a pointer to this vector's first element. - * \return A pointer to the first element of this vector. - */ - pointer data(void); - - /*! This method returns a const_pointer to this vector's first element. - * \return a const_pointer to the first element of this vector. - */ - const_pointer data(void) const; - - /*! This method resizes this vector to 0. - */ - void clear(void); - - /*! This method returns true iff size() == 0. - * \return true if size() == 0; false, otherwise. - */ - bool empty(void) const; - - /*! This method appends the given element to the end of this vector. - * \param x The element to append. - */ - void push_back(const value_type &x); - - /*! This method erases the last element of this vector, invalidating - * all iterators and references to it. - */ - void pop_back(void); - - /*! This method swaps the contents of this vector_base with another vector. - * \param v The vector with which to swap. - */ - void swap(host_vector &v); - - /*! This method removes the element at position pos. - * \param pos The position of the element of interest. - * \return An iterator pointing to the new location of the element that followed the element - * at position pos. - */ - iterator erase(iterator pos); - - /*! This method removes the range of elements [first,last) from this vector. - * \param first The beginning of the range of elements to remove. - * \param last The end of the range of elements to remove. - * \return An iterator pointing to the new location of the element that followed the last - * element in the sequence [first,last). - */ - iterator erase(iterator first, iterator last); - - /*! This method inserts a single copy of a given exemplar value at the - * specified position in this vector. - * \param position The insertion position. - * \param x The exemplar element to copy & insert. - * \return An iterator pointing to the newly inserted element. - */ - iterator insert(iterator position, const T &x); - - /*! This method inserts a copy of an exemplar value to a range at the - * specified position in this vector. - * \param position The insertion position - * \param n The number of insertions to perform. - * \param x The value to replicate and insert. - */ - void insert(iterator position, size_type n, const T &x); - - /*! This method inserts a copy of an input range at the specified position - * in this vector. - * \param position The insertion position. - * \param first The beginning of the range to copy. - * \param last The end of the range to copy. - * - * \tparam InputIterator is a model of Assignable. - */ - template - void insert(iterator position, InputIterator first, InputIterator last); - - /*! This version of \p assign replicates a given exemplar - * \p n times into this vector. - * \param n The number of times to copy \p x. - * \param x The exemplar element to replicate. - */ - void assign(size_type n, const T &x); - - /*! This version of \p assign makes this vector a copy of a given input range. - * \param first The beginning of the range to copy. - * \param last The end of the range to copy. - * - * \tparam InputIterator is a model of Input Iterator. - */ - template - void assign(InputIterator first, InputIterator last); - - /*! This method returns a copy of this vector's allocator. - * \return A copy of the alloctor used by this vector. - */ - allocator_type get_allocator(void) const; -#endif // end doxygen-only members -}; // end host_vector - -/*! \} - */ - -} // end thrust - -#include - diff --git a/compat/thrust/inner_product.h b/compat/thrust/inner_product.h deleted file mode 100644 index 01f5541..0000000 --- a/compat/thrust/inner_product.h +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file inner_product.h - * \brief Mathematical inner product between ranges - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reductions - * \{ - * \addtogroup transformed_reductions Transformed Reductions - * \ingroup reductions - * \{ - */ - - -/*! \p inner_product calculates an inner product of the ranges - * [first1, last1) and [first2, first2 + (last1 - first1)). - * - * Specifically, this version of \p inner_product computes the sum - * init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ... - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param init Initial value of the result. - * \return The inner product of sequences [first1, last1) - * and [first2, last2) plus \p init. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputType is a model of Assignable, - * and if \c x is an object of type \p OutputType, and \c y is an object of \p InputIterator1's \c value_type, - * and \c z is an object of \p InputIterator2's \c value_type, then x + y * z is defined - * and is convertible to \p OutputType. - * - * The following code demonstrates how to use \p inner_product to - * compute the dot product of two vectors using the \p thrust::host execution policy for parallelization. - * - * \code - * #include - * #include - * ... - * float vec1[3] = {1.0f, 2.0f, 5.0f}; - * float vec2[3] = {4.0f, 1.0f, 5.0f}; - * - * float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, 0.0f); - * - * // result == 31.0f - * \endcode - * - * \see http://www.sgi.com/tech/stl/inner_product.html - */ -template -OutputType inner_product(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init); - - -/*! \p inner_product calculates an inner product of the ranges - * [first1, last1) and [first2, first2 + (last1 - first1)). - * - * Specifically, this version of \p inner_product computes the sum - * init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ... - * - * Unlike the C++ Standard Template Library function std::inner_product, - * this version offers no guarantee on order of execution. - * - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param init Initial value of the result. - * \return The inner product of sequences [first1, last1) - * and [first2, last2) plus \p init. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputType is a model of Assignable, - * and if \c x is an object of type \p OutputType, and \c y is an object of \p InputIterator1's \c value_type, - * and \c z is an object of \p InputIterator2's \c value_type, then x + y * z is defined - * and is convertible to \p OutputType. - * - * The following code demonstrates how to use \p inner_product to - * compute the dot product of two vectors. - * - * \code - * #include - * ... - * float vec1[3] = {1.0f, 2.0f, 5.0f}; - * float vec2[3] = {4.0f, 1.0f, 5.0f}; - * - * float result = thrust::inner_product(vec1, vec1 + 3, vec2, 0.0f); - * - * // result == 31.0f - * \endcode - * - * \see http://www.sgi.com/tech/stl/inner_product.html - */ -template -OutputType inner_product(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, OutputType init); - - -/*! \p inner_product calculates an inner product of the ranges - * [first1, last1) and [first2, first2 + (last1 - first1)). - * - * This version of \p inner_product is identical to the first, except that is uses - * two user-supplied function objects instead of \c operator+ and \c operator*. - * - * Specifically, this version of \p inner_product computes the sum - * binary_op1( init, binary_op2(*first1, *first2) ), ... - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param init Initial value of the result. - * \param binary_op1 Generalized addition operation. - * \param binary_op2 Generalized multiplication operation. - * \return The inner product of sequences [first1, last1) and [first2, last2). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator1's \c value_type is convertible to \p BinaryFunction2's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator. - * and \p InputIterator2's \c value_type is convertible to \p BinaryFunction2's \c second_argument_type. - * \tparam OutputType is a model of Assignable, - * and \p OutputType is convertible to \p BinaryFunction1's \c first_argument_type. - * \tparam BinaryFunction1 is a model of Binary Function, - * and \p BinaryFunction1's \c return_type is convertible to \p OutputType. - * \tparam BinaryFunction2 is a model of Binary Function, - * and \p BinaryFunction2's \c return_type is convertible to \p BinaryFunction1's \c second_argument_type. - * - * \code - * #include - * #include - * ... - * float vec1[3] = {1.0f, 2.0f, 5.0f}; - * float vec2[3] = {4.0f, 1.0f, 5.0f}; - * - * float init = 0.0f; - * thrust::plus binary_op1; - * thrust::multiplies binary_op2; - * - * float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, init, binary_op1, binary_op2); - * - * // result == 31.0f - * \endcode - * - * \see http://www.sgi.com/tech/stl/inner_product.html - */ -template -OutputType inner_product(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init, - BinaryFunction1 binary_op1, - BinaryFunction2 binary_op2); - - -/*! \p inner_product calculates an inner product of the ranges - * [first1, last1) and [first2, first2 + (last1 - first1)). - * - * This version of \p inner_product is identical to the first, except that is uses - * two user-supplied function objects instead of \c operator+ and \c operator*. - * - * Specifically, this version of \p inner_product computes the sum - * binary_op1( init, binary_op2(*first1, *first2) ), ... - * - * Unlike the C++ Standard Template Library function std::inner_product, - * this version offers no guarantee on order of execution. - * - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param init Initial value of the result. - * \param binary_op1 Generalized addition operation. - * \param binary_op2 Generalized multiplication operation. - * \return The inner product of sequences [first1, last1) and [first2, last2). - * - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator1's \c value_type is convertible to \p BinaryFunction2's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator. - * and \p InputIterator2's \c value_type is convertible to \p BinaryFunction2's \c second_argument_type. - * \tparam OutputType is a model of Assignable, - * and \p OutputType is convertible to \p BinaryFunction1's \c first_argument_type. - * \tparam BinaryFunction1 is a model of Binary Function, - * and \p BinaryFunction1's \c return_type is convertible to \p OutputType. - * \tparam BinaryFunction2 is a model of Binary Function, - * and \p BinaryFunction2's \c return_type is convertible to \p BinaryFunction1's \c second_argument_type. - * - * \code - * #include - * ... - * float vec1[3] = {1.0f, 2.0f, 5.0f}; - * float vec2[3] = {4.0f, 1.0f, 5.0f}; - * - * float init = 0.0f; - * thrust::plus binary_op1; - * thrust::multiplies binary_op2; - * - * float result = thrust::inner_product(vec1, vec1 + 3, vec2, init, binary_op1, binary_op2); - * - * // result == 31.0f - * \endcode - * - * \see http://www.sgi.com/tech/stl/inner_product.html - */ -template -OutputType inner_product(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, OutputType init, - BinaryFunction1 binary_op1, BinaryFunction2 binary_op2); - - -/*! \} // end transformed_reductions - * \} // end reductions - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/iterator/constant_iterator.h b/compat/thrust/iterator/constant_iterator.h deleted file mode 100644 index e9e03c1..0000000 --- a/compat/thrust/iterator/constant_iterator.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/constant_iterator.h - * \brief An iterator which returns a constant value when - * dereferenced - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p constant_iterator is an iterator which represents a pointer into a range - * of constant values. This iterator is useful for creating a range filled with the same - * value without explicitly storing it in memory. Using \p constant_iterator saves both - * memory capacity and bandwidth. - * - * The following code snippet demonstrates how to create a \p constant_iterator whose - * \c value_type is \c int and whose value is \c 10. - * - * \code - * #include - * - * thrust::constant_iterator iter(10); - * - * *iter; // returns 10 - * iter[0]; // returns 10 - * iter[1]; // returns 10 - * iter[13]; // returns 10 - * - * // and so on... - * \endcode - * - * This next example demonstrates how to use a \p constant_iterator with the - * \p thrust::transform function to increment all elements of a sequence by the - * same value. We will create a temporary \p constant_iterator with the function - * \p make_constant_iterator function in order to avoid explicitly specifying - * its type: - * - * \code - * #include - * #include - * #include - * #include - * - * int main(void) - * { - * thrust::device_vector data(4); - * data[0] = 3; - * data[1] = 7; - * data[2] = 2; - * data[3] = 5; - * - * // add 10 to all values in data - * thrust::transform(data.begin(), data.end(), - * thrust::make_constant_iterator(10), - * data.begin(), - * thrust::plus()); - * - * // data is now [13, 17, 12, 15] - * - * return 0; - * } - * \endcode - * - * \see make_constant_iterator - */ -template - class constant_iterator - : public detail::constant_iterator_base::type -{ - /*! \cond - */ - friend class thrust::iterator_core_access; - typedef typename detail::constant_iterator_base::type super_t; - typedef typename detail::constant_iterator_base::incrementable incrementable; - typedef typename detail::constant_iterator_base::base_iterator base_iterator; - - public: - typedef typename super_t::reference reference; - typedef typename super_t::value_type value_type; - - /*! \endcond - */ - - /*! Null constructor initializes this \p constant_iterator's constant using its - * null constructor. - */ - __host__ __device__ - constant_iterator(void) - : super_t(), m_value(){}; - - /*! Copy constructor copies the value of another \p constant_iterator into this - * \p constant_iterator. - * - * \p rhs The constant_iterator to copy. - */ - __host__ __device__ - constant_iterator(constant_iterator const &rhs) - : super_t(rhs.base()), m_value(rhs.m_value) {} - - /*! Copy constructor copies the value of another \p constant_iterator with related - * System type. - * - * \param rhs The \p constant_iterator to copy. - */ - template - __host__ __device__ - constant_iterator(constant_iterator const &rhs, - typename thrust::detail::enable_if_convertible< - typename thrust::iterator_system >::type, - typename thrust::iterator_system::type - >::type * = 0) - : super_t(rhs.base()), m_value(rhs.value()) {} - - /*! This constructor receives a value to use as the constant value of this - * \p constant_iterator and an index specifying the location of this - * \p constant_iterator in a sequence. - * - * \p v The value of this \p constant_iterator's constant value. - * \p i The index of this \p constant_iterator in a sequence. Defaults to the - * value returned by \c Incrementable's null constructor. For example, - * when Incrementable == int, \c 0. - */ - __host__ __device__ - constant_iterator(value_type const& v, incrementable const &i = incrementable()) - : super_t(base_iterator(i)), m_value(v) {} - - /*! This constructor is templated to allow construction from a value type and - * incrementable type related this this \p constant_iterator's respective types. - * - * \p v The value of this \p constant_iterator's constant value. - * \p i The index of this \p constant_iterator in a sequence. Defaults to the - * value returned by \c Incrementable's null constructor. For example, - * when Incrementable == int, \c 0. - */ - template - __host__ __device__ - constant_iterator(OtherValue const& v, OtherIncrementable const& i = incrementable()) - : super_t(base_iterator(i)), m_value(v) {} - - /*! This method returns the value of this \p constant_iterator's constant value. - * \return A \c const reference to this \p constant_iterator's constant value. - */ - __host__ __device__ - Value const& value(void) const - { return m_value; } - - /*! \cond - */ - - protected: - __host__ __device__ - Value const& value_reference(void) const - { return m_value; } - - __host__ __device__ - Value & value_reference(void) - { return m_value; } - - private: // Core iterator interface - __host__ __device__ - reference dereference(void) const - { - return m_value; - } - - private: - Value m_value; - - /*! \endcond - */ -}; // end constant_iterator - - -/*! This version of \p make_constant_iterator creates a \p constant_iterator - * from values given for both value and index. The type of \p constant_iterator - * may be inferred by the compiler from the types of its parameters. - * - * \param x The value of the returned \p constant_iterator's constant value. - * \param i The index of the returned \p constant_iterator within a sequence. - * The type of this parameter defaults to \c int. In the default case, - * the value of this parameter is \c 0. - * - * \return A new \p constant_iterator with constant value & index as given - * by \p x & \p i. - * - * \see constant_iterator - */ -template -inline __host__ __device__ -constant_iterator make_constant_iterator(V x, I i = int()) -{ - return constant_iterator(x, i); -} // end make_constant_iterator() - - -/*! This version of \p make_constant_iterator creates a \p constant_iterator - * using only a parameter for the desired constant value. The value of the - * returned \p constant_iterator's index is set to \c 0. - * - * \param x The value of the returned \p constant_iterator's constant value. - * \return A new \p constant_iterator with constant value equal to \p x and - * index equal to \c 0. - * \see constant_iterator - */ -template -inline __host__ __device__ -constant_iterator make_constant_iterator(V x) -{ - return constant_iterator(x, 0); -} // end make_constant_iterator() - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end namespace thrust - diff --git a/compat/thrust/iterator/counting_iterator.h b/compat/thrust/iterator/counting_iterator.h deleted file mode 100644 index 99812ca..0000000 --- a/compat/thrust/iterator/counting_iterator.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/counting_iterator.h - * \brief An iterator which returns an increasing incrementable value - * when dereferenced - */ - -/* - * Copyright David Abrahams 2003. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include -#include - -// #include the details first -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p counting_iterator is an iterator which represents a pointer into a range - * of sequentially changing values. This iterator is useful for creating a range - * filled with a sequence without explicitly storing it in memory. Using - * \p counting_iterator saves memory capacity and bandwidth. - * - * The following code snippet demonstrates how to create a \p counting_iterator whose - * \c value_type is \c int and which sequentially increments by \c 1. - * - * \code - * #include - * ... - * // create iterators - * thrust::counting_iterator first(10); - * thrust::counting_iterator last = first + 3; - * - * first[0] // returns 10 - * first[1] // returns 11 - * first[100] // returns 110 - * - * // sum of [first, last) - * thrust::reduce(first, last); // returns 33 (i.e. 10 + 11 + 12) - * - * // initialize vector to [0,1,2,..] - * thrust::counting_iterator iter(0); - * thrust::device_vector vec(500); - * thrust::copy(iter, iter + vec.size(), vec.begin()); - * \endcode - * - * This next example demonstrates how to use a \p counting_iterator with the - * \p thrust::copy_if function to compute the indices of the non-zero elements - * of a \p device_vector. In this example, we use the \p make_counting_iterator - * function to avoid specifying the type of the \p counting_iterator. - * - * \code - * #include - * #include - * #include - * #include - * - * int main(void) - * { - * // this example computes indices for all the nonzero values in a sequence - * - * // sequence of zero and nonzero values - * thrust::device_vector stencil(8); - * stencil[0] = 0; - * stencil[1] = 1; - * stencil[2] = 1; - * stencil[3] = 0; - * stencil[4] = 0; - * stencil[5] = 1; - * stencil[6] = 0; - * stencil[7] = 1; - * - * // storage for the nonzero indices - * thrust::device_vector indices(8); - * - * // compute indices of nonzero elements - * typedef thrust::device_vector::iterator IndexIterator; - * - * // use make_counting_iterator to define the sequence [0, 8) - * IndexIterator indices_end = thrust::copy_if(thrust::make_counting_iterator(0), - * thrust::make_counting_iterator(8), - * stencil.begin(), - * indices.begin(), - * thrust::identity()); - * // indices now contains [1,2,5,7] - * - * return 0; - * } - * \endcode - * - * \see make_counting_iterator - */ -template - class counting_iterator - : public detail::counting_iterator_base::type -{ - /*! \cond - */ - typedef typename detail::counting_iterator_base::type super_t; - - friend class thrust::iterator_core_access; - - public: - typedef typename super_t::reference reference; - typedef typename super_t::difference_type difference_type; - - /*! \endcond - */ - - /*! Null constructor initializes this \p counting_iterator's \c Incrementable - * counter using its null constructor. - */ - __host__ __device__ - counting_iterator(void){}; - - /*! Copy constructor copies the value of another \p counting_iterator into a - * new \p counting_iterator. - * - * \p rhs The \p counting_iterator to copy. - */ - __host__ __device__ - counting_iterator(counting_iterator const &rhs):super_t(rhs.base()){} - - /*! Copy constructor copies the value of another counting_iterator - * with related System type. - * - * \param rhs The \p counting_iterator to copy. - */ - template - __host__ __device__ - counting_iterator(counting_iterator const &rhs, - typename thrust::detail::enable_if_convertible< - typename thrust::iterator_system >::type, - typename thrust::iterator_system::type - >::type * = 0) - : super_t(rhs.base()){} - - /*! This \c explicit constructor copies the value of an \c Incrementable - * into a new \p counting_iterator's \c Incrementable counter. - * - * \param x The initial value of the new \p counting_iterator's \c Incrementable - * counter. - */ - __host__ __device__ - explicit counting_iterator(Incrementable x):super_t(x){} - - /*! \cond - */ - private: - __host__ __device__ - reference dereference(void) const - { - return this->base_reference(); - } - - // note that we implement equal specially for floating point counting_iterator - template - __host__ __device__ - bool equal(counting_iterator const& y) const - { - typedef thrust::detail::counting_iterator_equal e; - return e::equal(this->base(), y.base()); - } - - template - __host__ __device__ - difference_type - distance_to(counting_iterator const& y) const - { - typedef typename - thrust::detail::eval_if< - thrust::detail::is_numeric::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - >::type d; - - return d::distance(this->base(), y.base()); - } - - /*! \endcond - */ -}; // end counting_iterator - - -/*! \p make_counting_iterator creates a \p counting_iterator - * using an initial value for its \c Incrementable counter. - * - * \param x The initial value of the new \p counting_iterator's counter. - * \return A new \p counting_iterator whose counter has been initialized to \p x. - */ -template -inline __host__ __device__ -counting_iterator make_counting_iterator(Incrementable x) -{ - return counting_iterator(x); -} - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - diff --git a/compat/thrust/iterator/detail/any_assign.h b/compat/thrust/iterator/detail/any_assign.h deleted file mode 100644 index e08a829..0000000 --- a/compat/thrust/iterator/detail/any_assign.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - - -// a type which may be assigned any other type -struct any_assign -{ - inline __host__ __device__ any_assign(void) - {} - - template - inline __host__ __device__ any_assign(T) - {} - - template - inline __host__ __device__ - any_assign &operator=(T) - { - if(0) - { - // trick the compiler into silencing "warning: this expression has no effect" - int *x = 0; - *x = 13; - } // end if - - return *this; - } -}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/any_system_tag.h b/compat/thrust/iterator/detail/any_system_tag.h deleted file mode 100644 index fc6417a..0000000 --- a/compat/thrust/iterator/detail/any_system_tag.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -struct any_system_tag - : thrust::execution_policy -{ - // allow any_system_tag to convert to any type at all - // XXX make this safer using enable_if> upon c++11 - template operator T () const {return T();} -}; - -// TODO remove this in 1.7.0 -typedef THRUST_DEPRECATED any_system_tag any_space_tag; - -} // end thrust - diff --git a/compat/thrust/iterator/detail/constant_iterator_base.h b/compat/thrust/iterator/detail/constant_iterator_base.h deleted file mode 100644 index 276e5ff..0000000 --- a/compat/thrust/iterator/detail/constant_iterator_base.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -// forward declaration of constant_iterator -template class constant_iterator; - -namespace detail -{ - -template - struct constant_iterator_base -{ - typedef Value value_type; - - // the reference type is the same as the value_type. - // we wish to avoid returning a reference to the internal state - // of the constant_iterator, which is prone to subtle bugs. - // consider the temporary iterator created in the expression - // *(iter + i) - typedef value_type reference; - - // the incrementable type is int unless otherwise specified - typedef typename thrust::detail::ia_dflt_help< - Incrementable, - thrust::detail::identity_ - >::type incrementable; - - typedef typename thrust::counting_iterator< - incrementable, - System, - thrust::random_access_traversal_tag - > base_iterator; - - typedef typename thrust::iterator_adaptor< - constant_iterator, - base_iterator, - value_type, // XXX we may need to pass const value_type here as boost counting_iterator does - typename thrust::iterator_system::type, - typename thrust::iterator_traversal::type, - reference - > type; -}; // end constant_iterator_base - -} // end detail - -} // end thrust - diff --git a/compat/thrust/iterator/detail/counting_iterator.inl b/compat/thrust/iterator/detail/counting_iterator.inl deleted file mode 100644 index ad4fcff..0000000 --- a/compat/thrust/iterator/detail/counting_iterator.inl +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -// forward declaration of counting_iterator -template - class counting_iterator; - -namespace detail -{ - -template - struct counting_iterator_base -{ - typedef typename thrust::detail::eval_if< - // use any_system_tag if we are given use_default - thrust::detail::is_same::value, - thrust::detail::identity_, - thrust::detail::identity_ - >::type system; - - typedef typename thrust::detail::ia_dflt_help< - Traversal, - thrust::detail::eval_if< - thrust::detail::is_numeric::value, - thrust::detail::identity_, - thrust::iterator_traversal - > - >::type traversal; - - // unlike Boost, we explicitly use std::ptrdiff_t as the difference type - // for floating point counting_iterators - typedef typename thrust::detail::ia_dflt_help< - Difference, - thrust::detail::eval_if< - thrust::detail::is_numeric::value, - thrust::detail::eval_if< - thrust::detail::is_integral::value, - thrust::detail::numeric_difference, - thrust::detail::identity_ - >, - thrust::iterator_difference - > - >::type difference; - - // our implementation departs from Boost's in that counting_iterator::dereference - // returns a copy of its counter, rather than a reference to it. returning a reference - // to the internal state of an iterator causes subtle bugs (consider the temporary - // iterator created in the expression *(iter + i) ) and has no compelling use case - typedef thrust::iterator_adaptor< - counting_iterator, // self - Incrementable, // Base - Incrementable, // XXX we may need to pass const here as Boost does - system, - traversal, - Incrementable, - difference - > type; -}; // end counting_iterator_base - - -template - struct iterator_distance -{ - __host__ __device__ - static Difference distance(Incrementable1 x, Incrementable2 y) - { - return y - x; - } -}; - - -template - struct number_distance -{ - __host__ __device__ - static Difference distance(Incrementable1 x, Incrementable2 y) - { - return static_cast(numeric_distance(x,y)); - } -}; - - -template - struct counting_iterator_equal -{ - __host__ __device__ - static bool equal(Incrementable1 x, Incrementable2 y) - { - return x == y; - } -}; - - -// specialization for floating point equality -template - struct counting_iterator_equal< - Difference, - Incrementable1, - Incrementable2, - typename thrust::detail::enable_if< - thrust::detail::is_floating_point::value || - thrust::detail::is_floating_point::value - >::type - > -{ - __host__ __device__ - static bool equal(Incrementable1 x, Incrementable2 y) - { - typedef number_distance d; - return d::distance(x,y) == 0; - } -}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/device_system_tag.h b/compat/thrust/iterator/detail/device_system_tag.h deleted file mode 100644 index ab66fb4..0000000 --- a/compat/thrust/iterator/detail/device_system_tag.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// #include the device system's execution_policy header -#define __THRUST_DEVICE_SYSTEM_TAG_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/execution_policy.h> -#include __THRUST_DEVICE_SYSTEM_TAG_HEADER -#undef __THRUST_DEVICE_SYSTEM_TAG_HEADER - -namespace thrust -{ - -typedef thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::tag device_system_tag; - -} // end thrust - -// TODO remove this in 1.8.0 -namespace thrust -{ - -typedef THRUST_DEPRECATED device_system_tag device_space_tag; - -} // end thrust - diff --git a/compat/thrust/iterator/detail/discard_iterator_base.h b/compat/thrust/iterator/detail/discard_iterator_base.h deleted file mode 100644 index 1909ca8..0000000 --- a/compat/thrust/iterator/detail/discard_iterator_base.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include // for std::ptrdiff_t - -namespace thrust -{ - -// forward declaration of discard_iterator -template class discard_iterator; - -namespace detail -{ - - -template - struct discard_iterator_base -{ - // XXX value_type should actually be void - // but this interferes with zip_iterator - typedef any_assign value_type; - typedef any_assign& reference; - typedef std::ptrdiff_t incrementable; - - typedef typename thrust::counting_iterator< - incrementable, - System, - thrust::random_access_traversal_tag - > base_iterator; - - typedef typename thrust::iterator_adaptor< - discard_iterator, - base_iterator, - value_type, - typename thrust::iterator_system::type, - typename thrust::iterator_traversal::type, - reference - > type; -}; // end discard_iterator_base - - -} // end detail - -} // end thrust - - diff --git a/compat/thrust/iterator/detail/distance_from_result.h b/compat/thrust/iterator/detail/distance_from_result.h deleted file mode 100644 index bf83e6c..0000000 --- a/compat/thrust/iterator/detail/distance_from_result.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace detail -{ - -// since both arguments are known to be specializations of iterator_facade, -// it's legal to access IteratorFacade2::difference_type -template - struct distance_from_result - : eval_if< - is_convertible::value, - identity_, - identity_ - > -{}; - -} // end detail - -} // end thrust - diff --git a/compat/thrust/iterator/detail/host_system_tag.h b/compat/thrust/iterator/detail/host_system_tag.h deleted file mode 100644 index 26d3f7d..0000000 --- a/compat/thrust/iterator/detail/host_system_tag.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// #include the host system's execution_policy header -#define __THRUST_HOST_SYSTEM_TAG_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/execution_policy.h> -#include __THRUST_HOST_SYSTEM_TAG_HEADER -#undef __THRUST_HOST_SYSTEM_TAG_HEADER - -namespace thrust -{ - -typedef thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::tag host_system_tag; - -} // end thrust - -// TODO remove this in 1.8.0 -namespace thrust -{ - -typedef THRUST_DEPRECATED host_system_tag host_space_tag; - -} // end thrust - diff --git a/compat/thrust/iterator/detail/is_iterator_category.h b/compat/thrust/iterator/detail/is_iterator_category.h deleted file mode 100644 index 95f14d5..0000000 --- a/compat/thrust/iterator/detail/is_iterator_category.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -template - struct is_host_iterator_category - : thrust::detail::or_< - thrust::detail::is_convertible, - thrust::detail::is_convertible - > -{ -}; // end is_host_iterator_category - -template - struct is_device_iterator_category - : thrust::detail::or_< - thrust::detail::is_convertible, - thrust::detail::is_convertible - > -{ -}; // end is_device_iterator_category - - -template - struct is_iterator_category - : thrust::detail::or_< - is_host_iterator_category, - is_device_iterator_category - > -{ -}; // end is_iterator_category - -} // end detail - -} // end thrust - diff --git a/compat/thrust/iterator/detail/is_trivial_iterator.h b/compat/thrust/iterator/detail/is_trivial_iterator.h deleted file mode 100644 index ca37e74..0000000 --- a/compat/thrust/iterator/detail/is_trivial_iterator.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#if __GNUC__ -// forward declaration of gnu's __normal_iterator -namespace __gnu_cxx -{ - -template class __normal_iterator; - -} // end __gnu_cxx -#endif // __GNUC__ - -#if _MSC_VER -// forward declaration of MSVC's "normal iterators" -namespace std -{ - -template struct _Ranit; - -} // end std -#endif // _MSC_VER - -namespace thrust -{ -namespace detail -{ - -#ifdef __GNUC__ -template - struct is_gnu_normal_iterator - : false_type -{}; - - -// catch gnu __normal_iterators -template - struct is_gnu_normal_iterator< __gnu_cxx::__normal_iterator > - : true_type -{}; -#endif // __GNUC__ - - -#ifdef _MSC_VER -// catch msvc _Ranit -template - struct is_convertible_to_msvc_Ranit : - is_convertible< - Iterator, - std::_Ranit< - typename iterator_value::type, - typename iterator_difference::type, - typename iterator_pointer::type, - typename iterator_reference::type - > - > -{}; -#endif // _MSC_VER - - -template - struct is_trivial_iterator : - integral_constant< - bool, - is_pointer::value - | thrust::detail::is_thrust_pointer::value -#if __GNUC__ - | is_gnu_normal_iterator::value -#endif // __GNUC__ -#ifdef _MSC_VER - | is_convertible_to_msvc_Ranit::value -#endif // _MSC_VER - > -{}; - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/iterator_adaptor_base.h b/compat/thrust/iterator/detail/iterator_adaptor_base.h deleted file mode 100644 index 8b77f05..0000000 --- a/compat/thrust/iterator/detail/iterator_adaptor_base.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - - -// forward declaration of iterator_adaptor for iterator_adaptor_base below -template -class iterator_adaptor; - - -namespace detail -{ - -// If T is use_default, return the result of invoking -// DefaultNullaryFn, otherwise return T. -// XXX rename to dflt_help -template -struct ia_dflt_help - : thrust::detail::eval_if< - thrust::detail::is_same::value - , DefaultNullaryFn - , thrust::detail::identity_ - > -{ -}; // end ia_dflt_help - - -// A metafunction which computes an iterator_adaptor's base class, -// a specialization of iterator_facade. -template - struct iterator_adaptor_base -{ - typedef typename ia_dflt_help< - Value, - iterator_value - >::type value; - - typedef typename ia_dflt_help< - System, - thrust::iterator_system - >::type system; - - typedef typename ia_dflt_help< - Traversal, - thrust::iterator_traversal - >::type traversal; - - typedef typename ia_dflt_help< - Reference, - thrust::detail::eval_if< - thrust::detail::is_same::value, - thrust::iterator_reference, - thrust::detail::add_reference - > - >::type reference; - - typedef typename ia_dflt_help< - Difference, - iterator_difference - >::type difference; - - typedef thrust::iterator_facade< - Derived, - value, - system, - traversal, - reference, - difference - > type; -}; // end iterator_adaptor_base - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/iterator_category_to_system.h b/compat/thrust/iterator/detail/iterator_category_to_system.h deleted file mode 100644 index 17e7d78..0000000 --- a/compat/thrust/iterator/detail/iterator_category_to_system.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -// XXX WAR circular #inclusion with forward declarations -struct random_access_universal_iterator_tag; -struct input_universal_iterator_tag; -struct output_universal_iterator_tag; - -namespace detail -{ - -// forward declaration -template struct is_iterator_system; - -template struct device_iterator_category_to_backend_system; - -// XXX this should work entirely differently -// we should just specialize this metafunction for iterator_category_with_system_and_traversal -template - struct iterator_category_to_system - // convertible to any iterator? - : eval_if< - or_< - is_convertible, - is_convertible - >::value, - - detail::identity_, - - // convertible to host iterator? - eval_if< - or_< - is_convertible, - is_convertible - >::value, - - detail::identity_, - - // convertible to device iterator? - eval_if< - or_< - is_convertible, - is_convertible - >::value, - - detail::identity_, - - // unknown system - detail::identity_ - > // if device - > // if host - > // if any -{ -}; // end iterator_category_to_system - - -template - struct iterator_category_or_traversal_to_system - : eval_if< - is_iterator_system::value, - detail::identity_, - iterator_category_to_system - > -{ -}; // end iterator_category_or_traversal_to_system - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/iterator_category_to_traversal.h b/compat/thrust/iterator/detail/iterator_category_to_traversal.h deleted file mode 100644 index 04ef60c..0000000 --- a/compat/thrust/iterator/detail/iterator_category_to_traversal.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -// XXX WAR circular #inclusion with these forward declarations -struct bidirectional_universal_iterator_tag; -struct forward_universal_iterator_tag; - -namespace detail -{ - -// forward declarations -template struct is_iterator_system; -template struct is_iterator_traversal; - -// make type_traits easy to access -using namespace thrust::detail; - -template - struct host_system_category_to_traversal - : eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - void - > - > - > - > - > -{ -}; // end host_system_category_to_traversal - - - -template - struct device_system_category_to_traversal - : eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - eval_if< - is_convertible::value, - detail::identity_, - void - > - > - > - > - > -{ -}; // end device_system_category_to_traversal - - - -template - struct any_system_category_to_traversal - : eval_if< - is_convertible::value, - identity_, - eval_if< - is_convertible::value, - identity_, - eval_if< - is_convertible::value, - identity_, - eval_if< - is_convertible::value, - identity_, - eval_if< - is_convertible::value, - identity_, - - // unknown traversal - void - > - > - > - > - > -{ -}; // end any_system_category_to_traversal - - -template - struct category_to_traversal - // check for any system - : eval_if< - or_< - is_convertible, - is_convertible - >::value, - - any_system_category_to_traversal, - - // check for host system - eval_if< - or_< - is_convertible, - is_convertible - >::value, - - host_system_category_to_traversal, - - // check for device system - eval_if< - or_< - is_convertible, - is_convertible - >::value, - - device_system_category_to_traversal, - - // unknown category - void - > - > - > -{}; - - -template - struct iterator_category_to_traversal - : eval_if< - is_iterator_traversal::value, - detail::identity_, - category_to_traversal - > -{ -}; // end iterator_category_to_traversal - - -} // end detail - -} // end thrust - diff --git a/compat/thrust/iterator/detail/iterator_facade_category.h b/compat/thrust/iterator/detail/iterator_facade_category.h deleted file mode 100644 index fbb8bd6..0000000 --- a/compat/thrust/iterator/detail/iterator_facade_category.h +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace detail -{ - -template - struct iterator_category_with_system_and_traversal - : Category -{ -}; // end iterator_category_with_system_and_traversal - -// specialize iterator_category_to_system for iterator_category_with_system_and_traversal -template struct iterator_category_to_system; - -template - struct iterator_category_to_system > -{ - typedef System type; -}; // end iterator_category_with_system_and_traversal - - -// adapted from http://www.boost.org/doc/libs/1_37_0/libs/iterator/doc/iterator_facade.html#iterator-category -// -// in our implementation, R need not be a reference type to result in a category -// derived from forward_XXX_iterator_tag -// -// iterator-category(T,V,R) := -// if(T is convertible to input_host_iterator_tag -// || T is convertible to output_host_iterator_tag -// || T is convertible to input_device_iterator_tag -// || T is convertible to output_device_iterator_tag -// ) -// return T -// -// else if (T is not convertible to incrementable_traversal_tag) -// the program is ill-formed -// -// else return a type X satisfying the following two constraints: -// -// 1. X is convertible to X1, and not to any more-derived -// type, where X1 is defined by: -// -// if (T is convertible to forward_traversal_tag) -// { -// if (T is convertible to random_access_traversal_tag) -// X1 = random_access_host_iterator_tag -// else if (T is convertible to bidirectional_traversal_tag) -// X1 = bidirectional_host_iterator_tag -// else -// X1 = forward_host_iterator_tag -// } -// else -// { -// if (T is convertible to single_pass_traversal_tag -// && R is convertible to V) -// X1 = input_host_iterator_tag -// else -// X1 = T -// } -// -// 2. category-to-traversal(X) is convertible to the most -// derived traversal tag type to which X is also convertible, -// and not to any more-derived traversal tag type. - - -template - struct iterator_facade_default_category; - - -// Thrust's implementation of iterator_facade_default_category is slightly -// different from Boost's equivalent. -// Thrust does not check is_convertible because Reference -// may not be a complete type at this point, and implementations of is_convertible -// typically require that both types be complete. -// Instead, it simply assumes that if is_convertible, -// then the category is input_iterator_tag - - -// this is the function for standard system iterators -template - struct iterator_facade_default_category_std : - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::identity_ - > - >, - thrust::detail::eval_if< // XXX note we differ from Boost here - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::identity_ - > - > -{ -}; // end iterator_facade_default_category_std - - -// this is the function for host system iterators -template - struct iterator_facade_default_category_host : - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::identity_ - > - >, - thrust::detail::eval_if< // XXX note we differ from Boost here - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::identity_ - > - > -{ -}; // end iterator_facade_default_category_host - - -// this is the function for device system iterators -template - struct iterator_facade_default_category_device : - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::identity_ - > - >, - thrust::detail::eval_if< - thrust::detail::is_convertible::value, // XXX note we differ from Boost here - thrust::detail::identity_, - thrust::detail::identity_ - > - > -{ -}; // end iterator_facade_default_category_device - - -// this is the function for any system iterators -template - struct iterator_facade_default_category_any : - thrust::detail::eval_if< - - thrust::detail::is_convertible::value, - - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - thrust::detail::identity_, - thrust::detail::identity_ - > - >, - - thrust::detail::eval_if< - thrust::detail::is_convertible::value, // XXX note we differ from Boost here - thrust::detail::identity_, - thrust::detail::identity_ - > - > -{ -}; // end iterator_facade_default_category_any - - -template - struct iterator_facade_default_category - // check for any system - : thrust::detail::eval_if< - thrust::detail::is_convertible::value, - iterator_facade_default_category_any, - - // check for host system - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - iterator_facade_default_category_host, - - // check for device system - thrust::detail::eval_if< - thrust::detail::is_convertible::value, - iterator_facade_default_category_device, - - // if we don't recognize the system, get a standard iterator category - // and combine it with System & Traversal - thrust::detail::identity_< - thrust::detail::iterator_category_with_system_and_traversal< - typename iterator_facade_default_category_std::type, - System, - Traversal - > - > - > - > - > -{}; - - -template - struct iterator_facade_category_impl -{ - typedef typename iterator_facade_default_category< - System,Traversal,ValueParam,Reference - >::type category; - - // we must be able to deduce both Traversal & System from category - // otherwise, munge them all together - typedef typename thrust::detail::eval_if< - thrust::detail::and_< - thrust::detail::is_same< - Traversal, - typename thrust::detail::iterator_category_to_traversal::type - >, - thrust::detail::is_same< - System, - typename thrust::detail::iterator_category_to_system::type - > - >::value, - thrust::detail::identity_, - thrust::detail::identity_ > - >::type type; -}; // end iterator_facade_category_impl - - -template - struct iterator_facade_category -{ - typedef typename - thrust::detail::eval_if< - thrust::detail::is_iterator_category::value, - thrust::detail::identity_, // categories are fine as-is - iterator_facade_category_impl - >::type type; -}; // end iterator_facade_category - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/iterator_traits.inl b/compat/thrust/iterator/detail/iterator_traits.inl deleted file mode 100644 index 924eabb..0000000 --- a/compat/thrust/iterator/detail/iterator_traits.inl +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file iterator_traits.inl - * \brief Inline file for iterator_traits.h. - */ - -#include -#include -#include - -namespace thrust -{ - -template - struct iterator_value -{ - typedef typename thrust::iterator_traits::value_type type; -}; // end iterator_value - - -template - struct iterator_pointer -{ - typedef typename thrust::iterator_traits::pointer type; -}; // end iterator_pointer - - -template - struct iterator_reference -{ - typedef typename iterator_traits::reference type; -}; // end iterator_reference - - -template - struct iterator_difference -{ - typedef typename thrust::iterator_traits::difference_type type; -}; // end iterator_difference - - -template - struct iterator_system - : detail::iterator_category_to_system< - typename thrust::iterator_traits::iterator_category - > -{ -}; // end iterator_system - -// specialize iterator_system for void *, which has no category -template<> - struct iterator_system -{ - typedef thrust::iterator_system::type type; -}; // end iterator_system - -template<> - struct iterator_system -{ - typedef thrust::iterator_system::type type; -}; // end iterator_system - - -template - struct iterator_traversal - : detail::iterator_category_to_traversal< - typename thrust::iterator_traits::iterator_category - > -{ -}; // end iterator_traversal - -namespace detail -{ - -template - struct is_iterator_traversal - : thrust::detail::is_convertible -{ -}; // end is_iterator_traversal - - -template - struct is_iterator_system - : detail::or_< - detail::is_convertible, - detail::or_< - detail::is_convertible, - detail::is_convertible - > - > -{ -}; // end is_iterator_system - - -} // end namespace detail -} // end namespace thrust - diff --git a/compat/thrust/iterator/detail/iterator_traversal_tags.h b/compat/thrust/iterator/detail/iterator_traversal_tags.h deleted file mode 100644 index dcbebf3..0000000 --- a/compat/thrust/iterator/detail/iterator_traversal_tags.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace thrust -{ - -// define Boost's traversal tags -struct no_traversal_tag {}; - -struct incrementable_traversal_tag - : no_traversal_tag {}; - -struct single_pass_traversal_tag - : incrementable_traversal_tag {}; - -struct forward_traversal_tag - : single_pass_traversal_tag {}; - -struct bidirectional_traversal_tag - : forward_traversal_tag {}; - -struct random_access_traversal_tag - : bidirectional_traversal_tag {}; - -} // end thrust - diff --git a/compat/thrust/iterator/detail/minimum_category.h b/compat/thrust/iterator/detail/minimum_category.h deleted file mode 100644 index e07e096..0000000 --- a/compat/thrust/iterator/detail/minimum_category.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ - -namespace detail -{ - -template - struct minimum_category - : minimum_type -{ -}; // end minimum_category - -} // end detail - -} // end thrust - - diff --git a/compat/thrust/iterator/detail/minimum_system.h b/compat/thrust/iterator/detail/minimum_system.h deleted file mode 100644 index 5448a0d..0000000 --- a/compat/thrust/iterator/detail/minimum_system.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace detail -{ - -template - struct minimum_system - : minimum_type -{ -}; // end minimum_system - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/normal_iterator.h b/compat/thrust/iterator/detail/normal_iterator.h deleted file mode 100644 index 7fe61bf..0000000 --- a/compat/thrust/iterator/detail/normal_iterator.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file normal_iterator.h - * \brief Defines the interface to an iterator class - * which adapts a pointer type. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template - class normal_iterator - : public iterator_adaptor< - normal_iterator, - Pointer - > -{ - typedef iterator_adaptor, Pointer> super_t; - - public: - __host__ __device__ - normal_iterator() {} - - __host__ __device__ - normal_iterator(Pointer p) - : super_t(p) {} - - template - __host__ __device__ - normal_iterator(const normal_iterator &other, - typename thrust::detail::enable_if_convertible< - OtherPointer, - Pointer - >::type * = 0) - : super_t(other.base()) {} - -}; // end normal_iterator - - -template - inline __host__ __device__ normal_iterator make_normal_iterator(Pointer ptr) -{ - return normal_iterator(ptr); -} - - -template struct is_trivial_iterator< normal_iterator > : public true_type {}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/permutation_iterator_base.h b/compat/thrust/iterator/detail/permutation_iterator_base.h deleted file mode 100644 index a145b88..0000000 --- a/compat/thrust/iterator/detail/permutation_iterator_base.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -template class permutation_iterator; - - -namespace detail -{ - -template - struct permutation_iterator_base -{ - typedef typename thrust::iterator_system::type System1; - typedef typename thrust::iterator_system::type System2; - - typedef thrust::iterator_adaptor< - permutation_iterator, - IndexIterator, - typename thrust::iterator_value::type, - typename detail::minimum_system::type, - thrust::use_default, - typename thrust::iterator_reference::type - > type; -}; // end permutation_iterator_base - -} // end detail - -} // end thrust - diff --git a/compat/thrust/iterator/detail/retag.h b/compat/thrust/iterator/detail/retag.h deleted file mode 100644 index 4417fa5..0000000 --- a/compat/thrust/iterator/detail/retag.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -// we can retag an iterator if FromTag converts to ToTag -// or vice versa -template - struct is_retaggable - : integral_constant< - bool, - (is_convertible::value || is_convertible::value) - > -{}; - - -template - struct enable_if_retaggable - : enable_if< - is_retaggable::value, - Result - > -{}; // end enable_if_retaggable - - -} // end detail - - -template - thrust::detail::tagged_iterator - reinterpret_tag(Iterator iter) -{ - return thrust::detail::tagged_iterator(iter); -} // end reinterpret_tag() - - -// specialization for raw pointer -template - thrust::pointer - reinterpret_tag(T *ptr) -{ - return thrust::pointer(ptr); -} // end reinterpret_tag() - - -// specialization for thrust::pointer -template - thrust::pointer - reinterpret_tag(thrust::pointer ptr) -{ - return reinterpret_tag(ptr.get()); -} // end reinterpret_tag() - - -// avoid deeply-nested tagged_iterator -template - thrust::detail::tagged_iterator - reinterpret_tag(thrust::detail::tagged_iterator iter) -{ - return reinterpret_tag(iter.base()); -} // end reinterpret_tag() - - -template - typename thrust::detail::enable_if_retaggable< - typename thrust::iterator_system::type, - Tag, - thrust::detail::tagged_iterator - >::type - retag(Iterator iter) -{ - return reinterpret_tag(iter); -} // end retag() - - -// specialization for raw pointer -template - typename thrust::detail::enable_if_retaggable< - typename thrust::iterator_system::type, - Tag, - thrust::pointer - >::type - retag(T *ptr) -{ - return reinterpret_tag(ptr); -} // end retag() - - -// specialization for thrust::pointer -template - typename thrust::detail::enable_if_retaggable< - OtherTag, - Tag, - thrust::pointer - >::type - retag(thrust::pointer ptr) -{ - return reinterpret_tag(ptr); -} // end retag() - - -// avoid deeply-nested tagged_iterator -template - typename thrust::detail::enable_if_retaggable< - OtherTag, - Tag, - thrust::detail::tagged_iterator - >::type - retag(thrust::detail::tagged_iterator iter) -{ - return reinterpret_tag(iter); -} // end retag() - - -} // end thrust - diff --git a/compat/thrust/iterator/detail/reverse_iterator.inl b/compat/thrust/iterator/detail/reverse_iterator.inl deleted file mode 100644 index 03e9032..0000000 --- a/compat/thrust/iterator/detail/reverse_iterator.inl +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace thrust -{ - -namespace detail -{ - -__thrust_hd_warning_disable__ -template -__host__ __device__ - Iterator prior(Iterator x) -{ - return --x; -} // end prior() - -} // end detail - -template - reverse_iterator - ::reverse_iterator(BidirectionalIterator x) - :super_t(x) -{ -} // end reverse_iterator::reverse_iterator() - -template - template - reverse_iterator - ::reverse_iterator(reverse_iterator const &r -// XXX msvc screws this up -#ifndef _MSC_VER - , typename thrust::detail::enable_if< - thrust::detail::is_convertible< - OtherBidirectionalIterator, - BidirectionalIterator - >::value - >::type * -#endif // _MSC_VER - ) - :super_t(r.base()) -{ -} // end reverse_iterator::reverse_iterator() - -template - typename reverse_iterator::super_t::reference - reverse_iterator - ::dereference(void) const -{ - return *thrust::detail::prior(this->base()); -} // end reverse_iterator::increment() - -template - void reverse_iterator - ::increment(void) -{ - --this->base_reference(); -} // end reverse_iterator::increment() - -template - void reverse_iterator - ::decrement(void) -{ - ++this->base_reference(); -} // end reverse_iterator::decrement() - -template - void reverse_iterator - ::advance(typename super_t::difference_type n) -{ - this->base_reference() += -n; -} // end reverse_iterator::advance() - -template - template - typename reverse_iterator::super_t::difference_type - reverse_iterator - ::distance_to(reverse_iterator const &y) const -{ - return this->base_reference() - y.base(); -} // end reverse_iterator::distance_to() - -template -__host__ __device__ -reverse_iterator make_reverse_iterator(BidirectionalIterator x) -{ - return reverse_iterator(x); -} // end make_reverse_iterator() - - -} // end thrust - diff --git a/compat/thrust/iterator/detail/reverse_iterator_base.h b/compat/thrust/iterator/detail/reverse_iterator_base.h deleted file mode 100644 index c10c5b7..0000000 --- a/compat/thrust/iterator/detail/reverse_iterator_base.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -template class reverse_iterator; - -namespace detail -{ - -template - struct reverse_iterator_base -{ - typedef thrust::iterator_adaptor< - thrust::reverse_iterator, - BidirectionalIterator - > type; -}; // end reverse_iterator_base - -} // end detail - -} // end thrust - diff --git a/compat/thrust/iterator/detail/tagged_iterator.h b/compat/thrust/iterator/detail/tagged_iterator.h deleted file mode 100644 index 69e6445..0000000 --- a/compat/thrust/iterator/detail/tagged_iterator.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -template class tagged_iterator; - -template - struct tagged_iterator_base -{ - typedef thrust::iterator_adaptor< - tagged_iterator, - Iterator, - typename thrust::iterator_value::type, - Tag, - typename thrust::iterator_traversal::type, - typename thrust::iterator_reference::type, - typename thrust::iterator_difference::type - > type; -}; // end tagged_iterator_base - -template - class tagged_iterator - : public tagged_iterator_base::type -{ - private: - typedef typename tagged_iterator_base::type super_t; - - public: - __host__ __device__ - tagged_iterator(void) {} - - __host__ __device__ - explicit tagged_iterator(Iterator x) - : super_t(x) {} -}; // end tagged_iterator - - -// specialize is_trivial_iterator for tagged_iterator -template struct is_trivial_iterator; - -// tagged_iterator is trivial if its base iterator is -template - struct is_trivial_iterator > - : is_trivial_iterator -{}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/transform_iterator.inl b/compat/thrust/iterator/detail/transform_iterator.inl deleted file mode 100644 index a5a36a7..0000000 --- a/compat/thrust/iterator/detail/transform_iterator.inl +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ - -template - class transform_iterator; - -namespace detail -{ - -// Compute the iterator_adaptor instantiation to be used for transform_iterator -template -struct transform_iterator_base -{ - private: - // By default, dereferencing the iterator yields the same as the function. - typedef typename thrust::detail::ia_dflt_help< - Reference, - thrust::detail::result_of::type)> - >::type reference; - - // To get the default for Value: remove any reference on the - // result type, but retain any constness to signal - // non-writability. Note that if we adopt Thomas' suggestion - // to key non-writability *only* on the Reference argument, - // we'd need to strip constness here as well. - typedef typename thrust::detail::ia_dflt_help< - Value, - thrust::detail::remove_reference - >::type cv_value_type; - - public: - typedef thrust::iterator_adaptor - < - transform_iterator - , Iterator - , cv_value_type - , thrust::use_default // Leave the system alone - //, thrust::use_default // Leave the traversal alone - // use the Iterator's category to let any system iterators remain random access even though - // transform_iterator's reference type may not be a reference - // XXX figure out why only iterators whose reference types are true references are random access - , typename thrust::iterator_traits::iterator_category - , reference - > type; -}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/tuple_of_iterator_references.h b/compat/thrust/iterator/detail/tuple_of_iterator_references.h deleted file mode 100644 index fdbf6b8..0000000 --- a/compat/thrust/iterator/detail/tuple_of_iterator_references.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - - -template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> - class tuple_of_iterator_references - : public thrust::tuple -{ - private: - typedef thrust::tuple super_t; - - public: - // allow implicit construction from tuple - inline __host__ __device__ - tuple_of_iterator_references(const super_t &other) - : super_t(other) - {} - - // allow assignment from tuples - // XXX might be worthwhile to guard this with an enable_if is_assignable - template - inline __host__ __device__ - tuple_of_iterator_references &operator=(const detail::cons &other) - { - super_t::operator=(other); - return *this; - } - - // allow assignment from pairs - // XXX might be worthwhile to guard this with an enable_if is_assignable - template - inline __host__ __device__ - tuple_of_iterator_references &operator=(const thrust::pair &other) - { - super_t::operator=(other); - return *this; - } - - // allow assignment from reference - // XXX perhaps we should generalize to reference - // we could captures reference this way - template - inline __host__ __device__ -// XXX gcc-4.2 crashes on is_assignable -// typename thrust::detail::enable_if< -// thrust::detail::is_assignable< -// super_t, -// const thrust::tuple -// >::value, -// tuple_of_iterator_references & -// >::type - tuple_of_iterator_references & - operator=(const thrust::reference, Pointer, Derived> &other) - { - typedef thrust::tuple tuple_type; - - // XXX perhaps this could be accelerated - tuple_type other_tuple = other; - super_t::operator=(other_tuple); - return *this; - } - - - // duplicate thrust::tuple's constructors - inline __host__ __device__ - tuple_of_iterator_references() {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0) - : super_t(t0, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1) - : super_t(t0, t1, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2) - : super_t(t0, t1, t2, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3) - : super_t(t0, t1, t2, t3, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4) - : super_t(t0, t1, t2, t3, t4, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5) - : super_t(t0, t1, t2, t3, t4, t5, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6) - : super_t(t0, t1, t2, t3, t4, t5, t6, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6, - typename access_traits::parameter_type t7) - : super_t(t0, t1, t2, t3, t4, t5, t6, t7, - static_cast(null_type()), - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6, - typename access_traits::parameter_type t7, - typename access_traits::parameter_type t8) - : super_t(t0, t1, t2, t3, t4, t5, t6, t7, t8, - static_cast(null_type())) - {} - - inline __host__ __device__ - tuple_of_iterator_references(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6, - typename access_traits::parameter_type t7, - typename access_traits::parameter_type t8, - typename access_traits::parameter_type t9) - : super_t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) - {} -}; - - -} // end detail -} // end thrust - diff --git a/compat/thrust/iterator/detail/universal_categories.h b/compat/thrust/iterator/detail/universal_categories.h deleted file mode 100644 index 7c39222..0000000 --- a/compat/thrust/iterator/detail/universal_categories.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -// define these types without inheritance to avoid ambiguous conversion to base classes - -struct input_universal_iterator_tag -{ - operator input_host_iterator_tag () {return input_host_iterator_tag();} - - operator input_device_iterator_tag () {return input_device_iterator_tag();} -}; - -struct output_universal_iterator_tag -{ - operator output_host_iterator_tag () {return output_host_iterator_tag();} - - operator output_device_iterator_tag () {return output_device_iterator_tag();} -}; - -struct forward_universal_iterator_tag - : input_universal_iterator_tag -{ - operator forward_host_iterator_tag () {return forward_host_iterator_tag();}; - - operator forward_device_iterator_tag () {return forward_device_iterator_tag();}; -}; - -struct bidirectional_universal_iterator_tag - : forward_universal_iterator_tag -{ - operator bidirectional_host_iterator_tag () {return bidirectional_host_iterator_tag();}; - - operator bidirectional_device_iterator_tag () {return bidirectional_device_iterator_tag();}; -}; - - -namespace detail -{ - -// create this struct to control conversion precedence in random_access_universal_iterator_tag -template -struct one_degree_of_separation - : T -{ -}; - -} // end detail - - -struct random_access_universal_iterator_tag -{ - // these conversions are all P0 - operator random_access_host_iterator_tag () {return random_access_host_iterator_tag();}; - - operator random_access_device_iterator_tag () {return random_access_device_iterator_tag();}; - - // bidirectional_universal_iterator_tag is P1 - operator detail::one_degree_of_separation () {return detail::one_degree_of_separation();} - -}; - - -} // end thrust - diff --git a/compat/thrust/iterator/detail/zip_iterator.inl b/compat/thrust/iterator/detail/zip_iterator.inl deleted file mode 100644 index fddd0ad..0000000 --- a/compat/thrust/iterator/detail/zip_iterator.inl +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -template - zip_iterator - ::zip_iterator(void) -{ -} // end zip_iterator::zip_iterator() - - -template - zip_iterator - ::zip_iterator(IteratorTuple iterator_tuple) - :m_iterator_tuple(iterator_tuple) -{ -} // end zip_iterator::zip_iterator() - - -template - template - zip_iterator - ::zip_iterator(const zip_iterator &other, - typename thrust::detail::enable_if_convertible< - OtherIteratorTuple, - IteratorTuple - >::type *) - :m_iterator_tuple(other.get_iterator_tuple()) -{ -} // end zip_iterator::zip_iterator() - - -template -const IteratorTuple &zip_iterator - ::get_iterator_tuple(void) const -{ - return m_iterator_tuple; -} // end zip_iterator::get_iterator_tuple() - - -template - typename zip_iterator::super_t::reference - zip_iterator - ::dereference(void) const -{ - using namespace detail::tuple_impl_specific; - - return thrust::detail::tuple_host_device_transform(get_iterator_tuple(), detail::dereference_iterator()); -} // end zip_iterator::dereference() - - -__thrust_hd_warning_disable__ -template - template - bool zip_iterator - ::equal(const zip_iterator &other) const -{ - return get<0>(get_iterator_tuple()) == get<0>(other.get_iterator_tuple()); -} // end zip_iterator::equal() - - -template - void zip_iterator - ::advance(typename super_t::difference_type n) -{ - using namespace detail::tuple_impl_specific; - - // XXX note that we use a pointer to System to dispatch to avoid - // default construction of a System - typename thrust::iterator_system::type *use_me_to_dispatch = 0; - - // dispatch on system - tuple_for_each(m_iterator_tuple, - detail::advance_iterator(n), - use_me_to_dispatch); -} // end zip_iterator::advance() - - -template - void zip_iterator - ::increment(void) -{ - using namespace detail::tuple_impl_specific; - - // XXX note that we use a pointer to System to dispatch to avoid - // default construction of a System - typename thrust::iterator_system::type *use_me_to_dispatch = 0; - - // dispatch on system - tuple_for_each(m_iterator_tuple, detail::increment_iterator(), - use_me_to_dispatch); -} // end zip_iterator::increment() - - -template - void zip_iterator - ::decrement(void) -{ - using namespace detail::tuple_impl_specific; - - // XXX note that we use a pointer to System to dispatch to avoid - // default construction of a System - typename thrust::iterator_system::type *use_me_to_dispatch = 0; - - // dispatch on system - tuple_for_each(m_iterator_tuple, detail::decrement_iterator(), - use_me_to_dispatch); -} // end zip_iterator::decrement() - - -__thrust_hd_warning_disable__ -template - template - typename zip_iterator::super_t::difference_type - zip_iterator - ::distance_to(const zip_iterator &other) const -{ - return get<0>(other.get_iterator_tuple()) - get<0>(get_iterator_tuple()); -} // end zip_iterator::distance_to() - - -template - zip_iterator make_zip_iterator(IteratorTuple t) -{ - return zip_iterator(t); -} // end make_zip_iterator() - - -} // end thrust - diff --git a/compat/thrust/iterator/detail/zip_iterator_base.h b/compat/thrust/iterator/detail/zip_iterator_base.h deleted file mode 100644 index 9dd7789..0000000 --- a/compat/thrust/iterator/detail/zip_iterator_base.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -// forward declare zip_iterator for zip_iterator_base -template class zip_iterator; - -namespace detail -{ - - -// Functors to be used with tuple algorithms -// -template -class advance_iterator -{ -public: - inline __host__ __device__ - advance_iterator(DiffType step) : m_step(step) {} - - template - inline __host__ __device__ - void operator()(Iterator& it) const - { it += m_step; } - -private: - DiffType m_step; -}; // end advance_iterator - - -struct increment_iterator -{ - template - inline __host__ __device__ - void operator()(Iterator& it) - { ++it; } -}; // end increment_iterator - - -struct decrement_iterator -{ - template - inline __host__ __device__ - void operator()(Iterator& it) - { --it; } -}; // end decrement_iterator - - -struct dereference_iterator -{ - template - struct apply - { - typedef typename - iterator_traits::reference - type; - }; // end apply - - // XXX silence warnings of the form "calling a __host__ function from a __host__ __device__ function is not allowed - __thrust_hd_warning_disable__ - template - __host__ __device__ - typename apply::type operator()(Iterator const& it) - { - return *it; - } -}; // end dereference_iterator - - -// The namespace tuple_impl_specific provides two meta- -// algorithms and two algorithms for tuples. -namespace tuple_impl_specific -{ - -// define apply1 for tuple_meta_transform_impl -template - struct apply1 - : UnaryMetaFunctionClass::template apply -{ -}; // end apply1 - - -// define apply2 for tuple_meta_accumulate_impl -template - struct apply2 - : UnaryMetaFunctionClass::template apply -{ -}; // end apply2 - - -// Meta-accumulate algorithm for tuples. Note: The template -// parameter StartType corresponds to the initial value in -// ordinary accumulation. -// -template - struct tuple_meta_accumulate; - -template< - typename Tuple - , class BinaryMetaFun - , typename StartType -> - struct tuple_meta_accumulate_impl -{ - typedef typename apply2< - BinaryMetaFun - , typename Tuple::head_type - , typename tuple_meta_accumulate< - typename Tuple::tail_type - , BinaryMetaFun - , StartType - >::type - >::type type; -}; - - -template< - typename Tuple - , class BinaryMetaFun - , typename StartType -> -struct tuple_meta_accumulate - : thrust::detail::eval_if< - thrust::detail::is_same::value - , thrust::detail::identity_ - , tuple_meta_accumulate_impl< - Tuple - , BinaryMetaFun - , StartType - > - > // end eval_if -{ -}; // end tuple_meta_accumulate - - -// transform algorithm for tuples. The template parameter Fun -// must be a unary functor which is also a unary metafunction -// class that computes its return type based on its argument -// type. For example: -// -// struct to_ptr -// { -// template -// struct apply -// { -// typedef Arg* type; -// } -// -// template -// Arg* operator()(Arg x); -// }; - - - -// for_each algorithm for tuples. -// -template -inline __host__ __device__ -Fun tuple_for_each(thrust::null_type, Fun f, System *) -{ - return f; -} // end tuple_for_each() - - -template -inline __host__ __device__ -Fun tuple_for_each(Tuple& t, Fun f, System *dispatch_tag) -{ - f( t.get_head() ); - return tuple_for_each(t.get_tail(), f, dispatch_tag); -} // end tuple_for_each() - - -template -inline __host__ __device__ -Fun tuple_for_each(Tuple& t, Fun f, thrust::host_system_tag *dispatch_tag) -{ -// XXX this path is required in order to accomodate pure host iterators -// (such as std::vector::iterator) in a zip_iterator -#ifndef __CUDA_ARCH__ - f( t.get_head() ); - return tuple_for_each(t.get_tail(), f, dispatch_tag); -#else - // this code will never be called - return f; -#endif -} // end tuple_for_each() - - -// Equality of tuples. NOTE: "==" for tuples currently (7/2003) -// has problems under some compilers, so I just do my own. -// No point in bringing in a bunch of #ifdefs here. This is -// going to go away with the next tuple implementation anyway. -// -__host__ __device__ -inline bool tuple_equal(thrust::null_type, thrust::null_type) -{ return true; } - - -template -__host__ __device__ -bool tuple_equal(Tuple1 const& t1, Tuple2 const& t2) -{ - return t1.get_head() == t2.get_head() && - tuple_equal(t1.get_tail(), t2.get_tail()); -} // end tuple_equal() - -} // end end tuple_impl_specific - - -// Metafunction to obtain the type of the tuple whose element types -// are the value_types of an iterator tupel. -// -template - struct tuple_of_value_types - : tuple_meta_transform< - IteratorTuple, - iterator_value - > -{ -}; // end tuple_of_value_types - - -struct minimum_category_lambda -{ - template - struct apply : minimum_category - {}; -}; - - - -// Metafunction to obtain the minimal traversal tag in a tuple -// of iterators. -// -template -struct minimum_traversal_category_in_iterator_tuple -{ - typedef typename tuple_meta_transform< - IteratorTuple - , thrust::iterator_traversal - >::type tuple_of_traversal_tags; - - typedef typename tuple_impl_specific::tuple_meta_accumulate< - tuple_of_traversal_tags - , minimum_category_lambda - , thrust::random_access_traversal_tag - >::type type; -}; - - -struct minimum_system_lambda -{ - template - struct apply : minimum_system - {}; -}; - - - -// Metafunction to obtain the minimal system tag in a tuple -// of iterators. -template -struct minimum_system_in_iterator_tuple -{ - typedef typename thrust::detail::tuple_meta_transform< - IteratorTuple, - thrust::iterator_system - >::type tuple_of_system_tags; - - typedef typename tuple_impl_specific::tuple_meta_accumulate< - tuple_of_system_tags, - minimum_system_lambda, - thrust::any_system_tag - >::type type; -}; - -namespace zip_iterator_base_ns -{ - - -template - struct tuple_elements_helper - : eval_if< - (i < tuple_size::value), - tuple_element, - identity_ - > -{}; - - -template - struct tuple_elements -{ - typedef typename tuple_elements_helper<0,Tuple>::type T0; - typedef typename tuple_elements_helper<1,Tuple>::type T1; - typedef typename tuple_elements_helper<2,Tuple>::type T2; - typedef typename tuple_elements_helper<3,Tuple>::type T3; - typedef typename tuple_elements_helper<4,Tuple>::type T4; - typedef typename tuple_elements_helper<5,Tuple>::type T5; - typedef typename tuple_elements_helper<6,Tuple>::type T6; - typedef typename tuple_elements_helper<7,Tuple>::type T7; - typedef typename tuple_elements_helper<8,Tuple>::type T8; - typedef typename tuple_elements_helper<9,Tuple>::type T9; -}; - - -template - struct tuple_of_iterator_references -{ - // get a thrust::tuple of the iterators' references - typedef typename tuple_meta_transform< - IteratorTuple, - iterator_reference - >::type tuple_of_references; - - // get at the individual tuple element types by name - typedef tuple_elements elements; - - // map thrust::tuple to tuple_of_iterator_references - typedef thrust::detail::tuple_of_iterator_references< - typename elements::T0, - typename elements::T1, - typename elements::T2, - typename elements::T3, - typename elements::T4, - typename elements::T5, - typename elements::T6, - typename elements::T7, - typename elements::T8, - typename elements::T9 - > type; -}; - - -} // end zip_iterator_base_ns - -/////////////////////////////////////////////////////////////////// -// -// Class zip_iterator_base -// -// Builds and exposes the iterator facade type from which the zip -// iterator will be derived. -// -template - struct zip_iterator_base -{ - //private: - // reference type is the type of the tuple obtained from the - // iterators' reference types. - typedef typename zip_iterator_base_ns::tuple_of_iterator_references::type reference; - - // Boost's Value type is the same as reference type. - //typedef reference value_type; - typedef typename tuple_of_value_types::type value_type; - - // Difference type is the first iterator's difference type - typedef typename thrust::iterator_traits< - typename thrust::tuple_element<0, IteratorTuple>::type - >::difference_type difference_type; - - // Iterator system is the minimum system tag in the - // iterator tuple - typedef typename - minimum_system_in_iterator_tuple::type system; - - // Traversal category is the minimum traversal category in the - // iterator tuple - typedef typename - minimum_traversal_category_in_iterator_tuple::type traversal_category; - - public: - - // The iterator facade type from which the zip iterator will - // be derived. - typedef thrust::iterator_facade< - zip_iterator, - value_type, - system, - traversal_category, - reference, - difference_type - > type; -}; // end zip_iterator_base - -} // end detail - -} // end thrust - - diff --git a/compat/thrust/iterator/discard_iterator.h b/compat/thrust/iterator/discard_iterator.h deleted file mode 100644 index 6e089b5..0000000 --- a/compat/thrust/iterator/discard_iterator.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/discard_iterator.h - * \brief An iterator which "discards" (ignores) values assigned to it upon dereference - */ - -#pragma once - -#include -#include -#include - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p discard_iterator is an iterator which represents a special kind of pointer that - * ignores values written to it upon dereference. This iterator is useful for ignoring - * the output of certain algorithms without wasting memory capacity or bandwidth. - * \p discard_iterator may also be used to count the size of an algorithm's output which - * may not be known a priori. - * - * The following code snippet demonstrates how to use \p discard_iterator to ignore - * ignore one of the output ranges of reduce_by_key - * - * \code - * #include - * #include - * #include - * - * int main(void) - * { - * thrust::device_vector keys(7), values(7); - * - * keys[0] = 1; - * keys[1] = 3; - * keys[2] = 3; - * keys[3] = 3; - * keys[4] = 2; - * keys[5] = 2; - * keys[6] = 1; - * - * values[0] = 9; - * values[1] = 8; - * values[2] = 7; - * values[3] = 6; - * values[4] = 5; - * values[5] = 4; - * values[6] = 3; - * - * thrust::device_vector result(4); - * - * // we are only interested in the reduced values - * // use discard_iterator to ignore the output keys - * thrust::reduce_by_key(keys.begin(), keys.end(), - * values.begin(), values.end(), - * thrust::make_discard_iterator(), - * result.begin()); - * - * // result is now [9, 21, 9, 3] - * - * return 0; - * } - * \endcode - * - * \see make_discard_iterator - */ -template - class discard_iterator - : public detail::discard_iterator_base::type -{ - /*! \cond - */ - friend class thrust::iterator_core_access; - typedef typename detail::discard_iterator_base::type super_t; - typedef typename detail::discard_iterator_base::incrementable incrementable; - typedef typename detail::discard_iterator_base::base_iterator base_iterator; - - public: - typedef typename super_t::reference reference; - typedef typename super_t::value_type value_type; - - /*! \endcond - */ - - /*! Copy constructor copies from a source discard_iterator. - * - * \p rhs The discard_iterator to copy. - */ - __host__ __device__ - discard_iterator(discard_iterator const &rhs) - : super_t(rhs.base()) {} - - /*! This constructor receives an optional index specifying the position of this - * \p discard_iterator in a range. - * - * \p i The index of this \p discard_iterator in a range. Defaults to the - * value returned by \c Incrementable's null constructor. For example, - * when Incrementable == int, \c 0. - */ - __host__ __device__ - discard_iterator(incrementable const &i = incrementable()) - : super_t(base_iterator(i)) {} - - /*! \cond - */ - - private: // Core iterator interface - __host__ __device__ - reference dereference(void) const - { - return m_element; - } - - mutable value_type m_element; - - /*! \endcond - */ -}; // end constant_iterator - - -/*! \p make_discard_iterator creates a \p discard_iterator from an optional index parameter. - * - * \param i The index of the returned \p discard_iterator within a range. - * In the default case, the value of this parameter is \c 0. - * - * \return A new \p discard_iterator with index as given by \p i. - * - * \see constant_iterator - */ -inline __host__ __device__ -discard_iterator<> make_discard_iterator(discard_iterator<>::difference_type i = discard_iterator<>::difference_type(0)) -{ - return discard_iterator<>(i); -} // end make_discard_iterator() - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end namespace thrust - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - diff --git a/compat/thrust/iterator/iterator_adaptor.h b/compat/thrust/iterator/iterator_adaptor.h deleted file mode 100644 index 7b9cca3..0000000 --- a/compat/thrust/iterator/iterator_adaptor.h +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/iterator_adaptor.h - * \brief An iterator which adapts a base iterator - */ - -/* - * (C) Copyright David Abrahams 2002. - * (C) Copyright Jeremy Siek 2002. - * (C) Copyright Thomas Witt 2002. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p iterator_adaptor is an iterator which adapts an existing type of iterator to create a new type of - * iterator. Most of Thrust's fancy iterators are defined via inheritance from \p iterator_adaptor. - * While composition of these existing Thrust iterators is often sufficient for expressing the desired - * functionality, it is occasionally more straightforward to derive from \p iterator_adaptor directly. - * - * To see how to use \p iterator_adaptor to create a novel iterator type, let's examine how to use it to - * define \p repeat_iterator, a fancy iterator which repeats elements from another range a given number of time: - * - * \code - * #include - * - * // derive repeat_iterator from iterator_adaptor - * template - * class repeat_iterator - * : public thrust::iterator_adaptor< - * repeat_iterator, // the first template parameter is the name of the iterator we're creating - * Iterator // the second template parameter is the name of the iterator we're adapting - * // we can use the default for the additional template parameters - * > - * { - * public: - * // shorthand for the name of the iterator_adaptor we're deriving from - * typedef thrust::iterator_adaptor< - * repeat_iterator, - * Iterator - * > super_t; - * - * __host__ __device__ - * repeat_iterator(const Iterator &x, int n) : super_t(x), begin(x), n(n) {} - * - * // befriend thrust::iterator_core_access to allow it access to the private interface below - * friend class thrust::iterator_core_access; - * - * private: - * // repeat each element of the adapted range n times - * unsigned int n; - * - * // used to keep track of where we began - * const Iterator begin; - * - * // it is private because only thrust::iterator_core_access needs access to it - * __host__ __device__ - * typename super_t::reference dereference() const - * { - * return *(begin + (this->base() - begin) / n); - * } - * }; - * \endcode - * - * Except for the first two, \p iterator_adaptor's template parameters are optional. When omitted, or when the - * user specifies \p thrust::use_default in its place, \p iterator_adaptor will use a default type inferred from \p Base. - * - * \p iterator_adaptor's functionality is derived from and generally equivalent to \p boost::iterator_adaptor. - * The exception is Thrust's addition of the template parameter \p System, which is necessary to allow Thrust - * to dispatch an algorithm to one of several parallel backend systems. - * - * \p iterator_adaptor is a powerful tool for creating custom iterators directly. However, the large set of iterator semantics which must be satisfied - * for algorithm compatibility can make \p iterator_adaptor difficult to use correctly. Unless you require the full expressivity of \p iterator_adaptor, - * consider building a custom iterator through composition of existing higher-level fancy iterators instead. - * - * Interested users may refer to boost::iterator_adaptor's documentation for further usage examples. - */ -template - class iterator_adaptor: - public detail::iterator_adaptor_base< - Derived, Base, Value, System, Traversal, Reference, Difference - >::type -{ - /*! \cond - */ - - friend class thrust::iterator_core_access; - - protected: - typedef typename detail::iterator_adaptor_base< - Derived, Base, Value, System, Traversal, Reference, Difference - >::type super_t; - - /*! \endcond - */ - - public: - /*! \p iterator_adaptor's default constructor does nothing. - */ - __host__ __device__ - iterator_adaptor(){} - - /*! This constructor copies from a given instance of the \p Base iterator. - */ - __host__ __device__ - explicit iterator_adaptor(Base const& iter) - : m_iterator(iter) - {} - - /*! The type of iterator this \p iterator_adaptor's \p adapts. - */ - typedef Base base_type; - - /*! \cond - */ - typedef typename super_t::reference reference; - - typedef typename super_t::difference_type difference_type; - /*! \endcond - */ - - /*! \return A \p const reference to the \p Base iterator this \p iterator_adaptor adapts. - */ - __host__ __device__ - Base const& base() const - { return m_iterator; } - - protected: - /*! \return A \p const reference to the \p Base iterator this \p iterator_adaptor adapts. - */ - __host__ __device__ - Base const& base_reference() const - { return m_iterator; } - - /*! \return A mutable reference to the \p Base iterator this \p iterator_adaptor adapts. - */ - __host__ __device__ - Base& base_reference() - { return m_iterator; } - - /*! \cond - */ - private: // Core iterator interface for iterator_facade - - __thrust_hd_warning_disable__ - __host__ __device__ - typename iterator_adaptor::reference dereference() const - { return *m_iterator; } - - __thrust_hd_warning_disable__ - template - __host__ __device__ - bool equal(iterator_adaptor const& x) const - { return m_iterator == x.base(); } - - __thrust_hd_warning_disable__ - __host__ __device__ - void advance(typename iterator_adaptor::difference_type n) - { - // XXX statically assert on random_access_traversal_tag - m_iterator += n; - } - - __thrust_hd_warning_disable__ - __host__ __device__ - void increment() - { ++m_iterator; } - - __thrust_hd_warning_disable__ - __host__ __device__ - void decrement() - { - // XXX statically assert on bidirectional_traversal_tag - --m_iterator; - } - - __thrust_hd_warning_disable__ - template - __host__ __device__ - typename iterator_adaptor::difference_type distance_to(iterator_adaptor const& y) const - { return y.base() - m_iterator; } - - private: - Base m_iterator; - - /*! \endcond - */ -}; // end iterator_adaptor - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - diff --git a/compat/thrust/iterator/iterator_categories.h b/compat/thrust/iterator/iterator_categories.h deleted file mode 100644 index 81601b4..0000000 --- a/compat/thrust/iterator/iterator_categories.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/iterator_categories.h - * \brief Types for reasoning about the categories of iterators - */ - -/* - * (C) Copyright Jeremy Siek 2002. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - - -#pragma once - -#include - -// #include this for stl's iterator tags -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \addtogroup iterator_tags Iterator Tags - * \ingroup iterators - * \addtogroup iterator_tag_classes Iterator Tag Classes - * \ingroup iterator_tags - * \{ - */ - -/*! \p input_device_iterator_tag is an empty class: it has no member functions, - * member variables, or nested types. It is used solely as a "tag": a - * representation of the Input Device Iterator concept within the C++ type - * system. - * - * \see http://www.sgi.com/tech/sgi/input_iterator_tag.html, iterator_traits, - * output_device_iterator_tag, forward_device_iterator_tag, - * bidirectional_device_iterator_tag, random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -struct input_device_iterator_tag {}; - -/*! \p output_device_iterator_tag is an empty class: it has no member functions, - * member variables, or nested types. It is used solely as a "tag": a - * representation of the Output Device Iterator concept within the C++ type - * system. - * - * \see http://www.sgi.com/tech/sgi/output_iterator_tag.html, iterator_traits, - * input_device_iterator_tag, forward_device_iterator_tag, - * bidirectional_device_iterator_tag, random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -struct output_device_iterator_tag {}; - -/*! \p forward_device_iterator_tag is an empty class: it has no member functions, - * member variables, or nested types. It is used solely as a "tag": a - * representation of the Forward Device Iterator concept within the C++ type - * system. - * - * \see http://www.sgi.com/tech/sgi/forward_iterator_tag.html, iterator_traits, - * input_device_iterator_tag, output_device_iterator_tag, - * bidirectional_device_iterator_tag, random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -struct forward_device_iterator_tag : public input_device_iterator_tag {}; - -/*! \p bidirectional_device_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Bidirectional Device Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/bidirectional_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -struct bidirectional_device_iterator_tag : public forward_device_iterator_tag {}; - -/*! \p random_access_device_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Random Access Device Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/random_access_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, bidirectional_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -struct random_access_device_iterator_tag : public bidirectional_device_iterator_tag {}; - -/*! \p input_host_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Input Host Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/input_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, bidirectional_device_iterator_tag, - * random_access_device_iterator_tag, - * output_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -typedef std::input_iterator_tag input_host_iterator_tag; - -/*! \p output_host_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Output Host Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/output_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, bidirectional_device_iterator_tag, - * random_access_device_iterator_tag, - * input_host_iterator_tag, forward_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -typedef std::output_iterator_tag output_host_iterator_tag; - -/*! \p forward_host_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Forward Host Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/forward_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, bidirectional_device_iterator_tag, - * random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, - * bidirectional_host_iterator_tag, random_access_host_iterator_tag - */ -typedef std::forward_iterator_tag forward_host_iterator_tag; - -/*! \p bidirectional_host_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Forward Host Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/bidirectional_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, bidirectional_device_iterator_tag, - * random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, - * forward_host_iterator_tag, random_access_host_iterator_tag - */ -typedef std::bidirectional_iterator_tag bidirectional_host_iterator_tag; - -/*! \p random_access_host_iterator_tag is an empty class: it has no member - * functions, member variables, or nested types. It is used solely as a "tag": a - * representation of the Forward Host Iterator concept within the C++ - * type system. - * - * \see http://www.sgi.com/tech/sgi/random_access_iterator_tag.html, - * iterator_traits, input_device_iterator_tag, output_device_iterator_tag, - * forward_device_iterator_tag, bidirectional_device_iterator_tag, - * random_access_device_iterator_tag, - * input_host_iterator_tag, output_host_iterator_tag, - * forward_host_iterator_tag, bidirectional_host_iterator_tag - */ -typedef std::random_access_iterator_tag random_access_host_iterator_tag; - -/*! \} // end iterator_tag_classes - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/iterator/iterator_facade.h b/compat/thrust/iterator/iterator_facade.h deleted file mode 100644 index 232c150..0000000 --- a/compat/thrust/iterator/iterator_facade.h +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/iterator/iterator_facade.h - * \brief A class which exposes a public interface for iterators - */ - -/* - * (C) Copyright David Abrahams 2002. - * (C) Copyright Jeremy Siek 2002. - * (C) Copyright Thomas Witt 2002. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - - -// This forward declaration is required for the friend declaration -// in iterator_core_access -template class iterator_facade; - - -/*! \p iterator_core_access is the class which user iterator types derived from \p thrust::iterator_adaptor - * or \p thrust::iterator_facade must befriend to allow it to access their private interface. - */ -class iterator_core_access -{ - /*! \cond - */ - - // declare our friends - template friend class iterator_facade; - - // iterator comparisons are our friends - template - inline __host__ __device__ - friend bool - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - inline __host__ __device__ - friend bool - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - inline __host__ __device__ - friend bool - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - inline __host__ __device__ - friend bool - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - inline __host__ __device__ - friend bool - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - inline __host__ __device__ - friend bool - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - // iterator difference is our friend - template - inline __host__ __device__ - friend - typename thrust::detail::distance_from_result< - iterator_facade, - iterator_facade - >::type - operator-(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - __host__ __device__ - static typename Facade::reference dereference(Facade const& f) - { - return f.dereference(); - } - - template - __host__ __device__ - static void increment(Facade& f) - { - f.increment(); - } - - template - __host__ __device__ - static void decrement(Facade& f) - { - f.decrement(); - } - - template - __host__ __device__ - static bool equal(Facade1 const& f1, Facade2 const& f2) - { - return f1.equal(f2); - } - - // XXX TODO: Investigate whether we need both of these cases - //template - //__host__ __device__ - //static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::true_) - //{ - // return f1.equal(f2); - //} - - //template - //__host__ __device__ - //static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::false_) - //{ - // return f2.equal(f1); - //} - - template - __host__ __device__ - static void advance(Facade& f, typename Facade::difference_type n) - { - f.advance(n); - } - - // Facade2 is convertible to Facade1, - // so return Facade1's difference_type - template - __host__ __device__ - static typename Facade1::difference_type - distance_from(Facade1 const& f1, Facade2 const& f2, thrust::detail::true_type) - { - return -f1.distance_to(f2); - } - - // Facade2 is not convertible to Facade1, - // so return Facade2's difference_type - template - __host__ __device__ - static typename Facade2::difference_type - distance_from(Facade1 const& f1, Facade2 const& f2, thrust::detail::false_type) - { - return f2.distance_to(f1); - } - - template - __host__ __device__ - static typename thrust::detail::distance_from_result::type - distance_from(Facade1 const& f1, Facade2 const& f2) - { - // dispatch the implementation of this method upon whether or not - // Facade2 is convertible to Facade1 - return distance_from(f1, f2, - typename thrust::detail::is_convertible::type()); - } - - // - // Curiously Recurring Template interface. - // - template - __host__ __device__ - static Derived& derived(iterator_facade& facade) - { - return *static_cast(&facade); - } - - template - __host__ __device__ - static Derived const& derived(iterator_facade const& facade) - { - return *static_cast(&facade); - } - - /*! \endcond - */ -}; // end iterator_core_access - - -/*! \p iterator_facade is a template which allows the programmer to define a novel iterator with a standards-conforming interface - * which Thrust can use to reason about algorithm acceleration opportunities. - * - * Because most of a standard iterator's interface is defined in terms of a small set of core primitives, \p iterator_facade - * defines the non-primitive portion mechanically. In principle a novel iterator could explicitly provide the entire interface in - * an ad hoc fashion but doing so might be tedious and prone to subtle errors. - * - * Often \p iterator_facade is too primitive a tool to use for defining novel iterators. In these cases, \p iterator_adaptor - * or a specific fancy iterator should be used instead. - * - * \p iterator_facade's functionality is derived from and generally equivalent to \p boost::iterator_facade. - * The exception is Thrust's addition of the template parameter \p System, which is necessary to allow Thrust - * to dispatch an algorithm to one of several parallel backend systems. An additional exception is Thrust's omission - * of the \c operator-> member function. - * - * Interested users may refer to boost::iterator_facade's documentation for usage examples. - * - * \note \p iterator_facade's arithmetic operator free functions exist with the usual meanings but are omitted here for brevity. - */ -template - class iterator_facade -{ - private: - /*! \cond - */ - - // - // Curiously Recurring Template interface. - // - __host__ __device__ - Derived& derived() - { - return *static_cast(this); - } - - __host__ __device__ - Derived const& derived() const - { - return *static_cast(this); - } - /*! \endcond - */ - - public: - /*! The type of element pointed to by \p iterator_facade. - */ - typedef typename thrust::detail::remove_const::type value_type; - - /*! The return type of \p iterator_facade::operator*(). - */ - typedef Reference reference; - - /*! The return type of \p iterator_facade's non-existent \c operator->() - * member function. Unlike \c boost::iterator_facade, \p iterator_facade - * disallows access to the \p value_type's members through expressions of the - * form iter->member. \p pointer is defined to \c void to indicate - * that these expressions are not allowed. This limitation may be relaxed in a - * future version of Thrust. - */ - typedef void pointer; - - /*! The type of expressions of the form x - y where x and y - * are of type \p iterator_facade. - */ - typedef Difference difference_type; - - /*! The type of iterator category of \p iterator_facade. - */ - typedef typename thrust::detail::iterator_facade_category< - System, Traversal, Value, Reference - >::type iterator_category; - - /*! \p operator*() dereferences this \p iterator_facade. - * \return A reference to the element pointed to by this \p iterator_facade. - */ - __host__ __device__ - reference operator*() const - { - return iterator_core_access::dereference(this->derived()); - } - - // XXX unimplemented for now, consider implementing it later - //pointer operator->() const - //{ - // return; - //} - - // XXX investigate whether or not we need to go to the lengths - // boost does to determine the return type - - /*! \p operator[] performs indexed dereference. - * \return A reference to the element \p n distance away from this \p iterator_facade. - */ - __host__ __device__ - reference operator[](difference_type n) const - { - return *(this->derived() + n); - } - - /*! \p operator++ pre-increments this \p iterator_facade to refer to the element in the next position. - * \return *this - */ - __host__ __device__ - Derived& operator++() - { - iterator_core_access::increment(this->derived()); - return this->derived(); - } - - /*! \p operator++ post-increments this \p iterator_facade and returns a new \p iterator_facade referring to the element in the next position. - * \return A copy of *this before increment. - */ - __host__ __device__ - Derived operator++(int) - { - Derived tmp(this->derived()); - ++*this; - return tmp; - } - - /*! \p operator-- pre-decrements this \p iterator_facade to refer to the element in the previous position. - * \return *this - */ - __host__ __device__ - Derived& operator--() - { - iterator_core_access::decrement(this->derived()); - return this->derived(); - } - - /*! \p operator-- post-decrements this \p iterator_facade and returns a new \p iterator_facade referring to the element in the previous position. - * \return A copy of *this before decrement. - */ - __host__ __device__ - Derived operator--(int) - { - Derived tmp(this->derived()); - --*this; - return tmp; - } - - /*! \p operator+= increments this \p iterator_facade to refer to an element a given distance after its current position. - * \param n The quantity to increment. - * \return *this - */ - __host__ __device__ - Derived& operator+=(difference_type n) - { - iterator_core_access::advance(this->derived(), n); - return this->derived(); - } - - /*! \p operator-= decrements this \p iterator_facade to refer to an element a given distance before its current postition. - * \param n The quantity to decrement. - * \return *this - */ - __host__ __device__ - Derived& operator-=(difference_type n) - { - iterator_core_access::advance(this->derived(), -n); - return this->derived(); - } - - /*! \p operator- subtracts a given quantity from this \p iterator_facade and returns a new \p iterator_facade referring to the element at the given position before this \p iterator_facade. - * \param n The quantity to decrement - * \return An \p iterator_facade pointing \p n elements before this \p iterator_facade. - */ - __host__ __device__ - Derived operator-(difference_type n) const - { - Derived result(this->derived()); - return result -= n; - } -}; // end iterator_facade - -/*! \cond - */ - -// Comparison operators -template -inline __host__ __device__ -// XXX it might be nice to implement this at some point -//typename enable_if_interoperable::type // exposition -bool -operator ==(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return iterator_core_access - ::equal(*static_cast(&lhs), - *static_cast(&rhs)); -} - -template -inline __host__ __device__ -// XXX it might be nice to implement this at some point -//typename enable_if_interoperable::type // exposition -bool -operator !=(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return !iterator_core_access - ::equal(*static_cast(&lhs), - *static_cast(&rhs)); -} - -template -inline __host__ __device__ -// XXX it might be nice to implement this at some point -//typename enable_if_interoperable::type // exposition -bool -operator <(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return 0 > iterator_core_access - ::distance_from(*static_cast(&lhs), - *static_cast(&rhs)); -} - -template -inline __host__ __device__ -// XXX it might be nice to implement this at some point -//typename enable_if_interoperable::type // exposition -bool -operator >(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return 0 < iterator_core_access - ::distance_from(*static_cast(&lhs), - *static_cast(&rhs)); -} - -template -inline __host__ __device__ -// XXX it might be nice to implement this at some point -//typename enable_if_interoperable::type // exposition -bool -operator <=(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return 0 >= iterator_core_access - ::distance_from(*static_cast(&lhs), - *static_cast(&rhs)); -} - -template -inline __host__ __device__ -// XXX it might be nice to implement this at some point -//typename enable_if_interoperable::type // exposition -bool -operator >=(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return 0 <= iterator_core_access - ::distance_from(*static_cast(&lhs), - *static_cast(&rhs)); -} - -// Iterator difference -template -inline __host__ __device__ - -// divine the type this operator returns -typename thrust::detail::distance_from_result< - iterator_facade, - iterator_facade ->::type - -operator-(iterator_facade const& lhs, - iterator_facade const& rhs) -{ - return iterator_core_access - ::distance_from(*static_cast(&lhs), - *static_cast(&rhs)); -} - -// Iterator addition -template -inline __host__ __device__ -Derived operator+ (iterator_facade const& i, - typename Derived::difference_type n) -{ - Derived tmp(static_cast(i)); - return tmp += n; -} - -template -inline __host__ __device__ -Derived operator+ (typename Derived::difference_type n, - iterator_facade const& i) -{ - Derived tmp(static_cast(i)); - return tmp += n; -} - -/*! \endcond - */ - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - diff --git a/compat/thrust/iterator/iterator_traits.h b/compat/thrust/iterator/iterator_traits.h deleted file mode 100644 index a16f219..0000000 --- a/compat/thrust/iterator/iterator_traits.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/iterator_traits.h - * \brief Traits and metafunctions for reasoning about the traits of iterators - */ - -/* - * (C) Copyright David Abrahams 2003. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -/*! \p iterator_traits is a type trait class that provides a uniform - * interface for querying the properties of iterators at compile-time. - */ -template - struct iterator_traits - : public std::iterator_traits -{ -}; // end iterator_traits - - -template struct iterator_value; - -template struct iterator_pointer; - -template struct iterator_reference; - -template struct iterator_difference; - -template struct iterator_traversal; - -template struct iterator_system; - -// TODO remove this in Thrust v1.7.0 -template - struct THRUST_DEPRECATED iterator_space -{ - typedef THRUST_DEPRECATED typename iterator_system::type type; -}; - - -} // end thrust - -#include -#include -#include -#include -#include - diff --git a/compat/thrust/iterator/permutation_iterator.h b/compat/thrust/iterator/permutation_iterator.h deleted file mode 100644 index 509097b..0000000 --- a/compat/thrust/iterator/permutation_iterator.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/iterator/permutation_iterator.h - * \brief An iterator which performs a gather or scatter operation when dereferenced - */ - -/* - * (C) Copyright Toon Knapen 2001. - * (C) Copyright David Abrahams 2003. - * (C) Copyright Roland Richter 2003. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p permutation_iterator is an iterator which represents a pointer into a - * reordered view of a given range. \p permutation_iterator is an imprecise name; - * the reordered view need not be a strict permutation. This iterator is useful - * for fusing a scatter or gather operation with other algorithms. - * - * This iterator takes two arguments: - * - * - an iterator to the range \c V on which the "permutation" will be applied - * - the reindexing scheme that defines how the elements of \c V will be permuted. - * - * Note that \p permutation_iterator is not limited to strict permutations of the - * given range \c V. The distance between begin and end of the reindexing iterators - * is allowed to be smaller compared to the size of the range \c V, in which case - * the \p permutation_iterator only provides a "permutation" of a subrange of \c V. - * The indices neither need to be unique. In this same context, it must be noted - * that the past-the-end \p permutation_iterator is completely defined by means of - * the past-the-end iterator to the indices. - * - * The following code snippet demonstrates how to create a \p permutation_iterator - * which represents a reordering of the contents of a \p device_vector. - * - * \code - * #include - * #include - * ... - * thrust::device_vector values(4); - * values[0] = 10.0f; - * values[1] = 20.0f; - * values[2] = 30.0f; - * values[3] = 40.0f; - * values[4] = 50.0f; - * values[5] = 60.0f; - * values[6] = 70.0f; - * values[7] = 80.0f; - * - * thrust::device_vector indices(4); - * indices[0] = 2; - * indices[1] = 6; - * indices[2] = 1; - * indices[3] = 3; - * - * typedef thrust::device_vector::iterator ElementIterator; - * typedef thrust::device_vector::iterator IndexIterator; - * - * thrust::permutation_iterator iter(values.begin(), indices.begin()); - * - * *iter; // returns 30.0f; - * iter[0]; // returns 30.0f; - * iter[1]; // returns 70.0f; - * iter[2]; // returns 20.0f; - * iter[3]; // returns 40.0f; - * - * // iter[4] is an out-of-bounds error - * - * *iter = -1.0f; // sets values[2] to -1.0f; - * iter[0] = -1.0f; // sets values[2] to -1.0f; - * iter[1] = -1.0f; // sets values[6] to -1.0f; - * iter[2] = -1.0f; // sets values[1] to -1.0f; - * iter[3] = -1.0f; // sets values[3] to -1.0f; - * - * // values is now {10, -1, -1, -1, 50, 60, -1, 80} - * \endcode - * - * \see make_permutation_iterator - */ -template - class permutation_iterator - : public thrust::detail::permutation_iterator_base< - ElementIterator, - IndexIterator - >::type -{ - /*! \cond - */ - private: - typedef typename detail::permutation_iterator_base::type super_t; - - friend class thrust::iterator_core_access; - /*! \endcond - */ - - public: - /*! Null constructor calls the null constructor of this \p permutation_iterator's - * element iterator. - */ - __host__ __device__ - permutation_iterator() - : m_element_iterator() {} - - /*! Constructor accepts an \c ElementIterator into a range of values and an - * \c IndexIterator into a range of indices defining the indexing scheme on the - * values. - * - * \param x An \c ElementIterator pointing this \p permutation_iterator's range of values. - * \param y An \c IndexIterator pointing to an indexing scheme to use on \p x. - */ - __host__ __device__ - explicit permutation_iterator(ElementIterator x, IndexIterator y) - : super_t(y), m_element_iterator(x) {} - - /*! Copy constructor accepts a related \p permutation_iterator. - * \param r A compatible \p permutation_iterator to copy from. - */ - template - __host__ __device__ - permutation_iterator(permutation_iterator const &r - // XXX remove these guards when we have static_assert - , typename detail::enable_if_convertible::type* = 0 - , typename detail::enable_if_convertible::type* = 0 - ) - : super_t(r.base()), m_element_iterator(r.m_element_iterator) - {} - - /*! \cond - */ - private: - __thrust_hd_warning_disable__ - __host__ __device__ - typename super_t::reference dereference() const - { - return *(m_element_iterator + *this->base()); - } - - // make friends for the copy constructor - template friend class permutation_iterator; - - ElementIterator m_element_iterator; - /*! \endcond - */ -}; // end permutation_iterator - - -/*! \p make_permutation_iterator creates a \p permutation_iterator - * from an \c ElementIterator pointing to a range of elements to "permute" - * and an \c IndexIterator pointing to a range of indices defining an indexing - * scheme on the values. - * - * \param e An \c ElementIterator pointing to a range of values. - * \param i An \c IndexIterator pointing to an indexing scheme to use on \p e. - * \return A new \p permutation_iterator which permutes the range \p e by \p i. - * \see permutation_iterator - */ -template -__host__ __device__ -permutation_iterator make_permutation_iterator(ElementIterator e, IndexIterator i) -{ - return permutation_iterator(e,i); -} - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - diff --git a/compat/thrust/iterator/retag.h b/compat/thrust/iterator/retag.h deleted file mode 100644 index 660da8f..0000000 --- a/compat/thrust/iterator/retag.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/iterator/retag.h - * \brief Functionality for altering an iterator's associated system. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \ingroup iterator_tags - * \{ - */ - -#if 0 -/*! \p reinterpret_tag returns a copy of an iterator and changes the type of the result's system tag. - * \tparam Tag Any system tag. - * \tparam Iterator Any iterator type. - * \param iter The iterator of interest. - * \return An iterator of unspecified type whose system tag is \p Tag and whose behavior is otherwise - * equivalent to \p iter. - * \note Unlike \p retag, \p reinterpret_tag does not enforce that the converted-to system tag be - * related to the converted-from system tag. - * \see retag - */ -template -unspecified_iterator_type reinterpret_tag(Iterator iter); - -/*! \p retag returns a copy of an iterator and changes the type of the result's system tag. - * \tparam Tag \p Tag shall be convertible to thrust::iterator_system::type, - * or thrust::iterator_system::type is a base type of \p Tag. - * \tparam Iterator Any iterator type. - * \param iter The iterator of interest. - * \return An iterator of unspecified type whose system tag is \p Tag and whose behavior is - * otherwise equivalent to \p iter. - * \note Unlike \p reinterpret_tag, \p retag enforces that the converted-to system tag be - * related to the converted-from system tag. - * \see reinterpret_tag - */ -template -unspecified_iterator_type retag(Iterator iter); -#endif - -/*! \} // iterator_tags - */ - - -} // end thrust - diff --git a/compat/thrust/iterator/reverse_iterator.h b/compat/thrust/iterator/reverse_iterator.h deleted file mode 100644 index 03f0339..0000000 --- a/compat/thrust/iterator/reverse_iterator.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/reverse_iterator.h - * \brief An iterator adaptor which adapts another iterator to traverse backwards - */ - -/* - * (C) Copyright David Abrahams 2002. - * (C) Copyright Jeremy Siek 2002. - * (C) Copyright Thomas Witt 2002. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p reverse_iterator is an iterator which represents a pointer into a - * reversed view of a given range. In this way, \p reverse_iterator allows - * backwards iteration through a bidirectional input range. - * - * It is important to note that although \p reverse_iterator is constructed - * from a given iterator, it points to the element preceding it. In this way, - * the past-the-end \p reverse_iterator of a given range points to the element - * preceding the first element of the input range. By the same token, the first - * \p reverse_iterator of a given range is constructed from a past-the-end iterator - * of the original range yet points to the last element of the input. - * - * The following code snippet demonstrates how to create a \p reverse_iterator - * which represents a reversed view of the contents of a \p device_vector. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(4); - * v[0] = 0.0f; - * v[1] = 1.0f; - * v[2] = 2.0f; - * v[3] = 3.0f; - * - * typedef thrust::device_vector::iterator Iterator; - * - * // note that we point the iterator to the *end* of the device_vector - * thrust::reverse_iterator iter(values.end()); - * - * *iter; // returns 3.0f; - * iter[0]; // returns 3.0f; - * iter[1]; // returns 2.0f; - * iter[2]; // returns 1.0f; - * iter[3]; // returns 0.0f; - * - * // iter[4] is an out-of-bounds error - * \endcode - * - * Since reversing a range is a common operation, containers like \p device_vector - * have nested typedefs for declaration shorthand and methods for constructing - * reverse_iterators. The following code snippet is equivalent to the previous: - * - * \code - * #include - * ... - * thrust::device_vector v(4); - * v[0] = 0.0f; - * v[1] = 1.0f; - * v[2] = 2.0f; - * v[3] = 3.0f; - * - * // we use the nested type reverse_iterator to refer to a reversed view of - * // a device_vector and the method rbegin() to create a reverse_iterator pointing - * // to the beginning of the reversed device_vector - * thrust::device_iterator::reverse_iterator iter = values.rbegin(); - * - * *iter; // returns 3.0f; - * iter[0]; // returns 3.0f; - * iter[1]; // returns 2.0f; - * iter[2]; // returns 1.0f; - * iter[3]; // returns 0.0f; - * - * // iter[4] is an out-of-bounds error - * - * // similarly, rend() points to the end of the reversed sequence: - * assert(values.rend() == (iter + 4)); - * \endcode - * - * Finally, the following code snippet demonstrates how to use reverse_iterator to - * perform a reversed prefix sum operation on the contents of a device_vector: - * - * \code - * #include - * #include - * ... - * thrust::device_vector v(5); - * v[0] = 0; - * v[1] = 1; - * v[2] = 2; - * v[3] = 3; - * v[4] = 4; - * - * thrust::device_vector result(5); - * - * // exclusive scan v into result in reverse - * thrust::exclusive_scan(v.rbegin(), v.rend(), result.begin()); - * - * // result is now {0, 4, 7, 9, 10} - * \endcode - * - * \see make_reverse_iterator - */ -template - class reverse_iterator - : public detail::reverse_iterator_base::type -{ - /*! \cond - */ - private: - typedef typename thrust::detail::reverse_iterator_base< - BidirectionalIterator - >::type super_t; - - friend class thrust::iterator_core_access; - /*! \endcond - */ - - public: - /*! Default constructor does nothing. - */ - __host__ __device__ - reverse_iterator(void) {} - - /*! \p Constructor accepts a \c BidirectionalIterator pointing to a range - * for this \p reverse_iterator to reverse. - * - * \param x A \c BidirectionalIterator pointing to a range to reverse. - */ - __host__ __device__ - explicit reverse_iterator(BidirectionalIterator x); - - /*! \p Copy constructor allows construction from a related compatible - * \p reverse_iterator. - * - * \param r A \p reverse_iterator to copy from. - */ - template - __host__ __device__ - reverse_iterator(reverse_iterator const &r -// XXX msvc screws this up -// XXX remove these guards when we have static_assert -#ifndef _MSC_VER - , typename thrust::detail::enable_if< - thrust::detail::is_convertible< - OtherBidirectionalIterator, - BidirectionalIterator - >::value - >::type * = 0 -#endif // _MSC_VER - ); - - /*! \cond - */ - private: - __thrust_hd_warning_disable__ - __host__ __device__ - typename super_t::reference dereference(void) const; - - __host__ __device__ - void increment(void); - - __host__ __device__ - void decrement(void); - - __host__ __device__ - void advance(typename super_t::difference_type n); - - template - __host__ __device__ - typename super_t::difference_type - distance_to(reverse_iterator const &y) const; - /*! \endcond - */ -}; // end reverse_iterator - - -/*! \p make_reverse_iterator creates a \p reverse_iterator - * from a \c BidirectionalIterator pointing to a range of elements to reverse. - * - * \param x A \c BidirectionalIterator pointing to a range to reverse. - * \return A new \p reverse_iterator which reverses the range \p x. - */ -template -__host__ __device__ -reverse_iterator make_reverse_iterator(BidirectionalIterator x); - - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - -#include - diff --git a/compat/thrust/iterator/transform_iterator.h b/compat/thrust/iterator/transform_iterator.h deleted file mode 100644 index 985b61b..0000000 --- a/compat/thrust/iterator/transform_iterator.h +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/transform_iterator.h - * \brief An iterator which adapts another iterator by applying a function to the result of its dereference - */ - -/* - * (C) Copyright David Abrahams 2002. - * (C) Copyright Jeremy Siek 2002. - * (C) Copyright Thomas Witt 2002. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include - -// #include the details first -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p transform_iterator is an iterator which represents a pointer into a range - * of values after transformation by a function. This iterator is useful for - * creating a range filled with the result of applying an operation to another range - * without either explicitly storing it in memory, or explicitly executing the transformation. - * Using \p transform_iterator facilitates kernel fusion by deferring the execution - * of a transformation until the value is needed while saving both memory capacity - * and bandwidth. - * - * The following code snippet demonstrates how to create a \p transform_iterator - * which represents the result of \c sqrtf applied to the contents of a \p device_vector. - * - * \code - * #include - * #include - * - * // note: functor inherits from unary_function - * struct square_root : public thrust::unary_function - * { - * __host__ __device__ - * float operator()(float x) const - * { - * return sqrtf(x); - * } - * }; - * - * int main(void) - * { - * thrust::device_vector v(4); - * v[0] = 1.0f; - * v[1] = 4.0f; - * v[2] = 9.0f; - * v[3] = 16.0f; - * - * typedef thrust::device_vector::iterator FloatIterator; - * - * thrust::transform_iterator iter(v.begin(), square_root()); - * - * *iter; // returns 1.0f - * iter[0]; // returns 1.0f; - * iter[1]; // returns 2.0f; - * iter[2]; // returns 3.0f; - * iter[3]; // returns 4.0f; - * - * // iter[4] is an out-of-bounds error - * } - * \endcode - * - * This next example demonstrates how to use a \p transform_iterator with the - * \p thrust::reduce function to compute the sum of squares of a sequence. - * We will create temporary \p transform_iterators with the - * \p make_transform_iterator function in order to avoid explicitly specifying their type: - * - * \code - * #include - * #include - * #include - * #include - * - * // note: functor inherits from unary_function - * struct square : public thrust::unary_function - * { - * __host__ __device__ - * float operator()(float x) const - * { - * return x * x; - * } - * }; - * - * int main(void) - * { - * // initialize a device array - * thrust::device_vector v(4); - * v[0] = 1.0f; - * v[1] = 2.0f; - * v[2] = 3.0f; - * v[3] = 4.0f; - * - * float sum_of_squares = - * thrust::reduce(thrust::make_transform_iterator(v.begin(), square()), - * thrust::make_transform_iterator(v.end(), square())); - * - * std::cout << "sum of squares: " << sum_of_squares << std::endl; - * return 0; - * } - * \endcode - * - * Note that in the previous two examples the transform functor (namely \c square_root - * and \c square) inherits from \c thrust::unary_function. Inheriting from - * \c thrust::unary_function ensures that a functor is a valid \c AdaptableUnaryFunction - * and provides all the necessary \c typedef declarations. The \p transform_iterator - * can also be applied to a \c UnaryFunction that does not inherit from - * \c thrust::unary_function using an optional template argument. The following example - * illustrates how to use the third template argument to specify the \c result_type of - * the function. - * - * \code - * #include - * #include - * - * // note: functor *does not* inherit from unary_function - * struct square_root - * { - * __host__ __device__ - * float operator()(float x) const - * { - * return sqrtf(x); - * } - * }; - * - * int main(void) - * { - * thrust::device_vector v(4); - * v[0] = 1.0f; - * v[1] = 4.0f; - * v[2] = 9.0f; - * v[3] = 16.0f; - * - * typedef thrust::device_vector::iterator FloatIterator; - * - * // note: float result_type is specified explicitly - * thrust::transform_iterator iter(v.begin(), square_root()); - * - * *iter; // returns 1.0f - * iter[0]; // returns 1.0f; - * iter[1]; // returns 2.0f; - * iter[2]; // returns 3.0f; - * iter[3]; // returns 4.0f; - * - * // iter[4] is an out-of-bounds error - * } - * \endcode - * - * \see make_transform_iterator - */ -template - class transform_iterator - : public detail::transform_iterator_base::type -{ - /*! \cond - */ - public: - typedef typename - detail::transform_iterator_base::type - super_t; - - friend class thrust::iterator_core_access; - /*! \endcond - */ - - public: - /*! Null constructor does nothing. - */ - __host__ __device__ - transform_iterator() {} - - /*! This constructor takes as arguments an \c Iterator and an \c AdaptableUnaryFunction - * and copies them to a new \p transform_iterator. - * - * \param x An \c Iterator pointing to the input to this \p transform_iterator's \c AdaptableUnaryFunction. - * \param f An \c AdaptableUnaryFunction used to transform the objects pointed to by \p x. - */ - __host__ __device__ - transform_iterator(Iterator const& x, AdaptableUnaryFunction f) - : super_t(x), m_f(f) { - } - - /*! This explicit constructor copies the value of a given \c Iterator and creates - * this \p transform_iterator's \c AdaptableUnaryFunction using its null constructor. - * - * \param x An \c Iterator to copy. - */ - __host__ __device__ - explicit transform_iterator(Iterator const& x) - : super_t(x) { } - - /*! This copy constructor creates a new \p transform_iterator from another - * \p transform_iterator. - * - * \param other The \p transform_iterator to copy. - */ - template - __host__ __device__ - transform_iterator(const transform_iterator &other, - typename thrust::detail::enable_if_convertible::type* = 0, - typename thrust::detail::enable_if_convertible::type* = 0) - : super_t(other.base()), m_f(other.functor()) {} - - /*! Copy assignment operator copies from another \p transform_iterator. - * \p other The other \p transform_iterator to copy - * \return *this - * - * \note If the type of this \p transform_iterator's functor is not copy assignable - * (for example, if it is a lambda) it is not an error to call this function. - * In this case, however, the functor will not be modified. - * - * In any case, this \p transform_iterator's underlying iterator will be copy assigned. - */ - __host__ __device__ - transform_iterator &operator=(const transform_iterator &other) - { - return do_assign(other, - // XXX gcc 4.2.1 crashes on is_copy_assignable; just assume the functor is assignable as a WAR -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC) && (THRUST_GCC_VERSION <= 40201) - thrust::detail::true_type() -#else - typename thrust::detail::is_copy_assignable::type() -#endif // THRUST_HOST_COMPILER - ); - } - - /*! This method returns a copy of this \p transform_iterator's \c AdaptableUnaryFunction. - * \return A copy of this \p transform_iterator's \c AdaptableUnaryFunction. - */ - __host__ __device__ - AdaptableUnaryFunction functor() const - { return m_f; } - - /*! \cond - */ - private: - __host__ __device__ - transform_iterator &do_assign(const transform_iterator &other, thrust::detail::true_type) - { - super_t::operator=(other); - - // do assign to m_f - m_f = other.functor(); - - return *this; - } - - __host__ __device__ - transform_iterator &do_assign(const transform_iterator &other, thrust::detail::false_type) - { - super_t::operator=(other); - - // don't assign to m_f - - return *this; - } - - __thrust_hd_warning_disable__ - __host__ __device__ - typename super_t::reference dereference() const - { - // XXX consider making this a member instead of a temporary created inside dereference - thrust::detail::host_device_function wrapped_f(m_f); - - return wrapped_f(*this->base()); - } - - // tag this as mutable per Dave Abrahams in this thread: - // http://lists.boost.org/Archives/boost/2004/05/65332.php - mutable AdaptableUnaryFunction m_f; - - /*! \endcond - */ -}; // end transform_iterator - - -/*! \p make_transform_iterator creates a \p transform_iterator - * from an \c Iterator and \c AdaptableUnaryFunction. - * - * \param it The \c Iterator pointing to the input range of the - * newly created \p transform_iterator. - * \param fun The \c AdaptableUnaryFunction used to transform the range pointed - * to by \p it in the newly created \p transform_iterator. - * \return A new \p transform_iterator which transforms the range at - * \p it by \p fun. - * \see transform_iterator - */ -template -inline __host__ __device__ -transform_iterator -make_transform_iterator(Iterator it, AdaptableUnaryFunction fun) -{ - return transform_iterator(it, fun); -} // end make_transform_iterator - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - diff --git a/compat/thrust/iterator/zip_iterator.h b/compat/thrust/iterator/zip_iterator.h deleted file mode 100644 index 8e7299c..0000000 --- a/compat/thrust/iterator/zip_iterator.h +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/iterator/zip_iterator.h - * \brief An iterator which returns a tuple of the result of dereferencing - * a tuple of iterators when dereferenced - */ - -/* - * Copyright David Abrahams and Thomas Becker 2000-2006. - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup iterators - * \{ - */ - -/*! \addtogroup fancyiterator Fancy Iterators - * \ingroup iterators - * \{ - */ - -/*! \p zip_iterator is an iterator which represents a pointer into a range - * of \p tuples whose elements are themselves taken from a \p tuple of input - * iterators. This iterator is useful for creating a virtual array of structures - * while achieving the same performance and bandwidth as the structure of arrays - * idiom. \p zip_iterator also facilitates kernel fusion by providing a convenient - * means of amortizing the execution of the same operation over multiple ranges. - * - * The following code snippet demonstrates how to create a \p zip_iterator - * which represents the result of "zipping" multiple ranges together. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector int_v(3); - * int_v[0] = 0; int_v[1] = 1; int_v[2] = 2; - * - * thrust::device_vector float_v(3); - * float_v[0] = 0.0f; float_v[1] = 1.0;f float_v[2] = 2.0f; - * - * thrust::device_vector char_v(3); - * char_v[0] = 'a'; char_v[1] = 'b'; char_v[2] = 'c'; - * - * // typedef these iterators for shorthand - * typedef thrust::device_vector::iterator IntIterator; - * typedef thrust::device_vector::iterator FloatIterator; - * typedef thrust::device_vector::iterator CharIterator; - * - * // typedef a tuple of these iterators - * typedef thrust::tuple IteratorTuple; - * - * // typedef the zip_iterator of this tuple - * typedef thrust::zip_iterator ZipIterator; - * - * // finally, create the zip_iterator - * ZipIterator iter(thrust::make_tuple(int_v.begin(), float_v.begin(), char_v.begin())); - * - * *iter; // returns (0, 0.0f, 'a') - * iter[0]; // returns (0, 0.0f, 'a') - * iter[1]; // returns (1, 1.0f, 'b') - * iter[2]; // returns (2, 2.0f, 'c') - * - * thrust::get<0>(iter[2]); // returns 2 - * thrust::get<1>(iter[0]); // returns 0.0f - * thrust::get<2>(iter[1]); // returns 'b' - * - * // iter[3] is an out-of-bounds error - * \endcode - * - * Defining the type of a \p zip_iterator can be complex. The next code example demonstrates - * how to use the \p make_zip_iterator function with the \p make_tuple function to avoid - * explicitly specifying the type of the \p zip_iterator. This example shows how to use - * \p zip_iterator to copy multiple ranges with a single call to \p thrust::copy. - * - * \code - * #include - * #include - * #include - * - * int main(void) - * { - * thrust::device_vector int_in(3), int_out(3); - * int_in[0] = 0; - * int_in[1] = 1; - * int_in[2] = 2; - * - * thrust::device_vector float_in(3), float_out(3); - * float_in[0] = 0.0f; - * float_in[1] = 10.0f; - * float_in[2] = 20.0f; - * - * thrust::copy(thrust::make_zip_iterator(thrust::make_tuple(int_in.begin(), float_in.begin())), - * thrust::make_zip_iterator(thrust::make_tuple(int_in.end(), float_in.end())), - * thrust::make_zip_iterator(thrust::make_tuple(int_out.begin(),float_out.begin()))); - * - * // int_out is now [0, 1, 2] - * // float_out is now [0.0f, 10.0f, 20.0f] - * - * return 0; - * } - * \endcode - * - * \see make_zip_iterator - * \see make_tuple - * \see tuple - * \see get - */ -template - class zip_iterator - : public detail::zip_iterator_base::type -{ - public: - /*! Null constructor does nothing. - */ - inline __host__ __device__ - zip_iterator(void); - - /*! This constructor creates a new \p zip_iterator from a - * \p tuple of iterators. - * - * \param iterator_tuple The \p tuple of iterators to copy from. - */ - inline __host__ __device__ - zip_iterator(IteratorTuple iterator_tuple); - - /*! This copy constructor creates a new \p zip_iterator from another - * \p zip_iterator. - * - * \param other The \p zip_iterator to copy. - */ - template - inline __host__ __device__ - zip_iterator(const zip_iterator &other, - typename thrust::detail::enable_if_convertible< - OtherIteratorTuple, - IteratorTuple - >::type * = 0); - - /*! This method returns a \c const reference to this \p zip_iterator's - * \p tuple of iterators. - * - * \return A \c const reference to this \p zip_iterator's \p tuple - * of iterators. - */ - inline __host__ __device__ - const IteratorTuple &get_iterator_tuple() const; - - /*! \cond - */ - private: - typedef typename - detail::zip_iterator_base::type super_t; - - friend class thrust::iterator_core_access; - - // Dereferencing returns a tuple built from the dereferenced - // iterators in the iterator tuple. - __host__ __device__ - typename super_t::reference dereference() const; - - // Two zip_iterators are equal if the two first iterators of the - // tuple are equal. Note this differs from Boost's implementation, which - // considers the entire tuple. - template - inline __host__ __device__ - bool equal(const zip_iterator &other) const; - - // Advancing a zip_iterator means to advance all iterators in the tuple - inline __host__ __device__ - void advance(typename super_t::difference_type n); - - // Incrementing a zip iterator means to increment all iterators in the tuple - inline __host__ __device__ - void increment(); - - // Decrementing a zip iterator means to decrement all iterators in the tuple - inline __host__ __device__ - void decrement(); - - // Distance is calculated using the first iterator in the tuple. - template - inline __host__ __device__ - typename super_t::difference_type - distance_to(const zip_iterator &other) const; - - // The iterator tuple. - IteratorTuple m_iterator_tuple; - - /*! \endcond - */ -}; // end zip_iterator - -/*! \p make_zip_iterator creates a \p zip_iterator from a \p tuple - * of iterators. - * - * \param t The \p tuple of iterators to copy. - * \return A newly created \p zip_iterator which zips the iterators encapsulated in \p t. - * - * \see zip_iterator - */ -template -inline __host__ __device__ -zip_iterator make_zip_iterator(IteratorTuple t); - -/*! \} // end fancyiterators - */ - -/*! \} // end iterators - */ - -} // end thrust - -#include - diff --git a/compat/thrust/logical.h b/compat/thrust/logical.h deleted file mode 100644 index 21510f3..0000000 --- a/compat/thrust/logical.h +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file logical.h - * \brief Logical operations on ranges - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reductions - * \{ - * \addtogroup logical - * \ingroup reductions - * \{ - */ - - -/*! \p all_of determines whether all elements in a range satify a predicate. - * Specifically, \p all_of returns \c true if pred(*i) is \c true - * for every iterator \c i in the range [first, last) and - * \c false otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred A predicate used to test range elements. - * \return \c true, if all elements satisfy the predicate; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * \tparam Predicate must be a model of Predicate. - * - * \code - * #include - * #include - * #include - * ... - * bool A[3] = {true, true, false}; - * - * thrust::all_of(thrust::host, A, A + 2, thrust::identity()); // returns true - * thrust::all_of(thrust::host, A, A + 3, thrust::identity()); // returns false - * - * // empty range - * thrust::all_of(thrust::host, A, A, thrust::identity()); // returns false - * - * \endcode - * - * \see any_of - * \see none_of - * \see transform_reduce - */ -template -bool all_of(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred); - - -/*! \p all_of determines whether all elements in a range satify a predicate. - * Specifically, \p all_of returns \c true if pred(*i) is \c true - * for every iterator \c i in the range [first, last) and - * \c false otherwise. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred A predicate used to test range elements. - * \return \c true, if all elements satisfy the predicate; \c false, otherwise. - * - * \tparam InputIterator is a model of Input Iterator, - * \tparam Predicate must be a model of Predicate. - * - * \code - * #include - * #include - * ... - * bool A[3] = {true, true, false}; - * - * thrust::all_of(A, A + 2, thrust::identity()); // returns true - * thrust::all_of(A, A + 3, thrust::identity()); // returns false - * - * // empty range - * thrust::all_of(A, A, thrust::identity()); // returns false - * - * \endcode - * - * \see any_of - * \see none_of - * \see transform_reduce - */ -template -bool all_of(InputIterator first, InputIterator last, Predicate pred); - - -/*! \p any_of determines whether any element in a range satifies a predicate. - * Specifically, \p any_of returns \c true if pred(*i) is \c true - * for any iterator \c i in the range [first, last) and - * \c false otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred A predicate used to test range elements. - * \return \c true, if any element satisfies the predicate; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * \tparam Predicate must be a model of Predicate. - * - * \code - * #include - * #include - * #include - * ... - * bool A[3] = {true, true, false}; - * - * thrust::any_of(thrust::host, A, A + 2, thrust::identity()); // returns true - * thrust::any_of(thrust::host, A, A + 3, thrust::identity()); // returns true - * - * thrust::any_of(thrust::host, A + 2, A + 3, thrust::identity()); // returns false - * - * // empty range - * thrust::any_of(thrust::host, A, A, thrust::identity()); // returns false - * \endcode - * - * \see all_of - * \see none_of - * \see transform_reduce - */ -template -bool any_of(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred); - - -/*! \p any_of determines whether any element in a range satifies a predicate. - * Specifically, \p any_of returns \c true if pred(*i) is \c true - * for any iterator \c i in the range [first, last) and - * \c false otherwise. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred A predicate used to test range elements. - * \return \c true, if any element satisfies the predicate; \c false, otherwise. - * - * \tparam InputIterator is a model of Input Iterator, - * \tparam Predicate must be a model of Predicate. - * - * \code - * #include - * #include - * ... - * bool A[3] = {true, true, false}; - * - * thrust::any_of(A, A + 2, thrust::identity()); // returns true - * thrust::any_of(A, A + 3, thrust::identity()); // returns true - * - * thrust::any_of(A + 2, A + 3, thrust::identity()); // returns false - * - * // empty range - * thrust::any_of(A, A, thrust::identity()); // returns false - * \endcode - * - * \see all_of - * \see none_of - * \see transform_reduce - */ -template -bool any_of(InputIterator first, InputIterator last, Predicate pred); - - -/*! \p none_of determines whether no element in a range satifies a predicate. - * Specifically, \p none_of returns \c true if there is no iterator \c i in - * the range [first, last) such that pred(*i) is \c true, - * and \c false otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred A predicate used to test range elements. - * \return \c true, if no element satisfies the predicate; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * \tparam Predicate must be a model of Predicate. - * - * \code - * #include - * #include - * #include - * ... - * bool A[3] = {true, true, false}; - * - * thrust::none_of(thrust::host, A, A + 2, thrust::identity()); // returns false - * thrust::none_of(thrust::host, A, A + 3, thrust::identity()); // returns false - * - * thrust::none_of(thrust::host, A + 2, A + 3, thrust::identity()); // returns true - * - * // empty range - * thrust::none_of(thrust::host, A, A, thrust::identity()); // returns true - * \endcode - * - * \see all_of - * \see any_of - * \see transform_reduce - */ -template -bool none_of(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last, Predicate pred); - - -/*! \p none_of determines whether no element in a range satifies a predicate. - * Specifically, \p none_of returns \c true if there is no iterator \c i in - * the range [first, last) such that pred(*i) is \c true, - * and \c false otherwise. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param pred A predicate used to test range elements. - * \return \c true, if no element satisfies the predicate; \c false, otherwise. - * - * \tparam InputIterator is a model of Input Iterator, - * \tparam Predicate must be a model of Predicate. - * - * \code - * #include - * #include - * ... - * bool A[3] = {true, true, false}; - * - * thrust::none_of(A, A + 2, thrust::identity()); // returns false - * thrust::none_of(A, A + 3, thrust::identity()); // returns false - * - * thrust::none_of(A + 2, A + 3, thrust::identity()); // returns true - * - * // empty range - * thrust::none_of(A, A, thrust::identity()); // returns true - * \endcode - * - * \see all_of - * \see any_of - * \see transform_reduce - */ -template -bool none_of(InputIterator first, InputIterator last, Predicate pred); - - -/*! \} // end logical - * \} // end reductions - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/memory.h b/compat/thrust/memory.h deleted file mode 100644 index 6362de4..0000000 --- a/compat/thrust/memory.h +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/memory.h - * \brief Abstractions for Thrust's memory model. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup memory_management Memory Management - * \addtogroup memory_management_classes Memory Management Classes - * \ingroup memory_management - * \{ - */ - -/*! \p pointer stores a pointer to an object allocated in memory. Like \p device_ptr, this - * type ensures type safety when dispatching standard algorithms on ranges resident in memory. - * - * \p pointer generalizes \p device_ptr by relaxing the backend system associated with the \p pointer. - * Instead of the backend system specified by \p THRUST_DEFAULT_DEVICE_BACKEND, \p pointer's - * system is given by its second template parameter, \p Tag. For the purpose of Thrust dispatch, - * device_ptr and pointer are considered equivalent. - * - * The raw pointer encapsulated by a \p pointer may be obtained through its get member function - * or the \p raw_pointer_cast free function. - * - * \tparam Element specifies the type of the pointed-to object. - * - * \tparam Tag specifies the system with which this \p pointer is associated. This may be any Thrust - * backend system, or a user-defined tag. - * - * \tparam Reference allows the client to specify the reference type returned upon derereference. - * By default, this type is reference. - * - * \tparam Derived allows the client to specify the name of the derived type when \p pointer is used as - * a base class. This is useful to ensure that arithmetic on values of the derived type return - * values of the derived type as a result. By default, this type is pointer. - * - * \note \p pointer is not a smart pointer; it is the client's responsibility to deallocate memory - * pointer to by \p pointer. - * - * \see device_ptr - * \see reference - * \see raw_pointer_cast - */ -// define pointer for the purpose of Doxygenating it -// it is actually defined elsewhere -#if 0 -template - class pointer -{ - public: - /*! The type of the raw pointer - */ - typedef typename super_t::base_type raw_pointer; - - /*! \p pointer's default constructor initializes its encapsulated pointer to \c 0 - */ - __host__ __device__ - pointer(); - - /*! This constructor allows construction of a pointer from a T*. - * - * \param ptr A raw pointer to copy from, presumed to point to a location in \p Tag's memory. - * \tparam OtherElement \p OtherElement shall be convertible to \p Element. - */ - template - __host__ __device__ - explicit pointer(OtherElement *ptr); - - /*! This contructor allows initialization from another pointer-like object. - * - * \param other The \p OtherPointer to copy. - * - * \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag, - * and its element type shall be convertible to \p Element. - */ - template - __host__ __device__ - pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type * = 0); - - /*! Assignment operator allows assigning from another pointer-like object with related type. - * - * \param other The other pointer-like object to assign from. - * \return *this - * - * \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag, - * and its element type shall be convertible to \p Element. - */ - template - __host__ __device__ - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - derived_type & - >::type - operator=(const OtherPointer &other); - - /*! \p get returns this \p pointer's encapsulated raw pointer. - * \return This \p pointer's raw pointer. - */ - __host__ __device__ - Element *get() const; -}; -#endif - -/*! \p reference is a wrapped reference to an object stored in memory. \p reference generalizes - * \p device_reference by relaxing the type of pointer associated with the object. \p reference - * is the type of the result of dereferencing a tagged pointer-like object such as \p pointer, and - * intermediates operations on objects existing in a remote memory. - * - * \tparam Element specifies the type of the referent object. - * \tparam Pointer specifies the type of the result of taking the address of \p reference. - * \tparam Derived allows the client to specify the name of the derived type when \p reference is used as - * a base class. This is useful to ensure that assignment to objects of the derived type return - * values of the derived type as a result. By default, this type is reference. - */ -// define pointer for the purpose of Doxygenating it -// it is actually defined elsewhere -#if 0 -template - class reference -{ - public: - /*! The type of this \p reference's wrapped pointers. - */ - typedef Pointer pointer; - - /*! The \p value_type of this \p reference. - */ - typedef typename thrust::detail::remove_const::type value_type; - - /*! This copy constructor initializes this \p reference - * to refer to an object pointed to by the given \p pointer. After - * this \p reference is constructed, it shall refer to the - * object pointed to by \p ptr. - * - * \param ptr A \p pointer to copy from. - */ - __host__ __device__ - explicit reference(const pointer &ptr); - - /*! This copy constructor accepts a const reference to another - * \p reference of related type. After this \p reference is constructed, - * it shall refer to the same object as \p other. - * - * \param other A \p reference to copy from. - * \tparam OtherElement the element type of the other \p reference. - * \tparam OtherPointer the pointer type of the other \p reference. - * \tparam OtherDerived the derived type of the other \p reference. - * - * \note This constructor is templated primarily to allow initialization of - * reference from reference. - */ - template - __host__ __device__ - reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type * = 0); - - /*! Copy assignment operator copy assigns from another \p reference. - * - * \param other The other \p reference to assign from. - * \return static_cast(*this) - */ - __host__ __device__ - derived_type &operator=(const reference &other); - - /*! Assignment operator copy assigns from another \p reference of related type. - * - * \param other The other \p reference to assign from. - * \return static_cast(*this) - * - * \tparam OtherElement the element type of the other \p reference. - * \tparam OtherPointer the pointer type of the other \p reference. - * \tparam OtherDerived the derived type of the other \p reference. - */ - template - __host__ __device__ - derived_type &operator=(const reference &other); - - /*! Assignment operator assigns from a \p value_type. - * - * \param x The \p value_type to assign from. - * \return static_cast(*this). - */ - __host__ __device__ - derived_type &operator=(const value_type &x); - - /*! Address-of operator returns a \p pointer pointing to the object - * referenced by this \p reference. It does not return the address of this - * \p reference. - * - * \return A \p pointer pointing to the referenct object. - */ - __host__ __device__ - pointer operator&() const; - - /*! Conversion operator converts this \p reference to \p value_type by - * returning a copy of the referent object. - * - * \return A copy of the referent object. - */ - __host__ __device__ - operator value_type () const; - - /*! Swaps the value of the referent object with another. - * - * \param other The other \p reference with which to swap. - * \note The argument is of type \p derived_type rather than \p reference. - */ - __host__ __device__ - void swap(derived_type &other); - - /*! Prefix increment operator increments the referent object. - * - * \return static_Cast(*this). - * - * \note Documentation for other arithmetic operators omitted for brevity. - */ - derived_type &operator++(); -}; -#endif - -/*! \} - */ - -/*! - * \addtogroup memory_management_functions Memory Management Functions - * \ingroup memory_management - * \{ - */ - - -/*! \addtogroup allocation_functions - * \{ - */ - - -/*! This version of \p malloc allocates untyped uninitialized storage associated with a given system. - * - * \param system The Thrust system with which to associate the storage. - * \param n The number of bytes of storage to allocate. - * \return If allocation succeeds, a pointer to the allocated storage; a null pointer otherwise. - * The pointer must be deallocated with \p thrust::free. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * - * \pre \p DerivedPolicy must be publically derived from thrust::execution_policy. - * - * The following code snippet demonstrates how to use \p malloc to allocate a range of memory - * associated with Thrust's device system. - * - * \code - * #include - * ... - * // allocate some memory with thrust::malloc - * const int N = 100; - * thrust::device_system_tag device_sys; - * thrust::pointer void_ptr = thrust::malloc(device_sys, N); - * - * // manipulate memory - * ... - * - * // deallocate void_ptr with thrust::free - * thrust::free(device_sys, void_ptr); - * \endcode - * - * \see free - * \see device_malloc - */ -template -pointer malloc(const thrust::detail::execution_policy_base &system, std::size_t n); - - -/*! This version of \p malloc allocates typed uninitialized storage associated with a given system. - * - * \param system The Thrust system with which to associate the storage. - * \param n The number of elements of type \c T which the storage should accomodate. - * \return If allocation succeeds, a pointer to an allocation large enough to accomodate \c n - * elements of type \c T; a null pointer otherwise. - * The pointer must be deallocated with \p thrust::free. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * - * \pre \p DerivedPolicy must be publically derived from thrust::execution_policy. - * - * The following code snippet demonstrates how to use \p malloc to allocate a range of memory - * to accomodate integers associated with Thrust's device system. - * - * \code - * #include - * ... - * // allocate storage for 100 ints with thrust::malloc - * const int N = 100; - * thrust::device_system_tag device_sys; - * thrust::pointer ptr = thrust::malloc(device_sys, N); - * - * // manipulate memory - * ... - * - * // deallocate ptr with thrust::free - * thrust::free(device_sys, ptr); - * \endcode - * - * \see free - * \see device_malloc - */ -template -pointer malloc(const thrust::detail::execution_policy_base &system, std::size_t n); - - -/*! \p get_temporary_buffer returns a pointer to storage associated with a given Thrust system sufficient to store up to - * \p n objects of type \c T. If not enough storage is available to accomodate \p n objects, an implementation may return - * a smaller buffer. The number of objects the returned buffer can accomodate is also returned. - * - * Thrust uses \p get_temporary_buffer internally when allocating temporary storage required by algorithm implementations. - * - * The storage allocated with \p get_temporary_buffer must be returned to the system with \p return_temporary_buffer. - * - * \param system The Thrust system with which to associate the storage. - * \param n The requested number of objects of type \c T the storage should accomodate. - * \return A pair \c p such that p.first is a pointer to the allocated storage and p.second is the number of - * contiguous objects of type \c T that the storage can accomodate. If no storage can be allocated, p.first if - * no storage can be obtained. The storage must be returned to the system using \p return_temporary_buffer. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * - * \pre \p DerivedPolicy must be publically derived from thrust::execution_policy. - * - * The following code snippet demonstrates how to use \p get_temporary_buffer to allocate a range of memory - * to accomodate integers associated with Thrust's device system. - * - * \code - * #include - * ... - * // allocate storage for 100 ints with thrust::get_temporary_buffer - * const int N = 100; - * - * typedef thrust::pair< - * thrust::pointer, - * std::ptrdiff_t - * > ptr_and_size_t; - * - * thrust::device_system_tag device_sys; - * ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer(device_sys, N); - * - * // manipulate up to 100 ints - * for(int i = 0; i < ptr_and_size.second; ++i) - * { - * *ptr_and_size.first = i; - * } - * - * // deallocate storage with thrust::return_temporary_buffer - * thrust::return_temporary_buffer(device_sys, ptr_and_size.first); - * \endcode - * - * \see malloc - * \see return_temporary_buffer - */ -template -thrust::pair, typename thrust::pointer::difference_type> -get_temporary_buffer(const thrust::detail::execution_policy_base &system, typename thrust::pointer::difference_type n); - - -/*! \} allocation_functions - */ - - -/*! \addtogroup deallocation_functions - * \{ - */ - - -/*! \p free deallocates the storage previously allocated by \p thrust::malloc. - * - * \param system The Thrust system with which the storage is associated. - * \param ptr A pointer previously returned by \p thrust::malloc. If \p ptr is null, \p free - * does nothing. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * - * \pre \p ptr shall have been returned by a previous call to thrust::malloc(system, n) or thrust::malloc(system, n) for some type \c T. - * - * The following code snippet demonstrates how to use \p free to deallocate a range of memory - * previously allocated with \p thrust::malloc. - * - * \code - * #include - * ... - * // allocate storage for 100 ints with thrust::malloc - * const int N = 100; - * thrust::device_system_tag device_sys; - * thrust::pointer ptr = thrust::malloc(device_sys, N); - * - * // mainpulate memory - * ... - * - * // deallocate ptr with thrust::free - * thrust::free(device_sys, ptr); - * \endcode - */ -template -void free(const thrust::detail::execution_policy_base &system, Pointer ptr); - - -/*! \p return_temporary_buffer deallocates storage associated with a given Thrust system previously allocated by \p get_temporary_buffer. - * - * Thrust uses \p return_temporary_buffer internally when deallocating temporary storage required by algorithm implementations. - * - * \param system The Thrust system with which the storage is associated. - * \param p A pointer previously returned by \p thrust::get_temporary_buffer. If \p ptr is null, \p return_temporary_buffer does nothing. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * - * \pre \p p shall have been previously allocated by \p thrust::get_temporary_buffer. - * - * The following code snippet demonstrates how to use \p return_temporary_buffer to deallocate a range of memory - * previously allocated by \p get_temporary_buffer. - * - * \code - * #include - * ... - * // allocate storage for 100 ints with thrust::get_temporary_buffer - * const int N = 100; - * - * typedef thrust::pair< - * thrust::pointer, - * std::ptrdiff_t - * > ptr_and_size_t; - * - * thrust::device_system_tag device_sys; - * ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer(device_sys, N); - * - * // manipulate up to 100 ints - * for(int i = 0; i < ptr_and_size.second; ++i) - * { - * *ptr_and_size.first = i; - * } - * - * // deallocate storage with thrust::return_temporary_buffer - * thrust::return_temporary_buffer(device_sys, ptr_and_size.first); - * \endcode - * - * \see free - * \see get_temporary_buffer - */ -template -void return_temporary_buffer(const thrust::detail::execution_policy_base &system, Pointer p); - - -/*! \} deallocation_functions - */ - - -/*! \p raw_pointer_cast creates a "raw" pointer from a pointer-like type, - * simply returning the wrapped pointer, should it exist. - * - * \param ptr The pointer of interest. - * \return ptr.get(), if the expression is well formed; ptr, otherwise. - * \see raw_reference_cast - */ -template -__host__ __device__ -inline typename thrust::detail::pointer_traits::raw_pointer - raw_pointer_cast(const Pointer &ptr); - - -/*! \p raw_reference_cast creates a "raw" reference from a wrapped reference type, - * simply returning the underlying reference, should it exist. - * - * If the argument is not a reference wrapper, the result is a reference to the argument. - * - * \param ref The reference of interest. - * \return *thrust::raw_pointer_cast(&ref). - * \note There are two versions of \p raw_reference_cast. One for const references, - * and one for non-const. - * \see raw_pointer_cast - */ -template -__host__ __device__ -inline typename detail::raw_reference::type - raw_reference_cast(T &ref); - - -/*! \p raw_reference_cast creates a "raw" reference from a wrapped reference type, - * simply returning the underlying reference, should it exist. - * - * If the argument is not a reference wrapper, the result is a reference to the argument. - * - * \param ref The reference of interest. - * \return *thrust::raw_pointer_cast(&ref). - * \note There are two versions of \p raw_reference_cast. One for const references, - * and one for non-const. - * \see raw_pointer_cast - */ -template -__host__ __device__ -inline typename detail::raw_reference::type - raw_reference_cast(const T &ref); - - -/*! \} - */ - -} // end thrust - diff --git a/compat/thrust/merge.h b/compat/thrust/merge.h deleted file mode 100644 index e5fa7b4..0000000 --- a/compat/thrust/merge.h +++ /dev/null @@ -1,676 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file merge.h - * \brief Merging sorted ranges - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup merging Merging - * \ingroup algorithms - * \{ - */ - - -/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) - * into a single sorted range. That is, it copies from [first1, last1) and - * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) - * such that the resulting range is in ascending order. \p merge is stable, meaning both that the - * relative order of elements within each input range is preserved, and that for equivalent elements - * in both input ranges the element from the first range precedes the element from the second. The - * return value is result + (last1 - first1) + (last2 - first2). - * - * This version of \p merge compares elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the merged output. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use - * \p merge to compute the merger of two sorted sets of integers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {1, 3, 5, 7, 9, 11}; - * int A2[7] = {1, 1, 2, 3, 5, 8, 13}; - * - * int result[13]; - * - * int *result_end = - * thrust::merge(thrust::host, - * A1, A1 + 6, - * A2, A2 + 7, - * result); - * // result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} - * \endcode - * - * \see http://www.sgi.com/tech/stl/merge.html - * \see \p set_union - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator merge(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) - * into a single sorted range. That is, it copies from [first1, last1) and - * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) - * such that the resulting range is in ascending order. \p merge is stable, meaning both that the - * relative order of elements within each input range is preserved, and that for equivalent elements - * in both input ranges the element from the first range precedes the element from the second. The - * return value is result + (last1 - first1) + (last2 - first2). - * - * This version of \p merge compares elements using \c operator<. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the merged output. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use - * \p merge to compute the merger of two sorted sets of integers. - * - * \code - * #include - * ... - * int A1[6] = {1, 3, 5, 7, 9, 11}; - * int A2[7] = {1, 1, 2, 3, 5, 8, 13}; - * - * int result[13]; - * - * int *result_end = thrust::merge(A1, A1 + 6, A2, A2 + 7, result); - * // result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} - * \endcode - * - * \see http://www.sgi.com/tech/stl/merge.html - * \see \p set_union - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator merge(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) - * into a single sorted range. That is, it copies from [first1, last1) and - * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) - * such that the resulting range is in ascending order. \p merge is stable, meaning both that the - * relative order of elements within each input range is preserved, and that for equivalent elements - * in both input ranges the element from the first range precedes the element from the second. The - * return value is result + (last1 - first1) + (last2 - first2). - * - * This version of \p merge compares elements using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the merged output. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use - * \p merge to compute the merger of two sets of integers sorted in - * descending order using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A1[6] = {11, 9, 7, 5, 3, 1}; - * int A2[7] = {13, 8, 5, 3, 2, 1, 1}; - * - * int result[13]; - * - * int *result_end = thrust::merge(thrust::host, - * A1, A1 + 6, - * A2, A2 + 7, - * result, - * thrust::greater()); - * // result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/merge.html - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator merge(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) - * into a single sorted range. That is, it copies from [first1, last1) and - * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) - * such that the resulting range is in ascending order. \p merge is stable, meaning both that the - * relative order of elements within each input range is preserved, and that for equivalent elements - * in both input ranges the element from the first range precedes the element from the second. The - * return value is result + (last1 - first1) + (last2 - first2). - * - * This version of \p merge compares elements using a function object \p comp. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the merged output. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use - * \p merge to compute the merger of two sets of integers sorted in - * descending order. - * - * \code - * #include - * #include - * ... - * int A1[6] = {11, 9, 7, 5, 3, 1}; - * int A2[7] = {13, 8, 5, 3, 2, 1, 1}; - * - * int result[13]; - * - * int *result_end = thrust::merge(A1, A1 + 6, A2, A2 + 7, result, thrust::greater()); - * // result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/merge.html - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator merge(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from - * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, - * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending key order. - * - * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - keys_first1)) - * and [values_first2 + (keys_last2 - keys_first2)) into a single range, - * [values_result, values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending order implied by each input element's associated key. - * - * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is - * preserved, and that for equivalent elements in all input key ranges the element from the first range - * precedes the element from the second. - * - * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) - * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the merged output range of keys. - * \param values_result The beginning of the merged output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use - * \p merge_by_key to compute the merger of two sets of integers sorted in - * ascending order using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A_keys[6] = {1, 3, 5, 7, 9, 11}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13}; - * int B_vals[7] = {1, 1, 1, 1, 1, 1, 1}; - * - * int keys_result[13]; - * int vals_result[13]; - * - * thrust::pair end = - * thrust::merge_by_key(thrust::host, - * A_keys, A_keys + 6, - * B_keys, B_keys + 7, - * A_vals, B_vals, - * keys_result, vals_result); - * - * // keys_result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} - * // vals_result = {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1} - * \endcode - * - * \see merge - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - merge_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from - * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, - * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending key order. - * - * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - keys_first1)) - * and [values_first2 + (keys_last2 - keys_first2)) into a single range, - * [values_result, values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending order implied by each input element's associated key. - * - * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is - * preserved, and that for equivalent elements in all input key ranges the element from the first range - * precedes the element from the second. - * - * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) - * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the merged output range of keys. - * \param values_result The beginning of the merged output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use - * \p merge_by_key to compute the merger of two sets of integers sorted in - * ascending order. - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {1, 3, 5, 7, 9, 11}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13}; - * int B_vals[7] = {1, 1, 1, 1, 1, 1, 1}; - * - * int keys_result[13]; - * int vals_result[13]; - * - * thrust::pair end = thrust::merge_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, B_vals, keys_result, vals_result); - * - * // keys_result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} - * // vals_result = {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1} - * \endcode - * - * \see merge - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - merge_by_key(InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from - * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, - * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending key order. - * - * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - keys_first1)) - * and [values_first2 + (keys_last2 - keys_first2)) into a single range, - * [values_result, values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending order implied by each input element's associated key. - * - * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is - * preserved, and that for equivalent elements in all input key ranges the element from the first range - * precedes the element from the second. - * - * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) - * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). - * - * This version of \p merge_by_key compares key elements using a function object \p comp. - * - * The algorithm's execution is parallelized using \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the merged output range of keys. - * \param values_result The beginning of the merged output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator1's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator1's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use - * \p merge_by_key to compute the merger of two sets of integers sorted in - * descending order using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A_keys[6] = {11, 9, 7, 5, 3, 1}; - * int A_vals[6] = { 0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1}; - * int B_vals[7] = { 1, 1, 1, 1, 1, 1, 1}; - * - * int keys_result[13]; - * int vals_result[13]; - * - * thrust::pair end = - * thrust::merge_by_key(thrust::host, - * A_keys, A_keys + 6, - * B_keys, B_keys + 7, - * A_vals, B_vals, - * keys_result, vals_result, - * thrust::greater()); - * - * // keys_result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} - * // vals_result = { 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1} - * \endcode - * - * \see merge - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - merge_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - Compare comp); - - -/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from - * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, - * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending key order. - * - * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - keys_first1)) - * and [values_first2 + (keys_last2 - keys_first2)) into a single range, - * [values_result, values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that - * the resulting range is in ascending order implied by each input element's associated key. - * - * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is - * preserved, and that for equivalent elements in all input key ranges the element from the first range - * precedes the element from the second. - * - * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) - * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). - * - * This version of \p merge_by_key compares key elements using a function object \p comp. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the merged output range of keys. - * \param values_result The beginning of the merged output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator1's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator1's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use - * \p merge_by_key to compute the merger of two sets of integers sorted in - * descending order. - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {11, 9, 7, 5, 3, 1}; - * int A_vals[6] = { 0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1}; - * int B_vals[7] = { 1, 1, 1, 1, 1, 1, 1}; - * - * int keys_result[13]; - * int vals_result[13]; - * - * thrust::pair end = thrust::merge_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, B_vals, keys_result, vals_result, thrust::greater()); - * - * // keys_result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} - * // vals_result = { 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1} - * \endcode - * - * \see merge - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - merge_by_key(InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \} // merging - */ - -} // end thrust - -#include - diff --git a/compat/thrust/mismatch.h b/compat/thrust/mismatch.h deleted file mode 100644 index 898157a..0000000 --- a/compat/thrust/mismatch.h +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file mismatch.h - * \brief Search for differences between ranges - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - -/*! \addtogroup searching - * \ingroup algorithms - * \{ - */ - - -/*! \p mismatch finds the first position where the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) differ. The two versions of - * \p mismatch use different tests for whether elements differ. - * - * This version of \p mismatch finds the first iterator \c i in [first1, last1) - * such that *i == *(first2 + (i - first1)) is \c false. The return value is a - * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). - * If no such iterator \c i exists, the return value is a \c pair whose first element - * is \c last1 and whose second element is *(first2 + (last1 - first1)). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \return The first position where the sequences differ. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * and \p InputIterator1's \c value_type is equality comparable to \p InputIterator2's \c value_type. - * \tparam InputIterator2 is a model of Input Iterator. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector vec1(4); - * thrust::device_vector vec2(4); - * - * vec1[0] = 0; vec2[0] = 0; - * vec1[1] = 5; vec2[1] = 5; - * vec1[2] = 3; vec2[2] = 8; - * vec1[3] = 7; vec2[3] = 7; - * - * typedef thrust::device_vector::iterator Iterator; - * thrust::pair result; - * - * result = thrust::mismatch(thrust::device, vec1.begin(), vec1.end(), vec2.begin()); - * - * // result.first is vec1.begin() + 2 - * // result.second is vec2.begin() + 2 - * \endcode - * - * \see find - * \see find_if - */ -template -thrust::pair mismatch(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2); - - -/*! \p mismatch finds the first position where the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) differ. The two versions of - * \p mismatch use different tests for whether elements differ. - * - * This version of \p mismatch finds the first iterator \c i in [first1, last1) - * such that *i == *(first2 + (i - first1)) is \c false. The return value is a - * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). - * If no such iterator \c i exists, the return value is a \c pair whose first element - * is \c last1 and whose second element is *(first2 + (last1 - first1)). - * - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \return The first position where the sequences differ. - * - * \tparam InputIterator1 is a model of Input Iterator - * and \p InputIterator1's \c value_type is equality comparable to \p InputIterator2's \c value_type. - * \tparam InputIterator2 is a model of Input Iterator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector vec1(4); - * thrust::device_vector vec2(4); - * - * vec1[0] = 0; vec2[0] = 0; - * vec1[1] = 5; vec2[1] = 5; - * vec1[2] = 3; vec2[2] = 8; - * vec1[3] = 7; vec2[3] = 7; - * - * typedef thrust::device_vector::iterator Iterator; - * thrust::pair result; - * - * result = thrust::mismatch(vec1.begin(), vec1.end(), vec2.begin()); - * - * // result.first is vec1.begin() + 2 - * // result.second is vec2.begin() + 2 - * \endcode - * - * \see find - * \see find_if - */ -template -thrust::pair mismatch(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2); - - -/*! \p mismatch finds the first position where the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) differ. The two versions of - * \p mismatch use different tests for whether elements differ. - * - * This version of \p mismatch finds the first iterator \c i in [first1, last1) - * such that pred(\*i, \*(first2 + (i - first1)) is \c false. The return value is a - * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). - * If no such iterator \c i exists, the return value is a \c pair whose first element is - * \c last1 and whose second element is *(first2 + (last1 - first1)). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param pred The binary predicate to compare elements. - * \return The first position where the sequences differ. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator. - * \tparam InputIterator2 is a model of Input Iterator. - * \tparam Predicate is a model of Input Iterator. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector vec1(4); - * thrust::device_vector vec2(4); - * - * vec1[0] = 0; vec2[0] = 0; - * vec1[1] = 5; vec2[1] = 5; - * vec1[2] = 3; vec2[2] = 8; - * vec1[3] = 7; vec2[3] = 7; - * - * typedef thrust::device_vector::iterator Iterator; - * thrust::pair result; - * - * result = thrust::mismatch(thrust::device, vec1.begin(), vec1.end(), vec2.begin(), thrust::equal_to()); - * - * // result.first is vec1.begin() + 2 - * // result.second is vec2.begin() + 2 - * \endcode - * - * \see find - * \see find_if - */ -template -thrust::pair mismatch(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - BinaryPredicate pred); - - -/*! \p mismatch finds the first position where the two ranges [first1, last1) - * and [first2, first2 + (last1 - first1)) differ. The two versions of - * \p mismatch use different tests for whether elements differ. - * - * This version of \p mismatch finds the first iterator \c i in [first1, last1) - * such that pred(\*i, \*(first2 + (i - first1)) is \c false. The return value is a - * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). - * If no such iterator \c i exists, the return value is a \c pair whose first element is - * \c last1 and whose second element is *(first2 + (last1 - first1)). - * - * \param first1 The beginning of the first sequence. - * \param last1 The end of the first sequence. - * \param first2 The beginning of the second sequence. - * \param pred The binary predicate to compare elements. - * \return The first position where the sequences differ. - * - * \tparam InputIterator1 is a model of Input Iterator. - * \tparam InputIterator2 is a model of Input Iterator. - * \tparam Predicate is a model of Input Iterator. - * - * \code - * #include - * #include - * ... - * thrust::device_vector vec1(4); - * thrust::device_vector vec2(4); - * - * vec1[0] = 0; vec2[0] = 0; - * vec1[1] = 5; vec2[1] = 5; - * vec1[2] = 3; vec2[2] = 8; - * vec1[3] = 7; vec2[3] = 7; - * - * typedef thrust::device_vector::iterator Iterator; - * thrust::pair result; - * - * result = thrust::mismatch(vec1.begin(), vec1.end(), vec2.begin(), thrust::equal_to()); - * - * // result.first is vec1.begin() + 2 - * // result.second is vec2.begin() + 2 - * \endcode - * - * \see find - * \see find_if - */ -template -thrust::pair mismatch(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - BinaryPredicate pred); - -/*! \} // end searching - */ - -} // end namespace thrust - -#include - diff --git a/compat/thrust/pair.h b/compat/thrust/pair.h deleted file mode 100644 index 897cc07..0000000 --- a/compat/thrust/pair.h +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file pair.h - * \brief A type encapsulating a heterogeneous pair of elements - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -/*! \addtogroup utility - * \{ - */ - -/*! \addtogroup pair - * \{ - */ - -/*! \p pair is a generic data structure encapsulating a heterogeneous - * pair of values. - * - * \tparam T1 The type of \p pair's first object type. There are no - * requirements on the type of \p T1. T1's type is - * provided by pair::first_type. - * - * \tparam T2 The type of \p pair's second object type. There are no - * requirements on the type of \p T2. T2's type is - * provided by pair::second_type. - */ -template - struct pair -{ - /*! \p first_type is the type of \p pair's first object type. - */ - typedef T1 first_type; - - /*! \p second_type is the type of \p pair's second object type. - */ - typedef T2 second_type; - - /*! The \p pair's first object. - */ - first_type first; - - /*! The \p pair's second object. - */ - second_type second; - - /*! \p pair's default constructor constructs \p first - * and \p second using \c first_type & \c second_type's - * default constructors, respectively. - */ - __host__ __device__ pair(void); - - /*! This constructor accepts two objects to copy into this \p pair. - * - * \param x The object to copy into \p first. - * \param y The object to copy into \p second. - */ - inline __host__ __device__ - pair(const T1 &x, const T2 &y); - - /*! This copy constructor copies from a \p pair whose types are - * convertible to this \p pair's \c first_type and \c second_type, - * respectively. - * - * \param p The \p pair to copy from. - * - * \tparam U1 is convertible to \c first_type. - * \tparam U2 is convertible to \c second_type. - */ - template - inline __host__ __device__ - pair(const pair &p); - - /*! This copy constructor copies from a std::pair whose types are - * convertible to this \p pair's \c first_type and \c second_type, - * respectively. - * - * \param p The std::pair to copy from. - * - * \tparam U1 is convertible to \c first_type. - * \tparam U2 is convertible to \c second_type. - */ - template - inline __host__ __device__ - pair(const std::pair &p); - - /*! \p swap swaps the elements of two pairs. - * - * \param p The other pair with which to swap. - */ - inline __host__ __device__ - void swap(pair &p); -}; // end pair - - -/*! This operator tests two \p pairs for equality. - * - * \param x The first \p pair to compare. - * \param y The second \p pair to compare. - * \return \c true if and only if x.first == y.first && x.second == y.second. - * - * \tparam T1 is a model of Equality Comparable. - * \tparam T2 is a model of Equality Comparable. - */ -template - inline __host__ __device__ - bool operator==(const pair &x, const pair &y); - - -/*! This operator tests two pairs for ascending ordering. - * - * \param x The first \p pair to compare. - * \param y The second \p pair to compare. - * \return \c true if and only if x.first < y.first || (!(y.first < x.first) && x.second < y.second). - * - * \tparam T1 is a model of LessThan Comparable. - * \tparam T2 is a model of LessThan Comparable. - */ -template - inline __host__ __device__ - bool operator<(const pair &x, const pair &y); - - -/*! This operator tests two pairs for inequality. - * - * \param x The first \p pair to compare. - * \param y The second \p pair to compare. - * \return \c true if and only if !(x == y). - * - * \tparam T1 is a model of Equality Comparable. - * \tparam T2 is a model of Equality Comparable. - */ -template - inline __host__ __device__ - bool operator!=(const pair &x, const pair &y); - - -/*! This operator tests two pairs for descending ordering. - * - * \param x The first \p pair to compare. - * \param y The second \p pair to compare. - * \return \c true if and only if y < x. - * - * \tparam T1 is a model of LessThan Comparable. - * \tparam T2 is a model of LessThan Comparable. - */ -template - inline __host__ __device__ - bool operator>(const pair &x, const pair &y); - - -/*! This operator tests two pairs for ascending ordering or equivalence. - * - * \param x The first \p pair to compare. - * \param y The second \p pair to compare. - * \return \c true if and only if !(y < x). - * - * \tparam T1 is a model of LessThan Comparable. - * \tparam T2 is a model of LessThan Comparable. - */ -template - inline __host__ __device__ - bool operator<=(const pair &x, const pair &y); - - -/*! This operator tests two pairs for descending ordering or equivalence. - * - * \param x The first \p pair to compare. - * \param y The second \p pair to compare. - * \return \c true if and only if !(x < y). - * - * \tparam T1 is a model of LessThan Comparable. - * \tparam T2 is a model of LessThan Comparable. - */ -template - inline __host__ __device__ - bool operator>=(const pair &x, const pair &y); - - -/*! \p swap swaps the contents of two pairs. - * - * \param x The first \p pair to swap. - * \param y The second \p pair to swap. - */ -template - inline __host__ __device__ - void swap(pair &x, pair &y); - - -/*! This convenience function creates a \p pair from two objects. - * - * \param x The first object to copy from. - * \param y The second object to copy from. - * \return A newly-constructed \p pair copied from \p a and \p b. - * - * \tparam T1 There are no requirements on the type of \p T1. - * \tparam T2 There are no requirements on the type of \p T2. - */ -template - inline __host__ __device__ - pair make_pair(T1 x, T2 y); - - -/*! This convenience metafunction is included for compatibility with - * \p tuple. It returns either the type of a \p pair's - * \c first_type or \c second_type in its nested type, \c type. - * - * \tparam N This parameter selects the member of interest. - * \tparam T A \c pair type of interest. - */ -template struct tuple_element; - - -/*! This convenience metafunction is included for compatibility with - * \p tuple. It returns \c 2, the number of elements of a \p pair, - * in its nested data member, \c value. - * - * \tparam Pair A \c pair type of interest. - */ -template struct tuple_size; - - -/*! This convenience function returns a reference to either the first or - * second member of a \p pair. - * - * \param p The \p pair of interest. - * \return \c p.first or \c p.second, depending on the template - * parameter. - * - * \tparam N This parameter selects the member of interest. - */ -// XXX comment out these prototypes as a WAR to a problem on MSVC 2005 -//template -// inline __host__ __device__ -// typename tuple_element >::type & -// get(pair &p); - - -/*! This convenience function returns a const reference to either the - * first or second member of a \p pair. - * - * \param p The \p pair of interest. - * \return \c p.first or \c p.second, depending on the template - * parameter. - * - * \tparam i This parameter selects the member of interest. - */ -// XXX comment out these prototypes as a WAR to a problem on MSVC 2005 -//template -// inline __host__ __device__ -// const typename tuple_element >::type & -// get(const pair &p); - -/*! \} // pair - */ - -/*! \} // utility - */ - -} // end thrust - -#include - diff --git a/compat/thrust/partition.h b/compat/thrust/partition.h deleted file mode 100644 index 61a6278..0000000 --- a/compat/thrust/partition.h +++ /dev/null @@ -1,1429 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file partition.h - * \brief Reorganizes a range based on a predicate - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reordering - * \ingroup algorithms - * - * \addtogroup partitioning - * \ingroup reordering - * \{ - */ - - -/*! \p partition reorders the elements [first, last) based on the function - * object \p pred, such that all of the elements that satisfy \p pred precede the - * elements that fail to satisfy it. The postcondition is that, for some iterator - * \c middle in the range [first, last), pred(*i) is \c true for every - * iterator \c i in the range [first,middle) and \c false for every iterator - * \c i in the range [middle, last). The return value of \p partition is - * \c middle. - * - * Note that the relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition, does guarantee to preserve the relative order. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements which do not satisfy \p pred. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, - * and \p ForwardIterator is mutable. - * \tparam Predicate is a model of Predicate. - * - * The following code snippet demonstrates how to use \p partition to reorder a - * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::partition(thrust::host, - * A, A + N, - * is_even()); - * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partition.html - * \see \p stable_partition - * \see \p partition_copy - */ -template - ForwardIterator partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p partition reorders the elements [first, last) based on the function - * object \p pred, such that all of the elements that satisfy \p pred precede the - * elements that fail to satisfy it. The postcondition is that, for some iterator - * \c middle in the range [first, last), pred(*i) is \c true for every - * iterator \c i in the range [first,middle) and \c false for every iterator - * \c i in the range [middle, last). The return value of \p partition is - * \c middle. - * - * Note that the relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition, does guarantee to preserve the relative order. - * - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements which do not satisfy \p pred. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, - * and \p ForwardIterator is mutable. - * \tparam Predicate is a model of Predicate. - * - * The following code snippet demonstrates how to use \p partition to reorder a - * sequence so that even numbers precede odd numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::partition(A, A + N, - * is_even()); - * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partition.html - * \see \p stable_partition - * \see \p partition_copy - */ -template - ForwardIterator partition(ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p partition reorders the elements [first, last) based on the function - * object \p pred applied to a stencil range [stencil, stencil + (last - first)), - * such that all of the elements whose corresponding stencil element satisfies \p pred precede all of the elements whose - * corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator - * \c middle in the range [first, last), pred(*stencil_i) is \c true for every iterator - * \c stencil_i in the range [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i - * in the range [stencil + (middle - first), stencil + (last - first)). - * The return value of \p stable_partition is \c middle. - * - * Note that the relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition, does guarantee to preserve the relative order. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements whose stencil elements do not satisfy \p pred. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The ranges [first,last) and [stencil, stencil + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p partition to reorder a - * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::partition(thrust::host, A, A + N, S, is_even()); - * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * // S is unmodified - * \endcode - * - * \see http://www.sgi.com/tech/stl/partition.html - * \see \p stable_partition - * \see \p partition_copy - */ -template - ForwardIterator partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -/*! \p partition reorders the elements [first, last) based on the function - * object \p pred applied to a stencil range [stencil, stencil + (last - first)), - * such that all of the elements whose corresponding stencil element satisfies \p pred precede all of the elements whose - * corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator - * \c middle in the range [first, last), pred(*stencil_i) is \c true for every iterator - * \c stencil_i in the range [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i - * in the range [stencil + (middle - first), stencil + (last - first)). - * The return value of \p stable_partition is \c middle. - * - * Note that the relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition, does guarantee to preserve the relative order. - * - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements whose stencil elements do not satisfy \p pred. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The ranges [first,last) and [stencil, stencil + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p partition to reorder a - * sequence so that even numbers precede odd numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::partition(A, A + N, S, is_even()); - * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * // S is unmodified - * \endcode - * - * \see http://www.sgi.com/tech/stl/partition.html - * \see \p stable_partition - * \see \p partition_copy - */ -template - ForwardIterator partition(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -/*! \p partition_copy differs from \ref partition only in that the reordered - * sequence is written to difference output sequences, rather than in place. - * - * \p partition_copy copies the elements [first, last) based on the - * function object \p pred. All of the elements that satisfy \p pred are copied - * to the range beginning at \p out_true and all the elements that fail to satisfy it - * are copied to the range beginning at \p out_false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p InputIterator's \c value_type - * is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input range shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p partition_copy to separate a - * sequence into two output sequences of even and odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::partition_copy(thrust::host, A, A + N, evens, odds, is_even()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \note The relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition_copy, does guarantee to preserve the relative order. - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p stable_partition_copy - * \see \p partition - */ -template - thrust::pair - partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p partition_copy differs from \ref partition only in that the reordered - * sequence is written to difference output sequences, rather than in place. - * - * \p partition_copy copies the elements [first, last) based on the - * function object \p pred. All of the elements that satisfy \p pred are copied - * to the range beginning at \p out_true and all the elements that fail to satisfy it - * are copied to the range beginning at \p out_false. - * - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p InputIterator's \c value_type - * is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input range shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p partition_copy to separate a - * sequence into two output sequences of even and odd numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::partition_copy(A, A + N, evens, odds, is_even()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \note The relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition_copy, does guarantee to preserve the relative order. - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p stable_partition_copy - * \see \p partition - */ -template - thrust::pair - partition_copy(InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p partition_copy differs from \ref partition only in that the reordered - * sequence is written to difference output sequences, rather than in place. - * - * \p partition_copy copies the elements [first, last) based on the - * function object \p pred which is applied to a range of stencil elements. All of the elements - * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true - * and all the elements whose stencil element fails to satisfy it are copied to the range beginning - * at \p out_false. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input ranges shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p partition_copy to separate a - * sequence into two output sequences of even and odd numbers using the \p thrust::host execution - * policy for parallelization. - * - * \code - * #include - * #include - * #include - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::stable_partition_copy(thrust::host, A, A + N, S, evens, odds, thrust::identity()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \note The relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition_copy, does guarantee to preserve the relative order. - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p stable_partition_copy - * \see \p partition - */ -template - thrust::pair - partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p partition_copy differs from \ref partition only in that the reordered - * sequence is written to difference output sequences, rather than in place. - * - * \p partition_copy copies the elements [first, last) based on the - * function object \p pred which is applied to a range of stencil elements. All of the elements - * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true - * and all the elements whose stencil element fails to satisfy it are copied to the range beginning - * at \p out_false. - * - * \param first The beginning of the sequence to reorder. - * \param last The end of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input ranges shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p partition_copy to separate a - * sequence into two output sequences of even and odd numbers. - * - * \code - * #include - * #include - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::stable_partition_copy(A, A + N, S, evens, odds, thrust::identity()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \note The relative order of elements in the two reordered sequences is not - * necessarily the same as it was in the original sequence. A different algorithm, - * \ref stable_partition_copy, does guarantee to preserve the relative order. - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p stable_partition_copy - * \see \p partition - */ -template - thrust::pair - partition_copy(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p stable_partition is much like \ref partition : it reorders the elements in the - * range [first, last) based on the function object \p pred, such that all of - * the elements that satisfy \p pred precede all of the elements that fail to satisfy - * it. The postcondition is that, for some iterator \p middle in the range - * [first, last), pred(*i) is \c true for every iterator \c i in the - * range [first,middle) and \c false for every iterator \c i in the range - * [middle, last). The return value of \p stable_partition is \c middle. - * - * \p stable_partition differs from \ref partition in that \p stable_partition is - * guaranteed to preserve relative order. That is, if \c x and \c y are elements in - * [first, last), and \c stencil_x and \c stencil_y are the stencil elements - * in corresponding positions within [stencil, stencil + (last - first)), - * and pred(stencil_x) == pred(stencil_y), and if \c x precedes - * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements which do not satisfy pred. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, - * and \p ForwardIterator is mutable. - * \tparam Predicate is a model of Predicate. - * - * The following code snippet demonstrates how to use \p stable_partition to reorder a - * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::stable_partition(thrust::host, - * A, A + N, - * is_even()); - * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_partition.html - * \see \p partition - * \see \p stable_partition_copy - */ -template - ForwardIterator stable_partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p stable_partition is much like \ref partition : it reorders the elements in the - * range [first, last) based on the function object \p pred, such that all of - * the elements that satisfy \p pred precede all of the elements that fail to satisfy - * it. The postcondition is that, for some iterator \p middle in the range - * [first, last), pred(*i) is \c true for every iterator \c i in the - * range [first,middle) and \c false for every iterator \c i in the range - * [middle, last). The return value of \p stable_partition is \c middle. - * - * \p stable_partition differs from \ref partition in that \p stable_partition is - * guaranteed to preserve relative order. That is, if \c x and \c y are elements in - * [first, last), and \c stencil_x and \c stencil_y are the stencil elements - * in corresponding positions within [stencil, stencil + (last - first)), - * and pred(stencil_x) == pred(stencil_y), and if \c x precedes - * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. - * - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements which do not satisfy pred. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, - * and \p ForwardIterator is mutable. - * \tparam Predicate is a model of Predicate. - * - * The following code snippet demonstrates how to use \p stable_partition to reorder a - * sequence so that even numbers precede odd numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::stable_partition(A, A + N, - * is_even()); - * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_partition.html - * \see \p partition - * \see \p stable_partition_copy - */ -template - ForwardIterator stable_partition(ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p stable_partition is much like \p partition: it reorders the elements in the - * range [first, last) based on the function object \p pred applied to a stencil - * range [stencil, stencil + (last - first)), such that all of - * the elements whose corresponding stencil element satisfies \p pred precede all of the elements whose - * corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator - * \c middle in the range [first, last), pred(*stencil_i) is \c true for every iterator - * \c stencil_i in the range [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i - * in the range [stencil + (middle - first), stencil + (last - first)). - * The return value of \p stable_partition is \c middle. - * - * \p stable_partition differs from \ref partition in that \p stable_partition is - * guaranteed to preserve relative order. That is, if \c x and \c y are elements in - * [first, last), such that pred(x) == pred(y), and if \c x precedes - * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements whose stencil elements do not satisfy \p pred. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall not overlap with the range [stencil, stencil + (last - first)). - * - * The following code snippet demonstrates how to use \p stable_partition to reorder a - * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::stable_partition(thrust::host, A, A + N, S, is_even()); - * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * // S is unmodified - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_partition.html - * \see \p partition - * \see \p stable_partition_copy - */ -template - ForwardIterator stable_partition(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -/*! \p stable_partition is much like \p partition: it reorders the elements in the - * range [first, last) based on the function object \p pred applied to a stencil - * range [stencil, stencil + (last - first)), such that all of - * the elements whose corresponding stencil element satisfies \p pred precede all of the elements whose - * corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator - * \c middle in the range [first, last), pred(*stencil_i) is \c true for every iterator - * \c stencil_i in the range [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i - * in the range [stencil + (middle - first), stencil + (last - first)). - * The return value of \p stable_partition is \c middle. - * - * \p stable_partition differs from \ref partition in that \p stable_partition is - * guaranteed to preserve relative order. That is, if \c x and \c y are elements in - * [first, last), such that pred(x) == pred(y), and if \c x precedes - * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. - * - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return An iterator referring to the first element of the second partition, that is, - * the sequence of the elements whose stencil elements do not satisfy \p pred. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall not overlap with the range [stencil, stencil + (last - first)). - * - * The following code snippet demonstrates how to use \p stable_partition to reorder a - * sequence so that even numbers precede odd numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * const int N = sizeof(A)/sizeof(int); - * thrust::stable_partition(A, A + N, S, is_even()); - * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * // S is unmodified - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_partition.html - * \see \p partition - * \see \p stable_partition_copy - */ -template - ForwardIterator stable_partition(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -/*! \p stable_partition_copy differs from \ref stable_partition only in that the reordered - * sequence is written to different output sequences, rather than in place. - * - * \p stable_partition_copy copies the elements [first, last) based on the - * function object \p pred. All of the elements that satisfy \p pred are copied - * to the range beginning at \p out_true and all the elements that fail to satisfy it - * are copied to the range beginning at \p out_false. - * - * \p stable_partition_copy differs from \ref partition_copy in that - * \p stable_partition_copy is guaranteed to preserve relative order. That is, if - * \c x and \c y are elements in [first, last), such that - * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true - * after \p stable_partition_copy that \c x precedes \c y in the output. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p InputIterator's \c value_type - * is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input ranges shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p stable_partition_copy to - * reorder a sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::stable_partition_copy(thrust::host, A, A + N, evens, odds, is_even()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p partition_copy - * \see \p stable_partition - */ -template - thrust::pair - stable_partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p stable_partition_copy differs from \ref stable_partition only in that the reordered - * sequence is written to different output sequences, rather than in place. - * - * \p stable_partition_copy copies the elements [first, last) based on the - * function object \p pred. All of the elements that satisfy \p pred are copied - * to the range beginning at \p out_true and all the elements that fail to satisfy it - * are copied to the range beginning at \p out_false. - * - * \p stable_partition_copy differs from \ref partition_copy in that - * \p stable_partition_copy is guaranteed to preserve relative order. That is, if - * \c x and \c y are elements in [first, last), such that - * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true - * after \p stable_partition_copy that \c x precedes \c y in the output. - * - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p InputIterator's \c value_type - * is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input ranges shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p stable_partition_copy to - * reorder a sequence so that even numbers precede odd numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::stable_partition_copy(A, A + N, evens, odds, is_even()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p partition_copy - * \see \p stable_partition - */ -template - thrust::pair - stable_partition_copy(InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p stable_partition_copy differs from \ref stable_partition only in that the reordered - * sequence is written to different output sequences, rather than in place. - * - * \p stable_partition_copy copies the elements [first, last) based on the - * function object \p pred which is applied to a range of stencil elements. All of the elements - * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true - * and all the elements whose stencil element fails to satisfy it are copied to the range beginning - * at \p out_false. - * - * \p stable_partition_copy differs from \ref partition_copy in that - * \p stable_partition_copy is guaranteed to preserve relative order. That is, if - * \c x and \c y are elements in [first, last), such that - * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true - * after \p stable_partition_copy that \c x precedes \c y in the output. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input ranges shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p stable_partition_copy to - * reorder a sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::stable_partition_copy(thrust::host, A, A + N, S, evens, odds, thrust::identity()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p partition_copy - * \see \p stable_partition - */ -template - thrust::pair - stable_partition_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \p stable_partition_copy differs from \ref stable_partition only in that the reordered - * sequence is written to different output sequences, rather than in place. - * - * \p stable_partition_copy copies the elements [first, last) based on the - * function object \p pred which is applied to a range of stencil elements. All of the elements - * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true - * and all the elements whose stencil element fails to satisfy it are copied to the range beginning - * at \p out_false. - * - * \p stable_partition_copy differs from \ref partition_copy in that - * \p stable_partition_copy is guaranteed to preserve relative order. That is, if - * \c x and \c y are elements in [first, last), such that - * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true - * after \p stable_partition_copy that \c x precedes \c y in the output. - * - * \param first The first element of the sequence to reorder. - * \param last One position past the last element of the sequence to reorder. - * \param stencil The beginning of the stencil sequence. - * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. - * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. - * \param pred A function object which decides to which partition each element of the - * sequence [first, last) belongs. - * \return A \p pair p such that p.first is the end of the output range beginning - * at \p out_true and p.second is the end of the output range beginning at - * \p out_false. - * - * \tparam InputIterator1 is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The input ranges shall not overlap with either output range. - * - * The following code snippet demonstrates how to use \p stable_partition_copy to - * reorder a sequence so that even numbers precede odd numbers. - * - * \code - * #include - * #include - * ... - * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; - * int result[10]; - * const int N = sizeof(A)/sizeof(int); - * int *evens = result; - * int *odds = result + 5; - * thrust::stable_partition_copy(A, A + N, S, evens, odds, thrust::identity()); - * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} - * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - * // evens points to {2, 4, 6, 8, 10} - * // odds points to {1, 3, 5, 7, 9} - * \endcode - * - * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf - * \see \p partition_copy - * \see \p stable_partition - */ -template - thrust::pair - stable_partition_copy(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -/*! \} // end stream_compaction - */ - -/*! \} // end reordering - */ - -/*! \addtogroup searching - * \{ - */ - - -/*! \p partition_point returns an iterator pointing to the end of the true - * partition of a partitioned range. \p partition_point requires the input range - * [first,last) to be a partition; that is, all elements which satisfy - * pred shall appear before those that do not. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range to consider. - * \param last The end of the range to consider. - * \param pred A function object which decides to which partition each element of the - * range [first, last) belongs. - * \return An iterator \c mid such that all_of(first, mid, pred) - * and none_of(mid, last, pred) are both true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall be partitioned by \p pred. - * - * \note Though similar, \p partition_point is not redundant with \p find_if_not. - * \p partition_point's precondition provides an opportunity for a - * faster implemention. - * - * \code - * #include - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * - * ... - * - * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; - * int * B = thrust::partition_point(thrust::host, A, A + 10, is_even()); - * // B - A is 5 - * // [A, B) contains only even values - * \endcode - * - * \see \p partition - * \see \p find_if_not - */ -template - ForwardIterator partition_point(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p partition_point returns an iterator pointing to the end of the true - * partition of a partitioned range. \p partition_point requires the input range - * [first,last) to be a partition; that is, all elements which satisfy - * pred shall appear before those that do not. - * \param first The beginning of the range to consider. - * \param last The end of the range to consider. - * \param pred A function object which decides to which partition each element of the - * range [first, last) belongs. - * \return An iterator \c mid such that all_of(first, mid, pred) - * and none_of(mid, last, pred) are both true. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall be partitioned by \p pred. - * - * \note Though similar, \p partition_point is not redundant with \p find_if_not. - * \p partition_point's precondition provides an opportunity for a - * faster implemention. - * - * \code - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * - * ... - * - * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; - * int * B = thrust::partition_point(A, A + 10, is_even()); - * // B - A is 5 - * // [A, B) contains only even values - * \endcode - * - * \see \p partition - * \see \p find_if_not - */ -template - ForwardIterator partition_point(ForwardIterator first, - ForwardIterator last, - Predicate pred); - -/*! \} // searching - */ - -/*! \addtogroup reductions - * \{ - * \addtogroup predicates - * \{ - */ - - -/*! \p is_partitioned returns \c true if the given range - * is partitioned with respect to a predicate, and \c false otherwise. - * - * Specifically, \p is_partitioned returns \c true if [first, last) - * is empty of if [first, last) is partitioned by \p pred, i.e. if - * all elements that satisfy \p pred appear before those that do not. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range to consider. - * \param last The end of the range to consider. - * \param pred A function object which decides to which partition each element of the - * range [first, last) belongs. - * \return \c true if the range [first, last) is partitioned with respect - * to \p pred, or if [first, last) is empty. \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \code - * #include - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * - * ... - * - * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; - * int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * - * thrust::is_partitioned(thrust::host, A, A + 10); // returns true - * thrust::is_partitioned(thrust::host, B, B + 10); // returns false - * \endcode - * - * \see \p partition - */ -template - bool is_partitioned(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - Predicate pred); - - -/*! \p is_partitioned returns \c true if the given range - * is partitioned with respect to a predicate, and \c false otherwise. - * - * Specifically, \p is_partitioned returns \c true if [first, last) - * is empty of if [first, last) is partitioned by \p pred, i.e. if - * all elements that satisfy \p pred appear before those that do not. - * - * \param first The beginning of the range to consider. - * \param last The end of the range to consider. - * \param pred A function object which decides to which partition each element of the - * range [first, last) belongs. - * \return \c true if the range [first, last) is partitioned with respect - * to \p pred, or if [first, last) is empty. \c false, otherwise. - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \code - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int &x) - * { - * return (x % 2) == 0; - * } - * }; - * - * ... - * - * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; - * int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - * - * thrust::is_partitioned(A, A + 10); // returns true - * thrust::is_partitioned(B, B + 10); // returns false - * \endcode - * - * \see \p partition - */ -template - bool is_partitioned(InputIterator first, - InputIterator last, - Predicate pred); - - -/*! \} // end predicates - * \} // end reductions - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/random.h b/compat/thrust/random.h deleted file mode 100644 index 5a2c00d..0000000 --- a/compat/thrust/random.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file random.h - * \brief Pseudo-random number generators. - */ - -#pragma once - -#include -#include - -// RNGs -#include -#include -#include -#include -#include - -// distributions -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup random Random Number Generation - * \{ - */ - - -/*! \namespace thrust::random - * \brief \p thrust::random is the namespace which contains random number engine class templates, - * random number engine adaptor class templates, engines with predefined parameters, - * and random number distribution class templates. They are provided in a separate namespace - * for import convenience but are also aliased in the top-level \p thrust namespace for - * easy access. - */ -namespace random -{ - -/*! \addtogroup predefined_random Random Number Engines with Predefined Parameters - * \ingroup random - * \{ - */ - -/*! \typedef ranlux24 - * \brief A random number engine with predefined parameters which implements the - * RANLUX level-3 random number generation algorithm. - * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux24 - * shall produce the value \c 9901578 . - */ -typedef discard_block_engine ranlux24; - - -/*! \typedef ranlux48 - * \brief A random number engine with predefined parameters which implements the - * RANLUX level-4 random number generation algorithm. - * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux48 - * shall produce the value \c 88229545517833 . - */ -typedef discard_block_engine ranlux48; - - -/*! \typedef taus88 - * \brief A random number engine with predefined parameters which implements - * L'Ecuyer's 1996 three-component Tausworthe random number generator. - * - * \note The 10000th consecutive invocation of a default-constructed object of type \p taus88 - * shall produce the value \c 3535848941 . - */ -typedef xor_combine_engine< - linear_feedback_shift_engine, - 0, - xor_combine_engine< - linear_feedback_shift_engine, 0, - linear_feedback_shift_engine, 0 - >, - 0 -> taus88; - -/*! \typedef default_random_engine - * \brief An implementation-defined "default" random number engine. - * \note \p default_random_engine is currently an alias for \p minstd_rand, and may change - * in a future version. - */ -typedef minstd_rand default_random_engine; - -/*! \} // end predefined_random - */ - -} // end random - - -/*! \} // end random - */ - -// import names into thrust:: -using random::ranlux24; -using random::ranlux48; -using random::taus88; -using random::default_random_engine; - -} // end thrust - diff --git a/compat/thrust/random/detail/discard_block_engine.inl b/compat/thrust/random/detail/discard_block_engine.inl deleted file mode 100644 index 5f01bd1..0000000 --- a/compat/thrust/random/detail/discard_block_engine.inl +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace thrust -{ - -namespace random -{ - - -template - discard_block_engine - ::discard_block_engine() - : m_e(), m_n(0) -{} - - -template - discard_block_engine - ::discard_block_engine(result_type s) - : m_e(s), m_n(0) -{} - - -template - discard_block_engine - ::discard_block_engine(const base_type &urng) - : m_e(urng), m_n(0) -{} - - -template - void discard_block_engine - ::seed(void) -{ - m_e.seed(); - m_n = 0; -} - - -template - void discard_block_engine - ::seed(result_type s) -{ - m_e.seed(s); - m_n = 0; -} - - -template - typename discard_block_engine::result_type - discard_block_engine - ::operator()(void) -{ - if(m_n >= used_block) - { - m_e.discard(block_size - m_n); -// for(; m_n < block_size; ++m_n) -// m_e(); - m_n = 0; - } - - ++m_n; - - return m_e(); -} - - -template - void discard_block_engine - ::discard(unsigned long long z) -{ - // XXX this should be accelerated - for(; z > 0; --z) - { - this->operator()(); - } // end for -} - - -template - const typename discard_block_engine::base_type & - discard_block_engine - ::base(void) const -{ - return m_e; -} - - -template - template - std::basic_ostream& discard_block_engine - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags & fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - const CharT space = os.widen(' '); - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(space); - - // output the base engine followed by n - os << m_e << space << m_n; - - // restore flags & fill character - os.flags(flags); - os.fill(fill); - - return os; -} - - -template - template - std::basic_istream& discard_block_engine - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::skipws); - - // input the base engine and then n - is >> m_e >> m_n; - - // restore old flags - is.flags(flags); - return is; -} - - -template - bool discard_block_engine - ::equal(const discard_block_engine &rhs) const -{ - return (m_e == rhs.m_e) && (m_n == rhs.m_n); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const discard_block_engine &e) -{ - return thrust::random::detail::random_core_access::stream_out(os,e); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - discard_block_engine &e) -{ - return thrust::random::detail::random_core_access::stream_in(is,e); -} - - -template -bool operator==(const discard_block_engine &lhs, - const discard_block_engine &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const discard_block_engine &lhs, - const discard_block_engine &rhs) -{ - return !(lhs == rhs); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/linear_congruential_engine.inl b/compat/thrust/random/detail/linear_congruential_engine.inl deleted file mode 100644 index f040563..0000000 --- a/compat/thrust/random/detail/linear_congruential_engine.inl +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - - -template - linear_congruential_engine - ::linear_congruential_engine(result_type s) -{ - seed(s); -} // end linear_congruential_engine::linear_congruential_engine() - - -template - void linear_congruential_engine - ::seed(result_type s) -{ - if((detail::mod(c) == 0) && - (detail::mod(s) == 0)) - m_x = detail::mod(1); - else - m_x = detail::mod(s); -} // end linear_congruential_engine::seed() - - -template - typename linear_congruential_engine::result_type - linear_congruential_engine - ::operator()(void) -{ - m_x = detail::mod(m_x); - return m_x; -} // end linear_congruential_engine::operator()() - - -template - void linear_congruential_engine - ::discard(unsigned long long z) -{ - thrust::random::detail::linear_congruential_engine_discard::discard(*this,z); -} // end linear_congruential_engine::discard() - - -template - template - std::basic_ostream& linear_congruential_engine - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags & fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(os.widen(' ')); - - // output one word of state - os << m_x; - - // restore flags & fill character - os.flags(flags); - os.fill(fill); - - return os; -} - - -template - template - std::basic_istream& linear_congruential_engine - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::dec); - - // input one word of state - is >> m_x; - - // restore flags - is.flags(flags); - - return is; -} - - -template -bool linear_congruential_engine - ::equal(const linear_congruential_engine &rhs) const -{ - return m_x == rhs.m_x; -} - - -template -__host__ __device__ -bool operator==(const linear_congruential_engine &lhs, - const linear_congruential_engine &rhs) -{ - return detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const linear_congruential_engine &lhs, - const linear_congruential_engine &rhs) -{ - return !(lhs == rhs); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const linear_congruential_engine &e) -{ - return detail::random_core_access::stream_out(os,e); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - linear_congruential_engine &e) -{ - return detail::random_core_access::stream_in(is,e); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/linear_congruential_engine_discard.h b/compat/thrust/random/detail/linear_congruential_engine_discard.h deleted file mode 100644 index f4ec233..0000000 --- a/compat/thrust/random/detail/linear_congruential_engine_discard.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace random -{ - -namespace detail -{ - - -template - struct linear_congruential_engine_discard_implementation -{ - __host__ __device__ - static void discard(UIntType &state, unsigned long long z) - { - for(; z > 0; --z) - { - state = detail::mod(state); - } - } -}; // end linear_congruential_engine_discard - - -// specialize for small integers and c == 0 -// XXX figure out a robust implemenation of this for any unsigned integer type later -template - struct linear_congruential_engine_discard_implementation -{ - __host__ __device__ - static void discard(thrust::detail::uint32_t &state, unsigned long long z) - { - const thrust::detail::uint32_t modulus = m; - - // XXX we need to use unsigned long long here or we will encounter overflow in the - // multiplies below - // figure out a robust implementation of this later - unsigned long long multiplier = a; - unsigned long long multiplier_to_z = 1; - - // see http://en.wikipedia.org/wiki/Modular_exponentiation - while(z > 0) - { - if(z & 1) - { - // multiply in this bit's contribution while using modulus to keep result small - multiplier_to_z = (multiplier_to_z * multiplier) % modulus; - } - - // move to the next bit of the exponent, square (and mod) the base accordingly - z >>= 1; - multiplier = (multiplier * multiplier) % modulus; - } - - state = static_cast((multiplier_to_z * state) % modulus); - } -}; // end linear_congruential_engine_discard - - -struct linear_congruential_engine_discard -{ - template - __host__ __device__ - static void discard(LinearCongruentialEngine &lcg, unsigned long long z) - { - typedef typename LinearCongruentialEngine::result_type result_type; - const result_type c = LinearCongruentialEngine::increment; - const result_type a = LinearCongruentialEngine::multiplier; - const result_type m = LinearCongruentialEngine::modulus; - - // XXX WAR unused variable warnings - (void) c; - (void) a; - (void) m; - - linear_congruential_engine_discard_implementation::discard(lcg.m_x, z); - } -}; // end linear_congruential_engine_discard - - -} // end detail - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/linear_feedback_shift_engine.inl b/compat/thrust/random/detail/linear_feedback_shift_engine.inl deleted file mode 100644 index 4e8dad5..0000000 --- a/compat/thrust/random/detail/linear_feedback_shift_engine.inl +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace thrust -{ - -namespace random -{ - -template - linear_feedback_shift_engine - ::linear_feedback_shift_engine(result_type value) -{ - seed(value); -} // end linear_feedback_shift_engine::linear_feedback_shift_engine() - -template - void linear_feedback_shift_engine - ::seed(result_type value) -{ - m_value = value; -} // end linear_feedback_shift_engine::seed() - -template - typename linear_feedback_shift_engine::result_type - linear_feedback_shift_engine - ::operator()(void) -{ - const UIntType b = (((m_value << q) ^ m_value) & wordmask) >> (k-s); - const UIntType mask = ( (~static_cast(0)) << (w-k) ) & wordmask; - m_value = ((m_value & mask) << s) ^ b; - return m_value; -} // end linear_feedback_shift_engine::operator()() - - -template - void linear_feedback_shift_engine - ::discard(unsigned long long z) -{ - for(; z > 0; --z) - { - this->operator()(); - } // end for -} // end linear_feedback_shift_engine::discard() - - -template - template - std::basic_ostream& linear_feedback_shift_engine - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags & fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(os.widen(' ')); - - // output one word of state - os << m_value; - - // restore flags & fill character - os.flags(flags); - os.fill(fill); - - return os; -} - - -template - template - std::basic_istream& linear_feedback_shift_engine - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::skipws); - - // input one word of state - is >> m_value; - - // restore flags - is.flags(flags); - - return is; -} - - -template - bool linear_feedback_shift_engine - ::equal(const linear_feedback_shift_engine &rhs) const -{ - return m_value == rhs.m_value; -} - - -template -bool operator==(const linear_feedback_shift_engine &lhs, - const linear_feedback_shift_engine &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const linear_feedback_shift_engine &lhs, - const linear_feedback_shift_engine &rhs) -{ - return !(lhs == rhs); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const linear_feedback_shift_engine &e) -{ - return thrust::random::detail::random_core_access::stream_out(os,e); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - linear_feedback_shift_engine &e) -{ - return thrust::random::detail::random_core_access::stream_in(is,e); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/linear_feedback_shift_engine_wordmask.h b/compat/thrust/random/detail/linear_feedback_shift_engine_wordmask.h deleted file mode 100644 index ed9e51e..0000000 --- a/compat/thrust/random/detail/linear_feedback_shift_engine_wordmask.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace thrust -{ - -namespace random -{ - -namespace detail -{ - -template - struct linear_feedback_shift_engine_wordmask -{ - static const T value = - (T(1u) << i) | - linear_feedback_shift_engine_wordmask::value; -}; // end linear_feedback_shift_engine_wordmask - -template - struct linear_feedback_shift_engine_wordmask -{ - static const T value = 0; -}; // end linear_feedback_shift_engine_wordmask - -} // end detail - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/mod.h b/compat/thrust/random/detail/mod.h deleted file mode 100644 index ceb2191..0000000 --- a/compat/thrust/random/detail/mod.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace thrust -{ - -namespace random -{ - -namespace detail -{ - -template - struct static_mod -{ - static const T q = m / a; - static const T r = m % a; - - __host__ __device__ - T operator()(T x) const - { - if(a == 1) - { - x %= m; - } - else - { - T t1 = a * (x % q); - T t2 = r * (x / q); - if(t1 >= t2) - { - x = t1 - t2; - } - else - { - x = m - t2 + t1; - } - } - - if(c != 0) - { - const T d = m - x; - if(d > c) - { - x += c; - } - else - { - x = c - d; - } - } - - return x; - } -}; // end static_mod - - -// Rely on machine overflow handling -template - struct static_mod -{ - __host__ __device__ - T operator()(T x) const - { - return a * x + c; - } -}; // end static_mod - -template -__host__ __device__ - T mod(T x) -{ - static_mod f; - return f(x); -} // end static_mod - -} // end detail - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/normal_distribution.inl b/compat/thrust/random/detail/normal_distribution.inl deleted file mode 100644 index 1bb55d7..0000000 --- a/compat/thrust/random/detail/normal_distribution.inl +++ /dev/null @@ -1,241 +0,0 @@ -/* - * - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// for floating point infinity -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC -#include -#else -#include -#endif - -namespace thrust -{ - -namespace random -{ - - -template - normal_distribution - ::normal_distribution(RealType a, RealType b) - :super_t(),m_param(a,b) -{ -} // end normal_distribution::normal_distribution() - - -template - normal_distribution - ::normal_distribution(const param_type &parm) - :super_t(),m_param(parm) -{ -} // end normal_distribution::normal_distribution() - - -template - void normal_distribution - ::reset(void) -{ - super_t::reset(); -} // end normal_distribution::reset() - - -template - template - typename normal_distribution::result_type - normal_distribution - ::operator()(UniformRandomNumberGenerator &urng) -{ - return operator()(urng, m_param); -} // end normal_distribution::operator()() - - -template - template - typename normal_distribution::result_type - normal_distribution - ::operator()(UniformRandomNumberGenerator &urng, - const param_type &parm) -{ - return super_t::sample(urng, parm.first, parm.second); -} // end normal_distribution::operator()() - - -template - typename normal_distribution::param_type - normal_distribution - ::param(void) const -{ - return m_param; -} // end normal_distribution::param() - - -template - void normal_distribution - ::param(const param_type &parm) -{ - m_param = parm; -} // end normal_distribution::param() - - -template - typename normal_distribution::result_type - normal_distribution - ::min THRUST_PREVENT_MACRO_SUBSTITUTION (void) const -{ - return -this->max(); -} // end normal_distribution::min() - - -template - typename normal_distribution::result_type - normal_distribution - ::max THRUST_PREVENT_MACRO_SUBSTITUTION (void) const -{ - // XXX this solution is pretty terrible - // we can't use numeric_traits::max because nvcc will - // complain that it is a __host__ function - union - { - thrust::detail::uint32_t inf_as_int; - float result; - } hack; - - hack.inf_as_int = 0x7f800000u; - - return hack.result; -} // end normal_distribution::max() - - -template - typename normal_distribution::result_type - normal_distribution - ::mean(void) const -{ - return m_param.first; -} // end normal_distribution::mean() - - -template - typename normal_distribution::result_type - normal_distribution - ::stddev(void) const -{ - return m_param.second; -} // end normal_distribution::stddev() - - -template - bool normal_distribution - ::equal(const normal_distribution &rhs) const -{ - return m_param == rhs.param(); -} - - -template - template - std::basic_ostream& - normal_distribution - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags and fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - const CharT space = os.widen(' '); - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(space); - - os << mean() << space << stddev(); - - // restore old flags and fill character - os.flags(flags); - os.fill(fill); - return os; -} - - -template - template - std::basic_istream& - normal_distribution - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::skipws); - - is >> m_param.first >> m_param.second; - - // restore old flags - is.flags(flags); - return is; -} - - -template -bool operator==(const normal_distribution &lhs, - const normal_distribution &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const normal_distribution &lhs, - const normal_distribution &rhs) -{ - return !(lhs == rhs); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const normal_distribution &d) -{ - return thrust::random::detail::random_core_access::stream_out(os,d); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - normal_distribution &d) -{ - return thrust::random::detail::random_core_access::stream_in(is,d); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/normal_distribution_base.h b/compat/thrust/random/detail/normal_distribution_base.h deleted file mode 100644 index d916611..0000000 --- a/compat/thrust/random/detail/normal_distribution_base.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Copyright Jens Maurer 2000-2001 - * Distributed under the Boost Software License, Version 1.0. (See - * accompanying file LICENSE_1_0.txt or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace random -{ -namespace detail -{ - -// this version samples the normal distribution directly -// and uses the non-standard math function erfcinv -template - class normal_distribution_nvcc -{ - protected: - template - __host__ __device__ - RealType sample(UniformRandomNumberGenerator &urng, const RealType mean, const RealType stddev) - { - typedef typename UniformRandomNumberGenerator::result_type uint_type; - const uint_type urng_range = UniformRandomNumberGenerator::max - UniformRandomNumberGenerator::min; - - // Constants for conversion - const RealType S1 = static_cast(1) / urng_range; - const RealType S2 = S1 / 2; - - RealType S3 = static_cast(-1.4142135623730950488016887242097); // -sqrt(2) - - // Get the integer value - uint_type u = urng() - UniformRandomNumberGenerator::min; - - // Ensure the conversion to float will give a value in the range [0,0.5) - if(u > (urng_range / 2)) - { - u = urng_range - u; - S3 = -S3; - } - - // Convert to floating point in [0,0.5) - RealType p = u*S1 + S2; - - // Apply inverse error function - return mean + stddev * S3 * erfcinv(2 * p); - } - - // no-op - __host__ __device__ - void reset() {} -}; - -// this version samples the normal distribution using -// Marsaglia's "polar method" -template - class normal_distribution_portable -{ - protected: - normal_distribution_portable() - : m_valid(false) - {} - - normal_distribution_portable(const normal_distribution_portable &other) - : m_valid(other.m_valid) - {} - - void reset() - { - m_valid = false; - } - - // note that we promise to call this member function with the same mean and stddev - template - __host__ __device__ - RealType sample(UniformRandomNumberGenerator &urng, const RealType mean, const RealType stddev) - { - // implementation from Boost - // allow for Koenig lookup - using std::sqrt; using std::log; using std::sin; using std::cos; - - if(!m_valid) - { - uniform_real_distribution u01; - m_r1 = u01(urng); - m_r2 = u01(urng); - m_cached_rho = sqrt(-RealType(2) * log(RealType(1)-m_r2)); - - m_valid = true; - } - else - { - m_valid = false; - } - - const RealType pi = RealType(3.14159265358979323846); - - RealType result = m_cached_rho * (m_valid ? - cos(RealType(2)*pi*m_r1) : - sin(RealType(2)*pi*m_r1)); - - return result; - } - - private: - RealType m_r1, m_r2, m_cached_rho; - bool m_valid; -}; - -template - struct normal_distribution_base -{ -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - typedef normal_distribution_nvcc type; -#else - typedef normal_distribution_portable type; -#endif -}; - -} // end detail -} // end random -} // end thrust - diff --git a/compat/thrust/random/detail/random_core_access.h b/compat/thrust/random/detail/random_core_access.h deleted file mode 100644 index 81f58e2..0000000 --- a/compat/thrust/random/detail/random_core_access.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace thrust -{ - -namespace random -{ - -namespace detail -{ - -struct random_core_access -{ - -template -static OStream &stream_out(OStream &os, const EngineOrDistribution &x) -{ - return x.stream_out(os); -} - -template -static IStream &stream_in(IStream &is, EngineOrDistribution &x) -{ - return x.stream_in(is); -} - -template -__host__ __device__ -static bool equal(const EngineOrDistribution &lhs, const EngineOrDistribution &rhs) -{ - return lhs.equal(rhs); -} - -}; // end random_core_access - -} // end detail - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/subtract_with_carry_engine.inl b/compat/thrust/random/detail/subtract_with_carry_engine.inl deleted file mode 100644 index a58b266..0000000 --- a/compat/thrust/random/detail/subtract_with_carry_engine.inl +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - - -template - subtract_with_carry_engine - ::subtract_with_carry_engine(result_type value) -{ - seed(value); -} // end subtract_with_carry_engine::subtract_with_carry_engine() - - -template - void subtract_with_carry_engine - ::seed(result_type value) -{ - thrust::random::linear_congruential_engine e(value == 0u ? default_seed : value); - - // initialize state - for(size_t i = 0; i < long_lag; ++i) - { - m_x[i] = detail::mod(e()); - } // end for i - - m_carry = (m_x[long_lag-1] == 0); - m_k = 0; -} // end subtract_with_carry_engine::seed() - - -template - typename subtract_with_carry_engine::result_type - subtract_with_carry_engine - ::operator()(void) -{ - // XXX we probably need to cache these m_x[m_k] in a register - // maybe we need to cache the use of all member variables - int short_index = m_k - short_lag; - if(short_index < 0) - short_index += long_lag; - result_type xi; - if (m_x[short_index] >= m_x[m_k] + m_carry) - { - // x(n) >= 0 - xi = m_x[short_index] - m_x[m_k] - m_carry; - m_carry = 0; - } - else - { - // x(n) < 0 - xi = modulus - m_x[m_k] - m_carry + m_x[short_index]; - m_carry = 1; - } - m_x[m_k] = xi; - ++m_k; - if(m_k >= long_lag) - m_k = 0; - return xi; -} // end subtract_with_carry_engine::operator()() - - -template - void subtract_with_carry_engine - ::discard(unsigned long long z) -{ - for(; z > 0; --z) - { - this->operator()(); - } // end for -} // end subtract_with_carry_engine::discard() - - -template - template - std::basic_ostream& subtract_with_carry_engine - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - const CharT space = os.widen(' '); - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(space); - - const UIntType long_lag = r; - - for(size_t i = 0; i < r; ++i) - os << m_x[(i + m_k) % long_lag] << space; - os << m_carry; - - os.flags(flags); - os.fill(fill); - return os; -} - - -template - template - std::basic_istream& subtract_with_carry_engine - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - const typename ios_base::fmtflags flags = is.flags(); - is.flags(ios_base::dec | ios_base::skipws); - - for(size_t i = 0; i < r; ++i) - is >> m_x[i]; - is >> m_carry; - - m_k = 0; - - is.flags(flags); - return is; -} - - -template - bool subtract_with_carry_engine - ::equal(const subtract_with_carry_engine &rhs) const -{ - const UIntType long_lag = r; - - bool result = true; - for(size_t i = 0; i < r; ++i) - { - result &= (m_x[(i + m_k) % long_lag] == rhs.m_x[(i + rhs.m_k) % long_lag]); - } - - // XXX not sure if this last check is necessary - result &= (m_carry == rhs.m_carry); - - return result; -} - - -template - std::basic_ostream& - operator<<(std::basic_ostream &os, - const subtract_with_carry_engine &e) -{ - return thrust::random::detail::random_core_access::stream_out(os,e); -} - - -template - std::basic_istream& - operator>>(std::basic_istream &is, - subtract_with_carry_engine &e) -{ - return thrust::random::detail::random_core_access::stream_in(is,e); -} - - -template - bool operator==(const subtract_with_carry_engine &lhs, - const subtract_with_carry_engine &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template - bool operator!=(const subtract_with_carry_engine &lhs, - const subtract_with_carry_engine &rhs) -{ - return !(lhs == rhs); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/uniform_int_distribution.inl b/compat/thrust/random/detail/uniform_int_distribution.inl deleted file mode 100644 index e92754c..0000000 --- a/compat/thrust/random/detail/uniform_int_distribution.inl +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - - -template - uniform_int_distribution - ::uniform_int_distribution(IntType a, IntType b) - :m_param(a,b) -{ -} // end uniform_int_distribution::uniform_int_distribution() - - -template - uniform_int_distribution - ::uniform_int_distribution(const param_type &parm) - :m_param(parm) -{ -} // end uniform_int_distribution::uniform_int_distribution() - - -template - void uniform_int_distribution - ::reset(void) -{ -} // end uniform_int_distribution::reset() - - -template - template - typename uniform_int_distribution::result_type - uniform_int_distribution - ::operator()(UniformRandomNumberGenerator &urng) -{ - return operator()(urng, m_param); -} // end uniform_int_distribution::operator()() - - -template - template - typename uniform_int_distribution::result_type - uniform_int_distribution - ::operator()(UniformRandomNumberGenerator &urng, const param_type &parm) -{ - // XXX this implementation is somewhat hacky and will skip - // values if the range of the RNG is smaller than the range of the distribution - // we should improve this implementation in a later version - - typedef typename thrust::detail::largest_available_float::type float_type; - - const float_type real_min(parm.first); - const float_type real_max(parm.second); - - // add one to the right end of the interval because it is half-open - // XXX adding 1.0 to a potentially large floating point number seems like a bad idea - uniform_real_distribution real_dist(real_min, real_max + float_type(1)); - - return static_cast(real_dist(urng)); -} // end uniform_int_distribution::operator()() - - -template - typename uniform_int_distribution::result_type - uniform_int_distribution - ::a(void) const -{ - return m_param.first; -} // end uniform_int_distribution::a() - - -template - typename uniform_int_distribution::result_type - uniform_int_distribution - ::b(void) const -{ - return m_param.second; -} // end uniform_int_distribution::b() - - -template - typename uniform_int_distribution::param_type - uniform_int_distribution - ::param(void) const -{ - return m_param; -} // end uniform_int_distribution::param() - - -template - void uniform_int_distribution - ::param(const param_type &parm) -{ - m_param = parm; -} // end uniform_int_distribution::param() - - -template - typename uniform_int_distribution::result_type - uniform_int_distribution - ::min THRUST_PREVENT_MACRO_SUBSTITUTION (void) const -{ - return a(); -} // end uniform_int_distribution::min() - - -template - typename uniform_int_distribution::result_type - uniform_int_distribution - ::max THRUST_PREVENT_MACRO_SUBSTITUTION (void) const -{ - return b(); -} // end uniform_int_distribution::max() - - -template - bool uniform_int_distribution - ::equal(const uniform_int_distribution &rhs) const -{ - return param() == rhs.param(); -} - - -template - template - std::basic_ostream& - uniform_int_distribution - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags and fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - const CharT space = os.widen(' '); - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(space); - - os << a() << space << b(); - - // restore old flags and fill character - os.flags(flags); - os.fill(fill); - return os; -} - - -template - template - std::basic_istream& - uniform_int_distribution - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::skipws); - - is >> m_param.first >> m_param.second; - - // restore old flags - is.flags(flags); - return is; -} - - -template -bool operator==(const uniform_int_distribution &lhs, - const uniform_int_distribution &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const uniform_int_distribution &lhs, - const uniform_int_distribution &rhs) -{ - return !(lhs == rhs); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const uniform_int_distribution &d) -{ - return thrust::random::detail::random_core_access::stream_out(os,d); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - uniform_int_distribution &d) -{ - return thrust::random::detail::random_core_access::stream_in(is,d); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/uniform_real_distribution.inl b/compat/thrust/random/detail/uniform_real_distribution.inl deleted file mode 100644 index 6f6d6b5..0000000 --- a/compat/thrust/random/detail/uniform_real_distribution.inl +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace thrust -{ - -namespace random -{ - - -template - uniform_real_distribution - ::uniform_real_distribution(RealType a, RealType b) - :m_param(a,b) -{ -} // end uniform_real_distribution::uniform_real_distribution() - -template - uniform_real_distribution - ::uniform_real_distribution(const param_type &parm) - :m_param(parm) -{ -} // end uniform_real_distribution::uniform_real_distribution() - -template - void uniform_real_distribution - ::reset(void) -{ -} // end uniform_real_distribution::reset() - -template - template - typename uniform_real_distribution::result_type - uniform_real_distribution - ::operator()(UniformRandomNumberGenerator &urng) -{ - return operator()(urng, m_param); -} // end uniform_real::operator()() - -template - template - typename uniform_real_distribution::result_type - uniform_real_distribution - ::operator()(UniformRandomNumberGenerator &urng, - const param_type &parm) -{ - // call the urng & map its result to [0,1) - result_type result = static_cast(urng() - UniformRandomNumberGenerator::min); - - // adding one to the denominator ensures that the interval is half-open at 1.0 - // XXX adding 1.0 to a potentially large floating point number seems like a bad idea - // XXX OTOH adding 1 to what is potentially UINT_MAX also seems like a bad idea - // XXX we could statically check if 1u + (max - min) is representable and do that, otherwise use the current implementation - result /= (result_type(1) + static_cast(UniformRandomNumberGenerator::max - UniformRandomNumberGenerator::min)); - - return (result * (parm.second - parm.first)) + parm.first; -} // end uniform_real::operator()() - -template - typename uniform_real_distribution::result_type - uniform_real_distribution - ::a(void) const -{ - return m_param.first; -} // end uniform_real::a() - -template - typename uniform_real_distribution::result_type - uniform_real_distribution - ::b(void) const -{ - return m_param.second; -} // end uniform_real_distribution::b() - -template - typename uniform_real_distribution::param_type - uniform_real_distribution - ::param(void) const -{ - return m_param;; -} // end uniform_real_distribution::param() - -template - void uniform_real_distribution - ::param(const param_type &parm) -{ - m_param = parm; -} // end uniform_real_distribution::param() - -template - typename uniform_real_distribution::result_type - uniform_real_distribution - ::min THRUST_PREVENT_MACRO_SUBSTITUTION (void) const -{ - return a(); -} // end uniform_real_distribution::min() - -template - typename uniform_real_distribution::result_type - uniform_real_distribution - ::max THRUST_PREVENT_MACRO_SUBSTITUTION (void) const -{ - return b(); -} // end uniform_real_distribution::max() - - -template - bool uniform_real_distribution - ::equal(const uniform_real_distribution &rhs) const -{ - return m_param == rhs.param(); -} - - -template - template - std::basic_ostream& - uniform_real_distribution - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags and fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - const CharT space = os.widen(' '); - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(space); - - os << a() << space << b(); - - // restore old flags and fill character - os.flags(flags); - os.fill(fill); - return os; -} - - -template - template - std::basic_istream& - uniform_real_distribution - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::skipws); - - is >> m_param.first >> m_param.second; - - // restore old flags - is.flags(flags); - return is; -} - - -template -bool operator==(const uniform_real_distribution &lhs, - const uniform_real_distribution &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const uniform_real_distribution &lhs, - const uniform_real_distribution &rhs) -{ - return !(lhs == rhs); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const uniform_real_distribution &d) -{ - return thrust::random::detail::random_core_access::stream_out(os,d); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - uniform_real_distribution &d) -{ - return thrust::random::detail::random_core_access::stream_in(is,d); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/xor_combine_engine.inl b/compat/thrust/random/detail/xor_combine_engine.inl deleted file mode 100644 index b138722..0000000 --- a/compat/thrust/random/detail/xor_combine_engine.inl +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace thrust -{ - -namespace random -{ - -template - xor_combine_engine - ::xor_combine_engine(void) - :m_b1(),m_b2() -{ -} // end xor_combine_engine::xor_combine_engine() - -template - xor_combine_engine - ::xor_combine_engine(const base1_type &urng1, const base2_type &urng2) - :m_b1(urng1),m_b2(urng2) -{ -} // end xor_combine_engine::xor_combine_engine() - -template - xor_combine_engine - ::xor_combine_engine(result_type s) - :m_b1(s),m_b2(s) -{ -} // end xor_combine_engine::xor_combine_engine() - -template - void xor_combine_engine - ::seed(void) -{ - m_b1.seed(); - m_b2.seed(); -} // end xor_combine_engine::seed() - -template - void xor_combine_engine - ::seed(result_type s) -{ - m_b1.seed(s); - m_b2.seed(s); -} // end xor_combine_engine::seed() - -template - const typename xor_combine_engine::base1_type & - xor_combine_engine - ::base1(void) const -{ - return m_b1; -} // end xor_combine_engine::base1() - -template - const typename xor_combine_engine::base2_type & - xor_combine_engine - ::base2(void) const -{ - return m_b2; -} // end xor_combine_engine::base2() - -template - typename xor_combine_engine::result_type - xor_combine_engine - ::operator()(void) -{ - return (result_type(m_b1() - base1_type::min) << shift1) ^ - (result_type(m_b2() - base2_type::min) << shift2); -} // end xor_combine_engine::operator()() - -template - void xor_combine_engine - ::discard(unsigned long long z) -{ - for(; z > 0; --z) - { - this->operator()(); - } // end for -} // end xor_combine_engine::discard() - - -template - template - std::basic_ostream& xor_combine_engine - ::stream_out(std::basic_ostream &os) const -{ - typedef std::basic_ostream ostream_type; - typedef typename ostream_type::ios_base ios_base; - - // save old flags and fill character - const typename ios_base::fmtflags flags = os.flags(); - const CharT fill = os.fill(); - - const CharT space = os.widen(' '); - os.flags(ios_base::dec | ios_base::fixed | ios_base::left); - os.fill(space); - - // output each base engine in turn - os << base1() << space << base2(); - - // restore old flags and fill character - os.flags(flags); - os.fill(fill); - return os; -} - - -template - template - std::basic_istream& xor_combine_engine - ::stream_in(std::basic_istream &is) -{ - typedef std::basic_istream istream_type; - typedef typename istream_type::ios_base ios_base; - - // save old flags - const typename ios_base::fmtflags flags = is.flags(); - - is.flags(ios_base::skipws); - - // input each base engine in turn - is >> m_b1 >> m_b2; - - // restore old flags - is.flags(flags); - return is; -} - - -template - bool xor_combine_engine - ::equal(const xor_combine_engine &rhs) const -{ - return (m_b1 == rhs.m_b1) && (m_b2 == rhs.m_b2); -} - - -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const xor_combine_engine &e) -{ - return thrust::random::detail::random_core_access::stream_out(os,e); -} - - -template -std::basic_istream& -operator>>(std::basic_istream &is, - xor_combine_engine &e) -{ - return thrust::random::detail::random_core_access::stream_in(is,e); -} - - -template -bool operator==(const xor_combine_engine &lhs, - const xor_combine_engine &rhs) -{ - return thrust::random::detail::random_core_access::equal(lhs,rhs); -} - - -template -bool operator!=(const xor_combine_engine &lhs, - const xor_combine_engine &rhs) -{ - return !(lhs == rhs); -} - - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/detail/xor_combine_engine_max.h b/compat/thrust/random/detail/xor_combine_engine_max.h deleted file mode 100644 index 8bad9a4..0000000 --- a/compat/thrust/random/detail/xor_combine_engine_max.h +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - -namespace detail -{ - - -namespace math = thrust::detail::mpl::math; - - -namespace detail -{ - -// two cases for this function avoids compile-time warnings of overflow -template - struct lshift_w -{ - static const UIntType value = 0; -}; - - -template - struct lshift_w -{ - static const UIntType value = lhs << rhs; -}; - -} // end detail - - -template - struct lshift_w -{ - static const bool shift_will_overflow = rhs >= w; - - static const UIntType value = detail::lshift_w::value; -}; - - -template - struct lshift - : lshift_w::digits, lhs, rhs> -{}; - - -template - struct two_to_the_power - : lshift -{}; - - -template - class xor_combine_engine_max_aux_constants -{ - public: - static const result_type two_to_the_d = two_to_the_power::value; - static const result_type c = lshift::value; - - static const result_type t = - math::max< - result_type, - c, - b - >::value; - - static const result_type u = - math::min< - result_type, - c, - b - >::value; - - static const result_type p = math::log2::value; - static const result_type two_to_the_p = two_to_the_power::value; - - static const result_type k = math::div::value; -}; - - -template struct xor_combine_engine_max_aux; - - -template - struct xor_combine_engine_max_aux_case4 -{ - typedef xor_combine_engine_max_aux_constants constants; - - static const result_type k_plus_1_times_two_to_the_p = - lshift< - result_type, - math::plus::value, - constants::p - >::value; - - static const result_type M = - xor_combine_engine_max_aux< - result_type, - math::div< - result_type, - math::mod< - result_type, - constants::u, - constants::two_to_the_p - >::value, - constants::two_to_the_p - >::value, - math::mod< - result_type, - constants::t, - constants::two_to_the_p - >::value, - d - >::value; - - static const result_type value = math::plus::value; -}; - - -template - struct xor_combine_engine_max_aux_case3 -{ - typedef xor_combine_engine_max_aux_constants constants; - - static const result_type k_plus_1_times_two_to_the_p = - lshift< - result_type, - math::plus::value, - constants::p - >::value; - - static const result_type M = - xor_combine_engine_max_aux< - result_type, - math::div< - result_type, - math::mod< - result_type, - constants::t, - constants::two_to_the_p - >::value, - constants::two_to_the_p - >::value, - math::mod< - result_type, - constants::u, - constants::two_to_the_p - >::value, - d - >::value; - - static const result_type value = math::plus::value; -}; - - - -template - struct xor_combine_engine_max_aux_case2 -{ - typedef xor_combine_engine_max_aux_constants constants; - - static const result_type k_plus_1_times_two_to_the_p = - lshift< - result_type, - math::plus::value, - constants::p - >::value; - - static const result_type value = - math::minus< - result_type, - k_plus_1_times_two_to_the_p, - 1 - >::value; -}; - - -template - struct xor_combine_engine_max_aux_case1 -{ - static const result_type c = lshift::value; - - static const result_type value = math::plus::value; -}; - - -template - struct xor_combine_engine_max_aux_2 -{ - typedef xor_combine_engine_max_aux_constants constants; - - static const result_type value = - thrust::detail::eval_if< - // if k is odd... - math::is_odd::value, - thrust::detail::identity_< - thrust::detail::integral_constant< - result_type, - xor_combine_engine_max_aux_case2::value - > - >, - thrust::detail::eval_if< - // otherwise if a * 2^3 >= b, then case 3 - a * constants::two_to_the_d >= b, - thrust::detail::identity_< - thrust::detail::integral_constant< - result_type, - xor_combine_engine_max_aux_case3::value - > - >, - // otherwise, case 4 - thrust::detail::identity_< - thrust::detail::integral_constant< - result_type, - xor_combine_engine_max_aux_case4::value - > - > - > - >::type::value; -}; - - -template::value)> - struct xor_combine_engine_max_aux_1 - : xor_combine_engine_max_aux_case1 -{}; - - -template - struct xor_combine_engine_max_aux_1 - : xor_combine_engine_max_aux_2 -{}; - - -template - struct xor_combine_engine_max_aux - : xor_combine_engine_max_aux_1 -{}; - - -template - struct xor_combine_engine_max -{ - static const size_t w = std::numeric_limits::digits; - - static const result_type m1 = - math::min< - result_type, - result_type(Engine1::max - Engine1::min), - two_to_the_power::value - 1 - >::value; - - static const result_type m2 = - math::min< - result_type, - result_type(Engine2::max - Engine2::min), - two_to_the_power::value - 1 - >::value; - - static const result_type s = s1 - s2; - - static const result_type M = - xor_combine_engine_max_aux< - result_type, - m1, - m2, - s - >::value; - - // the value is M(m1,m2,s) lshift_w s2 - static const result_type value = - lshift_w< - result_type, - w, - M, - s2 - >::value; -}; // end xor_combine_engine_max - -} // end detail - -} // end random - -} // end thrust - diff --git a/compat/thrust/random/discard_block_engine.h b/compat/thrust/random/discard_block_engine.h deleted file mode 100644 index c902c58..0000000 --- a/compat/thrust/random/discard_block_engine.h +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file discard_block_engine.h - * \brief A random number engine which adapts a base engine and produces - * numbers by discarding all but a contiguous blocks of its values. - */ - -#pragma once - -#include - -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - -/*! \addtogroup random_number_engine_adaptors Random Number Engine Adaptor Class Templates - * \ingroup random - * \{ - */ - -/*! \class discard_block_engine - * \brief A \p discard_block_engine adapts an existing base random number engine and produces - * random values by discarding some of the values returned by its base engine. - * Each cycle of the compound engine begins by returning \c r values successively produced - * by the base engine and ends by discarding p-r such values. The engine's state - * is the state of its base engine followed by the number of calls to operator() - * that have occurred since the beginning of the current cycle. - * - * \tparam Engine The type of the base random number engine to adapt. - * \tparam p The discard cycle length. - * \tparam r The number of values to return of the base engine. Because p-r will be - * discarded, r <= p. - * - * The following code snippet shows an example of using a \p discard_block_engine instance: - * - * \code - * #include - * #include - * #include - * - * int main(void) - * { - * // create a discard_block_engine from minstd_rand, with a cycle length of 13 - * // keep every first 10 values, and discard the next 3 - * thrust::discard_block_engine rng; - * - * // print a random number to standard output - * std::cout << rng() << std::endl; - * - * return 0; - * } - * \endcode - */ -template - class discard_block_engine -{ - public: - // types - - /*! \typedef base_type - * \brief The type of the adapted base random number engine. - */ - typedef Engine base_type; - - /*! \typedef result_type - * \brief The type of the unsigned integer produced by this \p linear_congruential_engine. - */ - typedef typename base_type::result_type result_type; - - // engine characteristics - - /*! The length of the production cycle. - */ - static const size_t block_size = p; - - /*! The number of used numbers per production cycle. - */ - static const size_t used_block = r; - - /*! The smallest value this \p discard_block_engine may potentially produce. - */ - static const result_type min = base_type::min; - - /*! The largest value this \p discard_block_engine may potentially produce. - */ - static const result_type max = base_type::max; - - // constructors and seeding functions - - /*! This constructor constructs a new \p discard_block_engine and constructs - * its \p base_type engine using its null constructor. - */ - __host__ __device__ - discard_block_engine(); - - /*! This constructor constructs a new \p discard_block_engine using - * a given \p base_type engine to initialize its adapted base engine. - * - * \param urng A \p base_type to use to initialize this \p discard_block_engine's - * adapted base engine. - */ - __host__ __device__ - explicit discard_block_engine(const base_type &urng); - - /*! This constructor initializes a new \p discard_block_engine with a given seed. - * - * \param s The seed used to intialize this \p discard_block_engine's adapted base engine. - */ - __host__ __device__ - explicit discard_block_engine(result_type s); - - /*! This method initializes the state of this \p discard_block_engine's adapted base engine - * by using its \p default_seed value. - */ - __host__ __device__ - void seed(void); - - /*! This method initializes the state of this \p discard_block_engine's adapted base engine - * by using the given seed. - * - * \param s The seed with which to intialize this \p discard_block_engine's adapted base engine. - */ - __host__ __device__ - void seed(result_type s); - - // generating functions - - /*! This member function produces a new random value and updates this \p discard_block_engine's state. - * \return A new random number. - */ - __host__ __device__ - result_type operator()(void); - - /*! This member function advances this \p discard_block_engine's state a given number of times - * and discards the results. - * - * \param z The number of random values to discard. - * \note This function is provided because an implementation may be able to accelerate it. - */ - __host__ __device__ - void discard(unsigned long long z); - - // property functions - - /*! This member function returns a const reference to this \p discard_block_engine's - * adapted base engine. - * - * \return A const reference to the base engine this \p discard_block_engine adapts. - */ - __host__ __device__ - const base_type &base(void) const; - - /*! \cond - */ - private: - base_type m_e; - unsigned int m_n; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const discard_block_engine &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - /*! \endcond - */ -}; // end discard_block_engine - - -/*! This function checks two \p discard_block_engines for equality. - * \param lhs The first \p discard_block_engine to test. - * \param rhs The second \p discard_block_engine to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const discard_block_engine &lhs, - const discard_block_engine &rhs); - - -/*! This function checks two \p discard_block_engines for inequality. - * \param lhs The first \p discard_block_engine to test. - * \param rhs The second \p discard_block_engine to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const discard_block_engine &lhs, - const discard_block_engine &rhs); - - -/*! This function streams a discard_block_engine to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param e The \p discard_block_engine to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const discard_block_engine &e); - - -/*! This function streams a discard_block_engine in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param e The \p discard_block_engine to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - discard_block_engine &e); - -/*! \} // end random_number_engine_adaptors - */ - -} // end random - -// import names into thrust:: -using random::discard_block_engine; - -} // end thrust - -#include - diff --git a/compat/thrust/random/linear_congruential_engine.h b/compat/thrust/random/linear_congruential_engine.h deleted file mode 100644 index 0added0..0000000 --- a/compat/thrust/random/linear_congruential_engine.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file linear_congruential_engine.h - * \brief A linear congruential pseudorandom number engine. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - -/*! \addtogroup random_number_engine_templates Random Number Engine Class Templates - * \ingroup random - * \{ - */ - -/*! \class linear_congruential_engine - * \brief A \p linear_congruential_engine random number engine produces unsigned integer - * random numbers using a linear congruential random number generation algorithm. - * - * The generation algorithm has the form x_i = (a * x_{i-1} + c) mod m. - * - * \tparam UIntType The type of unsigned integer to produce. - * \tparam a The multiplier used in the generation algorithm. - * \tparam c The increment used in the generation algorithm. - * \tparam m The modulus used in the generation algorithm. - * - * \note Inexperienced users should not use this class template directly. Instead, use - * \p minstd_rand or \p minstd_rand0. - * - * The following code snippet shows examples of use of a \p linear_congruential_engine instance: - * - * \code - * #include - * #include - * - * int main(void) - * { - * // create a minstd_rand object, which is an instance of linear_congruential_engine - * thrust::minstd_rand rng1; - * - * // output some random values to cout - * std::cout << rng1() << std::endl; - * - * // a random value is printed - * - * // create a new minstd_rand from a seed - * thrust::minstd_rand rng2(13); - * - * // discard some random values - * rng2.discard(13); - * - * // stream the object to an iostream - * std::cout << rng2 << std::endl; - * - * // rng2's current state is printed - * - * // print the minimum and maximum values that minstd_rand can produce - * std::cout << thrust::minstd_rand::min << std::endl; - * std::cout << thrust::minstd_rand::max << std::endl; - * - * // the range of minstd_rand is printed - * - * // save the state of rng2 to a different object - * thrust::minstd_rand rng3 = rng2; - * - * // compare rng2 and rng3 - * std::cout << (rng2 == rng3) << std::endl; - * - * // 1 is printed - * - * // re-seed rng2 with a different seed - * rng2.seed(7); - * - * // compare rng2 and rng3 - * std::cout << (rng2 == rng3) << std::endl; - * - * // 0 is printed - * - * return 0; - * } - * - * \endcode - * - * \see thrust::random::minstd_rand - * \see thrust::random::minstd_rand0 - */ -template - class linear_congruential_engine -{ - public: - // types - - /*! \typedef result_type - * \brief The type of the unsigned integer produced by this \p linear_congruential_engine. - */ - typedef UIntType result_type; - - // engine characteristics - - /*! The multiplier used in the generation algorithm. - */ - static const result_type multiplier = a; - - /*! The increment used in the generation algorithm. - */ - static const result_type increment = c; - - /*! The modulus used in the generation algorithm. - */ - static const result_type modulus = m; - - /*! The smallest value this \p linear_congruential_engine may potentially produce. - */ - static const result_type min = c == 0u ? 1u : 0u; - - /*! The largest value this \p linear_congruential_engine may potentially produce. - */ - static const result_type max = m - 1u; - - /*! The default seed of this \p linear_congruential_engine. - */ - static const result_type default_seed = 1u; - - // constructors and seeding functions - - /*! This constructor, which optionally accepts a seed, initializes a new - * \p linear_congruential_engine. - * - * \param s The seed used to intialize this \p linear_congruential_engine's state. - */ - __host__ __device__ - explicit linear_congruential_engine(result_type s = default_seed); - - /*! This method initializes this \p linear_congruential_engine's state, and optionally accepts - * a seed value. - * - * \param s The seed used to initializes this \p linear_congruential_engine's state. - */ - __host__ __device__ - void seed(result_type s = default_seed); - - // generating functions - - /*! This member function produces a new random value and updates this \p linear_congruential_engine's state. - * \return A new random number. - */ - __host__ __device__ - result_type operator()(void); - - /*! This member function advances this \p linear_congruential_engine's state a given number of times - * and discards the results. - * - * \param z The number of random values to discard. - * \note This function is provided because an implementation may be able to accelerate it. - */ - __host__ __device__ - void discard(unsigned long long z); - - /*! \cond - */ - private: - result_type m_x; - - static void transition(result_type &state); - - friend struct thrust::random::detail::random_core_access; - - friend struct thrust::random::detail::linear_congruential_engine_discard; - - __host__ __device__ - bool equal(const linear_congruential_engine &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - - /*! \endcond - */ -}; // end linear_congruential_engine - - -/*! This function checks two \p linear_congruential_engines for equality. - * \param lhs The first \p linear_congruential_engine to test. - * \param rhs The second \p linear_congruential_engine to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const linear_congruential_engine &lhs, - const linear_congruential_engine &rhs); - - -/*! This function checks two \p linear_congruential_engines for inequality. - * \param lhs The first \p linear_congruential_engine to test. - * \param rhs The second \p linear_congruential_engine to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const linear_congruential_engine &lhs, - const linear_congruential_engine &rhs); - - -/*! This function streams a linear_congruential_engine to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param e The \p linear_congruential_engine to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const linear_congruential_engine &e); - - -/*! This function streams a linear_congruential_engine in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param e The \p linear_congruential_engine to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - linear_congruential_engine &e); - - -/*! \} // random_number_engine_templates - */ - - -/*! \addtogroup predefined_random - * \{ - */ - -// XXX the type N2111 used here was uint_fast32_t - -/*! \typedef minstd_rand0 - * \brief A random number engine with predefined parameters which implements a version of - * the Minimal Standard random number generation algorithm. - * \note The 10000th consecutive invocation of a default-constructed object of type \p minstd_rand0 - * shall produce the value \c 1043618065 . - */ -typedef linear_congruential_engine minstd_rand0; - - -/*! \typedef minstd_rand - * \brief A random number engine with predefined parameters which implements a version of - * the Minimal Standard random number generation algorithm. - * \note The 10000th consecutive invocation of a default-constructed object of type \p minstd_rand - * shall produce the value \c 399268537 . - */ -typedef linear_congruential_engine minstd_rand; - -/*! \} // predefined_random - */ - -} // end random - -// import names into thrust:: -using random::linear_congruential_engine; -using random::minstd_rand; -using random::minstd_rand0; - -} // end thrust - -#include - diff --git a/compat/thrust/random/linear_feedback_shift_engine.h b/compat/thrust/random/linear_feedback_shift_engine.h deleted file mode 100644 index f5646c9..0000000 --- a/compat/thrust/random/linear_feedback_shift_engine.h +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file linear_feedback_shift_engine.h - * \brief A linear feedback shift pseudorandom number generator. - */ - -/* - * Copyright Jens Maurer 2002 - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include -#include // for size_t -#include - -namespace thrust -{ - - -namespace random -{ - -/*! \addtogroup random_number_engine_templates - * \{ - */ - -/*! \class linear_feedback_shift_engine - * \brief A \p linear_feedback_shift_engine random number engine produces - * unsigned integer random values using a linear feedback shift random number - * generation algorithm. - * - * \tparam UIntType The type of unsigned integer to produce. - * \tparam w The word size of the produced values (w <= sizeof(UIntType)). - * \tparam k The k parameter of Tausworthe's 1965 algorithm. - * \tparam q The q exponent of Tausworthe's 1965 algorithm. - * \tparam s The step size of Tausworthe's 1965 algorithm. - * - * \note linear_feedback_shift_engine is based on the Boost Template Library's linear_feedback_shift. - */ -template - class linear_feedback_shift_engine -{ - public: - // types - - /*! \typedef result_type - * \brief The type of the unsigned integer produced by this \p linear_feedback_shift_engine. - */ - typedef UIntType result_type; - - // engine characteristics - - /*! The word size of the produced values. - */ - static const size_t word_size = w; - - /*! A constant used in the generation algorithm. - */ - static const size_t exponent1 = k; - - /*! A constant used in the generation algorithm. - */ - static const size_t exponent2 = q; - - /*! The step size used in the generation algorithm. - */ - static const size_t step_size = s; - - /*! \cond - */ - private: - static const result_type wordmask = - detail::linear_feedback_shift_engine_wordmask< - result_type, - w - >::value; - /*! \endcond - */ - - public: - - /*! The smallest value this \p linear_feedback_shift_engine may potentially produce. - */ - static const result_type min = 0; - - /*! The largest value this \p linear_feedback_shift_engine may potentially produce. - */ - static const result_type max = wordmask; - - /*! The default seed of this \p linear_feedback_shift_engine. - */ - static const result_type default_seed = 341u; - - // constructors and seeding functions - - /*! This constructor, which optionally accepts a seed, initializes a new - * \p linear_feedback_shift_engine. - * - * \param value The seed used to intialize this \p linear_feedback_shift_engine's state. - */ - __host__ __device__ - explicit linear_feedback_shift_engine(result_type value = default_seed); - - /*! This method initializes this \p linear_feedback_shift_engine's state, and optionally accepts - * a seed value. - * - * \param value The seed used to initializes this \p linear_feedback_shift_engine's state. - */ - __host__ __device__ - void seed(result_type value = default_seed); - - // generating functions - - /*! This member function produces a new random value and updates this \p linear_feedback_shift_engine's state. - * \return A new random number. - */ - __host__ __device__ - result_type operator()(void); - - /*! This member function advances this \p linear_feedback_shift_engine's state a given number of times - * and discards the results. - * - * \param z The number of random values to discard. - * \note This function is provided because an implementation may be able to accelerate it. - */ - __host__ __device__ - void discard(unsigned long long z); - - /*! \cond - */ - private: - result_type m_value; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const linear_feedback_shift_engine &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - - /*! \endcond - */ -}; // end linear_feedback_shift_engine - - -/*! This function checks two \p linear_feedback_shift_engines for equality. - * \param lhs The first \p linear_feedback_shift_engine to test. - * \param rhs The second \p linear_feedback_shift_engine to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const linear_feedback_shift_engine &lhs, - const linear_feedback_shift_engine &rhs); - - -/*! This function checks two \p linear_feedback_shift_engines for inequality. - * \param lhs The first \p linear_feedback_shift_engine to test. - * \param rhs The second \p linear_feedback_shift_engine to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const linear_feedback_shift_engine &lhs, - const linear_feedback_shift_engine &rhs); - - -/*! This function streams a linear_feedback_shift_engine to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param e The \p linear_feedback_shift_engine to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const linear_feedback_shift_engine &e); - - -/*! This function streams a linear_feedback_shift_engine in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param e The \p linear_feedback_shift_engine to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - linear_feedback_shift_engine &e); - - -/*! \} // end random_number_engine_templates - */ - - -} // end random - -// import names into thrust:: -using random::linear_feedback_shift_engine; - -} // end thrust - -#include - diff --git a/compat/thrust/random/normal_distribution.h b/compat/thrust/random/normal_distribution.h deleted file mode 100644 index 5543f30..0000000 --- a/compat/thrust/random/normal_distribution.h +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file normal_distribution.h - * \brief A normal (Gaussian) distribution of real-valued numbers. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - - -/*! \addtogroup random_number_distributions - * \{ - */ - -/*! \class normal_distribution - * \brief A \p normal_distribution random number distribution produces floating point - * Normally distributed random numbers. - * - * \tparam RealType The type of floating point number to produce. - * - * The following code snippet demonstrates examples of using a \p normal_distribution with a - * random number engine to produce random values drawn from the Normal distribution with a given - * mean and variance: - * - * \code - * #include - * #include - * - * int main(void) - * { - * // create a minstd_rand object to act as our source of randomness - * thrust::minstd_rand rng; - * - * // create a normal_distribution to produce floats from the Normal distribution - * // with mean 2.0 and standard deviation 3.5 - * thrust::random::normal_distribution dist(2.0f, 3.5f); - * - * // write a random number to standard output - * std::cout << dist(rng) << std::endl; - * - * // write the mean of the distribution, just in case we forgot - * std::cout << dist.mean() << std::endl; - * - * // 2.0 is printed - * - * // and the standard deviation - * std::cout << dist.stddev() << std::endl; - * - * // 3.5 is printed - * - * return 0; - * } - * \endcode - */ -template - class normal_distribution - : public detail::normal_distribution_base::type -{ - private: - typedef typename detail::normal_distribution_base::type super_t; - - public: - // types - - /*! \typedef result_type - * \brief The type of the floating point number produced by this \p normal_distribution. - */ - typedef RealType result_type; - - /*! \typedef param_type - * \brief The type of the object encapsulating this \p normal_distribution's parameters. - */ - typedef thrust::pair param_type; - - // constructors and reset functions - - /*! This constructor creates a new \p normal_distribution from two values defining the - * half-open interval of the distribution. - * - * \param mean The mean (expected value) of the distribution. Defaults to \c 0.0. - * \param stddev The standard deviation of the distribution. Defaults to \c 1.0. - */ - __host__ __device__ - explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0); - - /*! This constructor creates a new \p normal_distribution from a \p param_type object - * encapsulating the range of the distribution. - * - * \param parm A \p param_type object encapsulating the parameters (i.e., the mean and standard deviation) of the distribution. - */ - __host__ __device__ - explicit normal_distribution(const param_type &parm); - - /*! Calling this member function guarantees that subsequent uses of this - * \p normal_distribution do not depend on values produced by any random - * number generator prior to invoking this function. - */ - __host__ __device__ - void reset(void); - - // generating functions - - /*! This method produces a new Normal random integer drawn from this \p normal_distribution's - * range using a \p UniformRandomNumberGenerator as a source of randomness. - * - * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness. - */ - template - __host__ __device__ - result_type operator()(UniformRandomNumberGenerator &urng); - - /*! This method produces a new Normal random integer as if by creating a new \p normal_distribution - * from the given \p param_type object, and calling its operator() method with the given - * \p UniformRandomNumberGenerator as a source of randomness. - * - * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness. - * \param parm A \p param_type object encapsulating the parameters of the \p normal_distribution - * to draw from. - */ - template - __host__ __device__ - result_type operator()(UniformRandomNumberGenerator &urng, const param_type &parm); - - // property functions - - /*! This method returns the value of the parameter with which this \p normal_distribution - * was constructed. - * - * \return The mean (expected value) of this \p normal_distribution's output. - */ - __host__ __device__ - result_type mean(void) const; - - /*! This method returns the value of the parameter with which this \p normal_distribution - * was constructed. - * - * \return The standard deviation of this \p uniform_real_distribution's output. - */ - __host__ __device__ - result_type stddev(void) const; - - /*! This method returns a \p param_type object encapsulating the parameters with which this - * \p normal_distribution was constructed. - * - * \return A \p param_type object encapsulating the parameters (i.e., the mean and standard deviation) of this \p normal_distribution. - */ - __host__ __device__ - param_type param(void) const; - - /*! This method changes the parameters of this \p normal_distribution using the values encapsulated - * in a given \p param_type object. - * - * \param parm A \p param_type object encapsulating the new parameters (i.e., the mean and variance) of this \p normal_distribution. - */ - __host__ __device__ - void param(const param_type &parm); - - /*! This method returns the smallest floating point number this \p normal_distribution can potentially produce. - * - * \return The lower bound of this \p normal_distribution's half-open interval. - */ - __host__ __device__ - result_type min THRUST_PREVENT_MACRO_SUBSTITUTION (void) const; - - /*! This method returns the smallest number larger than largest floating point number this \p uniform_real_distribution can potentially produce. - * - * \return The upper bound of this \p normal_distribution's half-open interval. - */ - __host__ __device__ - result_type max THRUST_PREVENT_MACRO_SUBSTITUTION (void) const; - - /*! \cond - */ - private: - param_type m_param; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const normal_distribution &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - /*! \endcond - */ -}; // end normal_distribution - - -/*! This function checks two \p normal_distributions for equality. - * \param lhs The first \p normal_distribution to test. - * \param rhs The second \p normal_distribution to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const normal_distribution &lhs, - const normal_distribution &rhs); - - -/*! This function checks two \p normal_distributions for inequality. - * \param lhs The first \p normal_distribution to test. - * \param rhs The second \p normal_distribution to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const normal_distribution &lhs, - const normal_distribution &rhs); - - -/*! This function streams a normal_distribution to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param d The \p normal_distribution to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const normal_distribution &d); - - -/*! This function streams a normal_distribution in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param d The \p normal_distribution to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - normal_distribution &d); - - -/*! \} // end random_number_distributions - */ - - -} // end random - -using random::normal_distribution; - -} // end thrust - -#include - diff --git a/compat/thrust/random/subtract_with_carry_engine.h b/compat/thrust/random/subtract_with_carry_engine.h deleted file mode 100644 index b888100..0000000 --- a/compat/thrust/random/subtract_with_carry_engine.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file subtract_with_carry_engine.h - * \brief A subtract-with-carry pseudorandom number generator - * based on Marsaglia & Zaman. - */ - -#pragma once - -#include -#include - -#include -#include // for size_t -#include - -namespace thrust -{ - -namespace random -{ - - -/*! \addtogroup random_number_engine_templates - * \{ - */ - -/*! \class subtract_with_carry_engine - * \brief A \p subtract_with_carry_engine random number engine produces unsigned - * integer random numbers using the subtract with carry algorithm of Marsaglia & Zaman. - * - * The generation algorithm is performed as follows: - * -# Let Y = X_{i-s}- X_{i-r} - c. - * -# Set X_i to y = T mod m. Set \c c to \c 1 if Y < 0, otherwise set \c c to \c 0. - * - * This algorithm corresponds to a modular linear function of the form - * - * TA(x_i) = (a * x_i) mod b, where \c b is of the form m^r - m^s + 1 and - * a = b - (b-1)/m. - * - * \tparam UIntType The type of unsigned integer to produce. - * \tparam w The word size of the produced values ( w <= sizeof(UIntType)). - * \tparam s The short lag of the generation algorithm. - * \tparam r The long lag of the generation algorithm. - * - * \note Inexperienced users should not use this class template directly. Instead, use - * \p ranlux24_base or \p ranlux48_base, which are instances of \p subtract_with_carry_engine. - * - * \see thrust::random::ranlux24_base - * \see thrust::random::ranlux48_base - */ -template - class subtract_with_carry_engine -{ - /*! \cond - */ - private: - static const UIntType modulus = UIntType(1) << w; - /*! \endcond - */ - - public: - // types - - /*! \typedef result_type - * \brief The type of the unsigned integer produced by this \p subtract_with_carry_engine. - */ - typedef UIntType result_type; - - // engine characteristics - - /*! The word size of the produced values. - */ - static const size_t word_size = w; - - /*! The size of the short lag used in the generation algorithm. - */ - static const size_t short_lag = s; - - /*! The size of the long lag used in the generation algorithm. - */ - static const size_t long_lag = r; - - /*! The smallest value this \p subtract_with_carry_engine may potentially produce. - */ - static const result_type min = 0; - - /*! The largest value this \p subtract_with_carry_engine may potentially produce. - */ - static const result_type max = modulus - 1; - - /*! The default seed of this \p subtract_with_carry_engine. - */ - static const result_type default_seed = 19780503u; - - // constructors and seeding functions - - /*! This constructor, which optionally accepts a seed, initializes a new - * \p subtract_with_carry_engine. - * - * \param value The seed used to intialize this \p subtract_with_carry_engine's state. - */ - __host__ __device__ - explicit subtract_with_carry_engine(result_type value = default_seed); - - /*! This method initializes this \p subtract_with_carry_engine's state, and optionally accepts - * a seed value. - * - * \param value The seed used to initializes this \p subtract_with_carry_engine's state. - */ - __host__ __device__ - void seed(result_type value = default_seed); - - // generating functions - - /*! This member function produces a new random value and updates this \p subtract_with_carry_engine's state. - * \return A new random number. - */ - __host__ __device__ - result_type operator()(void); - - /*! This member function advances this \p subtract_with_carry_engine's state a given number of times - * and discards the results. - * - * \param z The number of random values to discard. - * \note This function is provided because an implementation may be able to accelerate it. - */ - __host__ __device__ - void discard(unsigned long long z); - - /*! \cond - */ - private: - result_type m_x[long_lag]; - unsigned int m_k; - int m_carry; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const subtract_with_carry_engine &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - - /*! \endcond - */ -}; // end subtract_with_carry_engine - - -/*! This function checks two \p subtract_with_carry_engines for equality. - * \param lhs The first \p subtract_with_carry_engine to test. - * \param rhs The second \p subtract_with_carry_engine to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const subtract_with_carry_engine &lhs, - const subtract_with_carry_engine &rhs); - - -/*! This function checks two \p subtract_with_carry_engines for inequality. - * \param lhs The first \p subtract_with_carry_engine to test. - * \param rhs The second \p subtract_with_carry_engine to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const subtract_with_carry_engine&lhs, - const subtract_with_carry_engine&rhs); - - -/*! This function streams a subtract_with_carry_engine to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param e The \p subtract_with_carry_engine to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const subtract_with_carry_engine &e); - - -/*! This function streams a subtract_with_carry_engine in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param e The \p subtract_with_carry_engine to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - subtract_with_carry_engine &e); - - -/*! \} // end random_number_engine_templates - */ - - -/*! \addtogroup predefined_random - * \{ - */ - -// XXX N2111 uses uint_fast32_t here - -/*! \typedef ranlux24_base - * \brief A random number engine with predefined parameters which implements the - * base engine of the \p ranlux24 random number engine. - * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux24_base - * shall produce the value \c 7937952 . - */ -typedef subtract_with_carry_engine ranlux24_base; - - -// XXX N2111 uses uint_fast64_t here - -/*! \typedef ranlux48_base - * \brief A random number engine with predefined parameters which implements the - * base engine of the \p ranlux48 random number engine. - * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux48_base - * shall produce the value \c 192113843633948 . - */ -typedef subtract_with_carry_engine ranlux48_base; - -/*! \} // end predefined_random - */ - -} // end random - -// import names into thrust:: -using random::subtract_with_carry_engine; -using random::ranlux24_base; -using random::ranlux48_base; - -} // end thrust - -#include - diff --git a/compat/thrust/random/uniform_int_distribution.h b/compat/thrust/random/uniform_int_distribution.h deleted file mode 100644 index d05f7fa..0000000 --- a/compat/thrust/random/uniform_int_distribution.h +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file uniform_int_distribution.h - * \brief A uniform distribution of integer-valued numbers - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - -/*! \addtogroup random_number_distributions Random Number Distributions Class Templates - * \ingroup random - * \{ - */ - -/*! \class uniform_int_distribution - * \brief A \p uniform_int_distribution random number distribution produces signed or unsigned integer - * uniform random numbers from a given range. - * - * \tparam IntType The type of integer to produce. - * - * The following code snippet demonstrates examples of using a \p uniform_int_distribution with a - * random number engine to produce random integers drawn from a given range: - * - * \code - * #include - * #include - * - * int main(void) - * { - * // create a minstd_rand object to act as our source of randomness - * thrust::minstd_rand rng; - * - * // create a uniform_int_distribution to produce ints from [-7,13] - * thrust::uniform_int_distribution dist(-7,13); - * - * // write a random number from the range [-7,13] to standard output - * std::cout << dist(rng) << std::endl; - * - * // write the range of the distribution, just in case we forgot - * std::cout << dist.min() << std::endl; - * - * // -7 is printed - * - * std::cout << dist.max() << std::endl; - * - * // 13 is printed - * - * // write the parameters of the distribution (which happen to be the bounds) to standard output - * std::cout << dist.a() << std::endl; - * - * // -7 is printed - * - * std::cout << dist.b() << std::endl; - * - * // 13 is printed - * - * return 0; - * } - * \endcode - */ -template - class uniform_int_distribution -{ - public: - // types - - /*! \typedef result_type - * \brief The type of the integer produced by this \p uniform_int_distribution. - */ - typedef IntType result_type; - - /*! \typedef param_type - * \brief The type of the object encapsulating this \p uniform_int_distribution's parameters. - */ - typedef thrust::pair param_type; - - // constructors and reset functions - - /*! This constructor creates a new \p uniform_int_distribution from two values defining the - * range of the distribution. - * - * \param a The smallest integer to potentially produce. Defaults to \c 0. - * \param b The largest integer to potentially produce. Defaults to the largest representable integer in - * the platform. - */ - __host__ __device__ - explicit uniform_int_distribution(IntType a = 0, IntType b = thrust::detail::integer_traits::const_max); - - /*! This constructor creates a new \p uniform_int_distribution from a \p param_type object - * encapsulating the range of the distribution. - * - * \param parm A \p param_type object encapsulating the parameters (i.e., the range) of the distribution. - */ - __host__ __device__ - explicit uniform_int_distribution(const param_type &parm); - - /*! This does nothing. It is included to conform to the requirements of the RandomDistribution concept. - */ - __host__ __device__ - void reset(void); - - // generating functions - - /*! This method produces a new uniform random integer drawn from this \p uniform_int_distribution's - * range using a \p UniformRandomNumberGenerator as a source of randomness. - * - * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness. - */ - template - __host__ __device__ - result_type operator()(UniformRandomNumberGenerator &urng); - - /*! This method produces a new uniform random integer as if by creating a new \p uniform_int_distribution - * from the given \p param_type object, and calling its operator() method with the given - * \p UniformRandomNumberGenerator as a source of randomness. - * - * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness. - * \param parm A \p param_type object encapsulating the parameters of the \p uniform_int_distribution - * to draw from. - */ - template - __host__ __device__ - result_type operator()(UniformRandomNumberGenerator &urng, const param_type &parm); - - // property functions - - /*! This method returns the value of the parameter with which this \p uniform_int_distribution - * was constructed. - * - * \return The lower bound of this \p uniform_int_distribution's range. - */ - __host__ __device__ - result_type a(void) const; - - /*! This method returns the value of the parameter with which this \p uniform_int_distribution - * was constructed. - * - * \return The upper bound of this \p uniform_int_distribution's range. - */ - __host__ __device__ - result_type b(void) const; - - /*! This method returns a \p param_type object encapsulating the parameters with which this - * \p uniform_int_distribution was constructed. - * - * \return A \p param_type object enapsulating the range of this \p uniform_int_distribution. - */ - __host__ __device__ - param_type param(void) const; - - /*! This method changes the parameters of this \p uniform_int_distribution using the values encapsulated - * in a given \p param_type object. - * - * \param parm A \p param_type object encapsulating the new range of this \p uniform_int_distribution. - */ - __host__ __device__ - void param(const param_type &parm); - - /*! This method returns the smallest integer this \p uniform_int_distribution can potentially produce. - * - * \return The lower bound of this \p uniform_int_distribution's range. - */ - __host__ __device__ - result_type min THRUST_PREVENT_MACRO_SUBSTITUTION (void) const; - - /*! This method returns the largest integer this \p uniform_int_distribution can potentially produce. - * - * \return The upper bound of this \p uniform_int_distribution's range. - */ - __host__ __device__ - result_type max THRUST_PREVENT_MACRO_SUBSTITUTION (void) const; - - /*! \cond - */ - private: - param_type m_param; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const uniform_int_distribution &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - /*! \endcond - */ -}; // end uniform_int_distribution - - -/*! This function checks two \p uniform_int_distributions for equality. - * \param lhs The first \p uniform_int_distribution to test. - * \param rhs The second \p uniform_int_distribution to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const uniform_int_distribution &lhs, - const uniform_int_distribution &rhs); - - -/*! This function checks two \p uniform_int_distributions for inequality. - * \param lhs The first \p uniform_int_distribution to test. - * \param rhs The second \p uniform_int_distribution to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const uniform_int_distribution &lhs, - const uniform_int_distribution &rhs); - - -/*! This function streams a uniform_int_distribution to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param d The \p uniform_int_distribution to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const uniform_int_distribution &d); - - -/*! This function streams a uniform_int_distribution in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param d The \p uniform_int_distribution to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - uniform_int_distribution &d); - - -/*! \} // end random_number_distributions - */ - - -} // end random - -using random::uniform_int_distribution; - -} // end thrust - -#include - diff --git a/compat/thrust/random/uniform_real_distribution.h b/compat/thrust/random/uniform_real_distribution.h deleted file mode 100644 index ab85ab3..0000000 --- a/compat/thrust/random/uniform_real_distribution.h +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file uniform_real_distribution.h - * \brief A uniform distribution of real-valued numbers - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace random -{ - - -/*! \addtogroup random_number_distributions - * \{ - */ - -/*! \class uniform_real_distribution - * \brief A \p uniform_real_distribution random number distribution produces floating point - * uniform random numbers from a half-open interval. - * - * \tparam RealType The type of floating point number to produce. - * - * The following code snippet demonstrates examples of using a \p uniform_real_distribution with a - * random number engine to produce random integers drawn from a given range: - * - * \code - * #include - * #include - * - * int main(void) - * { - * // create a minstd_rand object to act as our source of randomness - * thrust::minstd_rand rng; - * - * // create a uniform_real_distribution to produce floats from [-7,13) - * thrust::uniform_real_distribution dist(-7,13); - * - * // write a random number from the range [-7,13) to standard output - * std::cout << dist(rng) << std::endl; - * - * // write the range of the distribution, just in case we forgot - * std::cout << dist.min() << std::endl; - * - * // -7.0 is printed - * - * std::cout << dist.max() << std::endl; - * - * // 13.0 is printed - * - * // write the parameters of the distribution (which happen to be the bounds) to standard output - * std::cout << dist.a() << std::endl; - * - * // -7.0 is printed - * - * std::cout << dist.b() << std::endl; - * - * // 13.0 is printed - * - * return 0; - * } - * \endcode - */ -template - class uniform_real_distribution -{ - public: - // types - - /*! \typedef result_type - * \brief The type of the floating point number produced by this \p uniform_real_distribution. - */ - typedef RealType result_type; - - /*! \typedef param_type - * \brief The type of the object encapsulating this \p uniform_real_distribution's parameters. - */ - typedef thrust::pair param_type; - - // constructors and reset functions - - /*! This constructor creates a new \p uniform_real_distribution from two values defining the - * half-open interval of the distribution. - * - * \param a The smallest floating point number to potentially produce. Defaults to \c 0.0. - * \param b The smallest number larger than the largest floating point number to potentially produce. Defaults to \c 1.0. - */ - __host__ __device__ - explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); - - /*! This constructor creates a new \p uniform_real_distribution from a \p param_type object - * encapsulating the range of the distribution. - * - * \param parm A \p param_type object encapsulating the parameters (i.e., the range) of the distribution. - */ - __host__ __device__ - explicit uniform_real_distribution(const param_type &parm); - - /*! This does nothing. It is included to conform to the requirements of the RandomDistribution concept. - */ - __host__ __device__ - void reset(void); - - // generating functions - - /*! This method produces a new uniform random integer drawn from this \p uniform_real_distribution's - * range using a \p UniformRandomNumberGenerator as a source of randomness. - * - * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness. - */ - template - __host__ __device__ - result_type operator()(UniformRandomNumberGenerator &urng); - - /*! This method produces a new uniform random integer as if by creating a new \p uniform_real_distribution - * from the given \p param_type object, and calling its operator() method with the given - * \p UniformRandomNumberGenerator as a source of randomness. - * - * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness. - * \param parm A \p param_type object encapsulating the parameters of the \p uniform_real_distribution - * to draw from. - */ - template - __host__ __device__ - result_type operator()(UniformRandomNumberGenerator &urng, const param_type &parm); - - // property functions - - /*! This method returns the value of the parameter with which this \p uniform_real_distribution - * was constructed. - * - * \return The lower bound of this \p uniform_real_distribution's half-open interval. - */ - __host__ __device__ - result_type a(void) const; - - /*! This method returns the value of the parameter with which this \p uniform_real_distribution - * was constructed. - * - * \return The upper bound of this \p uniform_real_distribution's half-open interval. - */ - __host__ __device__ - result_type b(void) const; - - /*! This method returns a \p param_type object encapsulating the parameters with which this - * \p uniform_real_distribution was constructed. - * - * \return A \p param_type object enapsulating the half-open interval of this \p uniform_real_distribution. - */ - __host__ __device__ - param_type param(void) const; - - /*! This method changes the parameters of this \p uniform_real_distribution using the values encapsulated - * in a given \p param_type object. - * - * \param parm A \p param_type object encapsulating the new half-open interval of this \p uniform_real_distribution. - */ - __host__ __device__ - void param(const param_type &parm); - - /*! This method returns the smallest floating point number this \p uniform_real_distribution can potentially produce. - * - * \return The lower bound of this \p uniform_real_distribution's half-open interval. - */ - __host__ __device__ - result_type min THRUST_PREVENT_MACRO_SUBSTITUTION (void) const; - - /*! This method returns the smallest number larger than largest floating point number this \p uniform_real_distribution can potentially produce. - * - * \return The upper bound of this \p uniform_real_distribution's half-open interval. - */ - __host__ __device__ - result_type max THRUST_PREVENT_MACRO_SUBSTITUTION (void) const; - - /*! \cond - */ - private: - param_type m_param; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const uniform_real_distribution &rhs) const; - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - /*! \endcond - */ -}; // end uniform_real_distribution - - -/*! This function checks two \p uniform_real_distributions for equality. - * \param lhs The first \p uniform_real_distribution to test. - * \param rhs The second \p uniform_real_distribution to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const uniform_real_distribution &lhs, - const uniform_real_distribution &rhs); - - -/*! This function checks two \p uniform_real_distributions for inequality. - * \param lhs The first \p uniform_real_distribution to test. - * \param rhs The second \p uniform_real_distribution to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const uniform_real_distribution &lhs, - const uniform_real_distribution &rhs); - - -/*! This function streams a uniform_real_distribution to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param d The \p uniform_real_distribution to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const uniform_real_distribution &d); - - -/*! This function streams a uniform_real_distribution in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param d The \p uniform_real_distribution to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - uniform_real_distribution &d); - - -/*! \} // end random_number_distributions - */ - - -} // end random - -using random::uniform_real_distribution; - -} // end thrust - -#include - diff --git a/compat/thrust/random/xor_combine_engine.h b/compat/thrust/random/xor_combine_engine.h deleted file mode 100644 index 61eb5a5..0000000 --- a/compat/thrust/random/xor_combine_engine.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file xor_combine_engine.h - * \brief A pseudorandom number generator which produces pseudorandom - * numbers from two integer base engines by merging their - * pseudorandom numbers with bitwise exclusive-or. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include // for size_t - -namespace thrust -{ - -namespace random -{ - -/*! \addtogroup random_number_engine_adaptors - * \{ - */ - -/*! \class xor_combine_engine - * \brief An \p xor_combine_engine adapts two existing base random number engines and - * produces random values by combining the values produced by each. - * - * \tparam Engine1 The type of the first base random number engine to adapt. - * \tparam s1 The size of the first shift to use in the generation algorithm. - * \tparam Engine2 The type of the second base random number engine to adapt. - * \tparam s2 The second of the second shift to use in the generation algorithm. Defaults to \c 0. - * - * The following code snippet shows an example of using an \p xor_combine_engine instance: - * - * \code - * #include - * #include - * #include - * - * int main(void) - * { - * // create an xor_combine_engine from minstd_rand and minstd_rand0 - * // use a shift of 0 for each - * thrust::xor_combine_engine rng; - * - * // print a random number to standard output - * std::cout << rng() << std::endl; - * - * return 0; - * } - * \endcode - */ -template - class xor_combine_engine -{ - public: - // types - - /*! \typedef base1_type - * \brief The type of the first adapted base random number engine. - */ - typedef Engine1 base1_type; - - /*! \typedef base2_type - * \brief The type of the second adapted base random number engine. - */ - typedef Engine2 base2_type; - - /*! \typedef result_type - * \brief The type of the unsigned integer produced by this \p xor_combine_engine. - */ - typedef typename thrust::detail::eval_if< - (sizeof(typename base2_type::result_type) > sizeof(typename base1_type::result_type)), - thrust::detail::identity_, - thrust::detail::identity_ - >::type result_type; - - /*! The size of the first shift used in the generation algorithm. - */ - static const size_t shift1 = s1; - - /*! The size of the second shift used in the generation algorithm. - */ - static const size_t shift2 = s2; - - /*! The smallest value this \p xor_combine_engine may potentially produce. - */ - static const result_type min = 0; - - /*! The largest value this \p xor_combine_engine may potentially produce. - */ - static const result_type max = - detail::xor_combine_engine_max< - Engine1, s1, Engine2, s2, result_type - >::value; - - // constructors and seeding functions - - /*! This constructor constructs a new \p xor_combine_engine and constructs - * its adapted engines using their null constructors. - */ - __host__ __device__ - xor_combine_engine(void); - - /*! This constructor constructs a new \p xor_combine_engine using - * given \p base1_type and \p base2_type engines to initialize its adapted base engines. - * - * \param urng1 A \p base1_type to use to initialize this \p xor_combine_engine's - * first adapted base engine. - * \param urng2 A \p base2_type to use to initialize this \p xor_combine_engine's - * first adapted base engine. - */ - __host__ __device__ - xor_combine_engine(const base1_type &urng1, const base2_type &urng2); - - /*! This constructor initializes a new \p xor_combine_engine with a given seed. - * - * \param s The seed used to intialize this \p xor_combine_engine's adapted base engines. - */ - __host__ __device__ - xor_combine_engine(result_type s); - - /*! This method initializes the state of this \p xor_combine_engine's adapted base engines - * by using their \p default_seed values. - */ - __host__ __device__ - void seed(void); - - /*! This method initializes the state of this \p xor_combine_engine's adapted base engines - * by using the given seed. - * - * \param s The seed with which to intialize this \p xor_combine_engine's adapted base engines. - */ - __host__ __device__ - void seed(result_type s); - - // generating functions - - /*! This member function produces a new random value and updates this \p xor_combine_engine's state. - * \return A new random number. - */ - __host__ __device__ - result_type operator()(void); - - /*! This member function advances this \p xor_combine_engine's state a given number of times - * and discards the results. - * - * \param z The number of random values to discard. - * \note This function is provided because an implementation may be able to accelerate it. - */ - __host__ __device__ - void discard(unsigned long long z); - - // property functions - - /*! This member function returns a const reference to this \p xor_combine_engine's - * first adapted base engine. - * - * \return A const reference to the first base engine this \p xor_combine_engine adapts. - */ - __host__ __device__ - const base1_type &base1(void) const; - - /*! This member function returns a const reference to this \p xor_combine_engine's - * second adapted base engine. - * - * \return A const reference to the second base engine this \p xor_combine_engine adapts. - */ - __host__ __device__ - const base2_type &base2(void) const; - - /*! \cond - */ - private: - base1_type m_b1; - base2_type m_b2; - - friend struct thrust::random::detail::random_core_access; - - __host__ __device__ - bool equal(const xor_combine_engine &rhs) const; - - template - std::basic_istream& stream_in(std::basic_istream &is); - - template - std::basic_ostream& stream_out(std::basic_ostream &os) const; - - /*! \endcond - */ -}; // end xor_combine_engine - - -/*! This function checks two \p xor_combine_engines for equality. - * \param lhs The first \p xor_combine_engine to test. - * \param rhs The second \p xor_combine_engine to test. - * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator==(const xor_combine_engine &lhs, - const xor_combine_engine &rhs); - - -/*! This function checks two \p xor_combine_engines for inequality. - * \param lhs The first \p xor_combine_engine to test. - * \param rhs The second \p xor_combine_engine to test. - * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise. - */ -template -__host__ __device__ -bool operator!=(const xor_combine_engine &lhs, - const xor_combine_engine &rhs); - - -/*! This function streams a xor_combine_engine to a \p std::basic_ostream. - * \param os The \p basic_ostream to stream out to. - * \param e The \p xor_combine_engine to stream out. - * \return \p os - */ -template -std::basic_ostream& -operator<<(std::basic_ostream &os, - const xor_combine_engine &e); - - -/*! This function streams a xor_combine_engine in from a std::basic_istream. - * \param is The \p basic_istream to stream from. - * \param e The \p xor_combine_engine to stream in. - * \return \p is - */ -template -std::basic_istream& -operator>>(std::basic_istream &is, - xor_combine_engine &e); - - -/*! \} // end random_number_engine_adaptors - */ - - -} // end random - -// import names into thrust:: -using random::xor_combine_engine; - -} // end thrust - -#include - diff --git a/compat/thrust/reduce.h b/compat/thrust/reduce.h deleted file mode 100644 index 1dc931f..0000000 --- a/compat/thrust/reduce.h +++ /dev/null @@ -1,779 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief Functions for reducing a range to a single value - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reductions - * \{ - */ - - -/*! \p reduce is a generalization of summation: it computes the sum (or some - * other binary operation) of all the elements in the range [first, - * last). This version of \p reduce uses \c 0 as the initial value of the - * reduction. \p reduce is similar to the C++ Standard Template Library's - * std::accumulate. The primary difference between the two functions - * is that std::accumulate guarantees the order of summation, while - * \p reduce requires associativity of the binary operation to parallelize - * the reduction. - * - * Note that \p reduce also assumes that the binary reduction operator (in this - * case operator+) is commutative. If the reduction operator is not commutative - * then \p thrust::reduce should not be used. Instead, one could use - * \p inclusive_scan (which does not require commutativity) and select the - * last element of the output array. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return The result of the reduction. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and if \c x and \c y are objects of \p InputIterator's \c value_type, - * then x + y is defined and is convertible to \p InputIterator's - * \c value_type. If \c T is \c InputIterator's \c value_type, then - * T(0) is defined. - * - * The following code snippet demonstrates how to use \p reduce to compute - * the sum of a sequence of integers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int result = thrust::reduce(thrust::host, data, data + 6); - * - * // result == 9 - * \endcode - * - * \see http://www.sgi.com/tech/stl/accumulate.html - */ -template - typename thrust::iterator_traits::value_type - reduce(const thrust::detail::execution_policy_base &exec, InputIterator first, InputIterator last); - - -/*! \p reduce is a generalization of summation: it computes the sum (or some - * other binary operation) of all the elements in the range [first, - * last). This version of \p reduce uses \c 0 as the initial value of the - * reduction. \p reduce is similar to the C++ Standard Template Library's - * std::accumulate. The primary difference between the two functions - * is that std::accumulate guarantees the order of summation, while - * \p reduce requires associativity of the binary operation to parallelize - * the reduction. - * - * Note that \p reduce also assumes that the binary reduction operator (in this - * case operator+) is commutative. If the reduction operator is not commutative - * then \p thrust::reduce should not be used. Instead, one could use - * \p inclusive_scan (which does not require commutativity) and select the - * last element of the output array. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return The result of the reduction. - * - * \tparam InputIterator is a model of Input Iterator - * and if \c x and \c y are objects of \p InputIterator's \c value_type, - * then x + y is defined and is convertible to \p InputIterator's - * \c value_type. If \c T is \c InputIterator's \c value_type, then - * T(0) is defined. - * - * The following code snippet demonstrates how to use \p reduce to compute - * the sum of a sequence of integers. - * - * \code - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int result = thrust::reduce(data, data + 6); - * - * // result == 9 - * \endcode - * - * \see http://www.sgi.com/tech/stl/accumulate.html - */ -template typename - thrust::iterator_traits::value_type reduce(InputIterator first, InputIterator last); - - -/*! \p reduce is a generalization of summation: it computes the sum (or some - * other binary operation) of all the elements in the range [first, - * last). This version of \p reduce uses \p init as the initial value of the - * reduction. \p reduce is similar to the C++ Standard Template Library's - * std::accumulate. The primary difference between the two functions - * is that std::accumulate guarantees the order of summation, while - * \p reduce requires associativity of the binary operation to parallelize - * the reduction. - * - * Note that \p reduce also assumes that the binary reduction operator (in this - * case operator+) is commutative. If the reduction operator is not commutative - * then \p thrust::reduce should not be used. Instead, one could use - * \p inclusive_scan (which does not require commutativity) and select the - * last element of the output array. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param init The initial value. - * \return The result of the reduction. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and if \c x and \c y are objects of \p InputIterator's \c value_type, - * then x + y is defined and is convertible to \p T. - * \tparam T is convertible to \p InputIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p reduce to compute - * the sum of a sequence of integers including an intialization value using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int result = thrust::reduce(thrust::host, data, data + 6, 1); - * - * // result == 10 - * \endcode - * - * \see http://www.sgi.com/tech/stl/accumulate.html - */ -template - T reduce(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - T init); - - -/*! \p reduce is a generalization of summation: it computes the sum (or some - * other binary operation) of all the elements in the range [first, - * last). This version of \p reduce uses \p init as the initial value of the - * reduction. \p reduce is similar to the C++ Standard Template Library's - * std::accumulate. The primary difference between the two functions - * is that std::accumulate guarantees the order of summation, while - * \p reduce requires associativity of the binary operation to parallelize - * the reduction. - * - * Note that \p reduce also assumes that the binary reduction operator (in this - * case operator+) is commutative. If the reduction operator is not commutative - * then \p thrust::reduce should not be used. Instead, one could use - * \p inclusive_scan (which does not require commutativity) and select the - * last element of the output array. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param init The initial value. - * \return The result of the reduction. - * - * \tparam InputIterator is a model of Input Iterator - * and if \c x and \c y are objects of \p InputIterator's \c value_type, - * then x + y is defined and is convertible to \p T. - * \tparam T is convertible to \p InputIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p reduce to compute - * the sum of a sequence of integers including an intialization value. - * - * \code - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int result = thrust::reduce(data, data + 6, 1); - * - * // result == 10 - * \endcode - * - * \see http://www.sgi.com/tech/stl/accumulate.html - */ -template - T reduce(InputIterator first, - InputIterator last, - T init); - - -/*! \p reduce is a generalization of summation: it computes the sum (or some - * other binary operation) of all the elements in the range [first, - * last). This version of \p reduce uses \p init as the initial value of the - * reduction and \p binary_op as the binary function used for summation. \p reduce - * is similar to the C++ Standard Template Library's std::accumulate. - * The primary difference between the two functions is that std::accumulate - * guarantees the order of summation, while \p reduce requires associativity of - * \p binary_op to parallelize the reduction. - * - * Note that \p reduce also assumes that the binary reduction operator (in this - * case \p binary_op) is commutative. If the reduction operator is not commutative - * then \p thrust::reduce should not be used. Instead, one could use - * \p inclusive_scan (which does not require commutativity) and select the - * last element of the output array. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param init The initial value. - * \param binary_op The binary function used to 'sum' values. - * \return The result of the reduction. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c T. - * \tparam T is a model of Assignable, - * and is convertible to \p BinaryFunction's \c first_argument_type and \c second_argument_type. - * \tparam BinaryFunction is a model of Binary Function, - * and \p BinaryFunction's \c result_type is convertible to \p OutputType. - * - * The following code snippet demonstrates how to use \p reduce to - * compute the maximum value of a sequence of integers using the \p thrust::host execution policy - * for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int result = thrust::reduce(thrust::host, - * data, data + 6, - * -1, - * thrust::maximum()); - * // result == 3 - * \endcode - * - * \see http://www.sgi.com/tech/stl/accumulate.html - * \see transform_reduce - */ -template - T reduce(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - T init, - BinaryFunction binary_op); - - -/*! \p reduce is a generalization of summation: it computes the sum (or some - * other binary operation) of all the elements in the range [first, - * last). This version of \p reduce uses \p init as the initial value of the - * reduction and \p binary_op as the binary function used for summation. \p reduce - * is similar to the C++ Standard Template Library's std::accumulate. - * The primary difference between the two functions is that std::accumulate - * guarantees the order of summation, while \p reduce requires associativity of - * \p binary_op to parallelize the reduction. - * - * Note that \p reduce also assumes that the binary reduction operator (in this - * case \p binary_op) is commutative. If the reduction operator is not commutative - * then \p thrust::reduce should not be used. Instead, one could use - * \p inclusive_scan (which does not require commutativity) and select the - * last element of the output array. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param init The initial value. - * \param binary_op The binary function used to 'sum' values. - * \return The result of the reduction. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c T. - * \tparam T is a model of Assignable, - * and is convertible to \p BinaryFunction's \c first_argument_type and \c second_argument_type. - * \tparam BinaryFunction is a model of Binary Function, - * and \p BinaryFunction's \c result_type is convertible to \p OutputType. - * - * The following code snippet demonstrates how to use \p reduce to - * compute the maximum value of a sequence of integers. - * - * \code - * #include - * #include - * ... - * int data[6] = {1, 0, 2, 2, 1, 3}; - * int result = thrust::reduce(data, data + 6, - * -1, - * thrust::maximum()); - * // result == 3 - * \endcode - * - * \see http://www.sgi.com/tech/stl/accumulate.html - * \see transform_reduce - */ -template - T reduce(InputIterator first, - InputIterator last, - T init, - BinaryFunction binary_op); - - -/*! \p reduce_by_key is a generalization of \p reduce to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p reduce_by_key copies the first element of the group to the - * \c keys_output. The corresponding values in the range are reduced using the - * \c plus and the result copied to \c values_output. - * - * This version of \p reduce_by_key uses the function object \c equal_to - * to test for equality and \c plus to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_output The beginning of the output key range. - * \param values_output The beginning of the output value range. - * \return A pair of iterators at end of the ranges [keys_output, keys_output_last) and [values_output, values_output_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p reduce_by_key to - * compact a sequence of key/value pairs and sum values with equal keys using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * new_end = thrust::reduce_by_key(thrust::host, A, A + N, B, C, D); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 21, 9, 3} and new_end.second - D is 4. - * \endcode - * - * \see reduce - * \see unique_copy - * \see unique_by_key - * \see unique_by_key_copy - */ -template - thrust::pair - reduce_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output); - - -/*! \p reduce_by_key is a generalization of \p reduce to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p reduce_by_key copies the first element of the group to the - * \c keys_output. The corresponding values in the range are reduced using the - * \c plus and the result copied to \c values_output. - * - * This version of \p reduce_by_key uses the function object \c equal_to - * to test for equality and \c plus to reduce values with equal keys. - * - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_output The beginning of the output key range. - * \param values_output The beginning of the output value range. - * \return A pair of iterators at end of the ranges [keys_output, keys_output_last) and [values_output, values_output_last). - * - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p reduce_by_key to - * compact a sequence of key/value pairs and sum values with equal keys. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * new_end = thrust::reduce_by_key(A, A + N, B, C, D); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 21, 9, 3} and new_end.second - D is 4. - * \endcode - * - * \see reduce - * \see unique_copy - * \see unique_by_key - * \see unique_by_key_copy - */ -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output); - - -/*! \p reduce_by_key is a generalization of \p reduce to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p reduce_by_key copies the first element of the group to the - * \c keys_output. The corresponding values in the range are reduced using the - * \c plus and the result copied to \c values_output. - * - * This version of \p reduce_by_key uses the function object \c binary_pred - * to test for equality and \c plus to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_output The beginning of the output key range. - * \param values_output The beginning of the output value range. - * \param binary_pred The binary predicate used to determine equality. - * \return A pair of iterators at end of the ranges [keys_output, keys_output_last) and [values_output, values_output_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p reduce_by_key to - * compact a sequence of key/value pairs and sum values with equal keys using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * new_end = thrust::reduce_by_key(thrust::host, A, A + N, B, C, D, binary_pred); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 21, 9, 3} and new_end.second - D is 4. - * \endcode - * - * \see reduce - * \see unique_copy - * \see unique_by_key - * \see unique_by_key_copy - */ -template - thrust::pair - reduce_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred); - - -/*! \p reduce_by_key is a generalization of \p reduce to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p reduce_by_key copies the first element of the group to the - * \c keys_output. The corresponding values in the range are reduced using the - * \c plus and the result copied to \c values_output. - * - * This version of \p reduce_by_key uses the function object \c binary_pred - * to test for equality and \c plus to reduce values with equal keys. - * - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_output The beginning of the output key range. - * \param values_output The beginning of the output value range. - * \param binary_pred The binary predicate used to determine equality. - * \return A pair of iterators at end of the ranges [keys_output, keys_output_last) and [values_output, values_output_last). - * - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p reduce_by_key to - * compact a sequence of key/value pairs and sum values with equal keys. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * new_end = thrust::reduce_by_key(A, A + N, B, C, D, binary_pred); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 21, 9, 3} and new_end.second - D is 4. - * \endcode - * - * \see reduce - * \see unique_copy - * \see unique_by_key - * \see unique_by_key_copy - */ -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred); - - -/*! \p reduce_by_key is a generalization of \p reduce to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p reduce_by_key copies the first element of the group to the - * \c keys_output. The corresponding values in the range are reduced using the - * \c BinaryFunction \c binary_op and the result copied to \c values_output. - * Specifically, if consecutive key iterators \c i and \c (i + 1) are - * such that binary_pred(*i, *(i+1)) is \c true, then the corresponding - * values are reduced to a single value with \c binary_op. - * - * This version of \p reduce_by_key uses the function object \c binary_pred - * to test for equality and \c binary_op to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_output The beginning of the output key range. - * \param values_output The beginning of the output value range. - * \param binary_pred The binary predicate used to determine equality. - * \param binary_op The binary function used to accumulate values. - * \return A pair of iterators at end of the ranges [keys_output, keys_output_last) and [values_output, values_output_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * \tparam BinaryFunction is a model of Binary Function - * and \c BinaryFunction's \c result_type is convertible to \c OutputIterator2's \c value_type. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p reduce_by_key to - * compact a sequence of key/value pairs and sum values with equal keys using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * thrust::plus binary_op; - * new_end = thrust::reduce_by_key(thrust::host, A, A + N, B, C, D, binary_pred, binary_op); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 21, 9, 3} and new_end.second - D is 4. - * \endcode - * - * \see reduce - * \see unique_copy - * \see unique_by_key - * \see unique_by_key_copy - */ -template - thrust::pair - reduce_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op); - - -/*! \p reduce_by_key is a generalization of \p reduce to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p reduce_by_key copies the first element of the group to the - * \c keys_output. The corresponding values in the range are reduced using the - * \c BinaryFunction \c binary_op and the result copied to \c values_output. - * Specifically, if consecutive key iterators \c i and \c (i + 1) are - * such that binary_pred(*i, *(i+1)) is \c true, then the corresponding - * values are reduced to a single value with \c binary_op. - * - * This version of \p reduce_by_key uses the function object \c binary_pred - * to test for equality and \c binary_op to reduce values with equal keys. - * - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_output The beginning of the output key range. - * \param values_output The beginning of the output value range. - * \param binary_pred The binary predicate used to determine equality. - * \param binary_op The binary function used to accumulate values. - * \return A pair of iterators at end of the ranges [keys_output, keys_output_last) and [values_output, values_output_last). - * - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * \tparam BinaryFunction is a model of Binary Function - * and \c BinaryFunction's \c result_type is convertible to \c OutputIterator2's \c value_type. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p reduce_by_key to - * compact a sequence of key/value pairs and sum values with equal keys. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * thrust::plus binary_op; - * new_end = thrust::reduce_by_key(A, A + N, B, C, D, binary_pred, binary_op); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 21, 9, 3} and new_end.second - D is 4. - * \endcode - * - * \see reduce - * \see unique_copy - * \see unique_by_key - * \see unique_by_key_copy - */ -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op); - - -/*! \} // end reductions - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/remove.h b/compat/thrust/remove.h deleted file mode 100644 index c538776..0000000 --- a/compat/thrust/remove.h +++ /dev/null @@ -1,800 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file remove.h - * \brief Functions for removing elements from a range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup stream_compaction Stream Compaction - * \ingroup reordering - * \{ - * - */ - - -/*! \p remove removes from the range [first, last) all elements that are - * equal to \p value. That is, \p remove returns an iterator \p new_last such - * that the range [first, new_last) contains no elements equal to - * \p value. The iterators in the range [new_first,last) are all still - * dereferenceable, but the elements that they point to are unspecified. \p remove - * is stable, meaning that the relative order of elements that are not equal to - * \p value is unchanged. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param value The value to remove from the range [first, last). - * Elements which are equal to value are removed from the sequence. - * \return A \p ForwardIterator pointing to the end of the resulting range of - * elements which are not equal to \p value. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam T is a model of Equality Comparable, - * and objects of type \p T can be compared for equality with objects of \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p remove to remove a number - * of interest from a range using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {3, 1, 4, 1, 5, 9}; - * int *new_end = thrust::remove(A, A + N, 1); - * // The first four values of A are now {3, 4, 5, 9} - * // Values beyond new_end are unspecified - * \endcode - * - * \note The meaning of "removal" is somewhat subtle. \p remove does not destroy any - * iterators, and does not change the distance between \p first and \p last. - * (There's no way that it could do anything of the sort.) So, for example, if - * \c V is a device_vector, remove(V.begin(), V.end(), 0) does not - * change V.size(): \c V will contain just as many elements as it did - * before. \p remove returns an iterator that points to the end of the resulting - * range after elements have been removed from it; it follows that the elements - * after that iterator are of no interest, and may be discarded. If you are - * removing elements from a - * Sequence, you may - * simply erase them. That is, a reasonable way of removing elements from a - * Sequence is - * S.erase(remove(S.begin(), S.end(), x), S.end()). - * - * \see http://www.sgi.com/tech/stl/remove.html - * \see remove_if - * \see remove_copy - * \see remove_copy_if - */ -template - ForwardIterator remove(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &value); - - -/*! \p remove removes from the range [first, last) all elements that are - * equal to \p value. That is, \p remove returns an iterator \p new_last such - * that the range [first, new_last) contains no elements equal to - * \p value. The iterators in the range [new_first,last) are all still - * dereferenceable, but the elements that they point to are unspecified. \p remove - * is stable, meaning that the relative order of elements that are not equal to - * \p value is unchanged. - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param value The value to remove from the range [first, last). - * Elements which are equal to value are removed from the sequence. - * \return A \p ForwardIterator pointing to the end of the resulting range of - * elements which are not equal to \p value. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam T is a model of Equality Comparable, - * and objects of type \p T can be compared for equality with objects of \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p remove to remove a number - * of interest from a range. - * - * \code - * #include - * ... - * const int N = 6; - * int A[N] = {3, 1, 4, 1, 5, 9}; - * int *new_end = thrust::remove(A, A + N, 1); - * // The first four values of A are now {3, 4, 5, 9} - * // Values beyond new_end are unspecified - * \endcode - * - * \note The meaning of "removal" is somewhat subtle. \p remove does not destroy any - * iterators, and does not change the distance between \p first and \p last. - * (There's no way that it could do anything of the sort.) So, for example, if - * \c V is a device_vector, remove(V.begin(), V.end(), 0) does not - * change V.size(): \c V will contain just as many elements as it did - * before. \p remove returns an iterator that points to the end of the resulting - * range after elements have been removed from it; it follows that the elements - * after that iterator are of no interest, and may be discarded. If you are - * removing elements from a - * Sequence, you may - * simply erase them. That is, a reasonable way of removing elements from a - * Sequence is - * S.erase(remove(S.begin(), S.end(), x), S.end()). - * - * \see http://www.sgi.com/tech/stl/remove.html - * \see remove_if - * \see remove_copy - * \see remove_copy_if - */ -template - ForwardIterator remove(ForwardIterator first, - ForwardIterator last, - const T &value); - - -/*! \p remove_copy copies elements that are not equal to \p value from the range - * [first, last) to a range beginning at \p result. The return value is - * the end of the resulting range. This operation is stable, meaning that the - * relative order of the elements that are copied is the same as in - * the range [first, last). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param result The resulting range is copied to the sequence beginning at this - * location. - * \param value The value to omit from the copied range. - * \return An OutputIterator pointing to the end of the resulting range of elements - * which are not equal to \p value. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam T is a model of Equality Comparable, - * and objects of type \p T can be compared for equality with objects of \p InputIterator's \c value_type. - * - * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_copy to copy - * a sequence of numbers to an output range while omitting a value of interest using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int result[N-2]; - * thrust::remove_copy(thrust::host, V, V + N, result, 0); - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-2, -1, 1, 2} - * \endcode - * - * \see http://www.sgi.com/tech/stl/remove_copy.html - * \see remove - * \see remove_if - * \see remove_copy_if - */ -template - OutputIterator remove_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - const T &value); - - -/*! \p remove_copy copies elements that are not equal to \p value from the range - * [first, last) to a range beginning at \p result. The return value is - * the end of the resulting range. This operation is stable, meaning that the - * relative order of the elements that are copied is the same as in - * the range [first, last). - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param result The resulting range is copied to the sequence beginning at this - * location. - * \param value The value to omit from the copied range. - * \return An OutputIterator pointing to the end of the resulting range of elements - * which are not equal to \p value. - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam T is a model of Equality Comparable, - * and objects of type \p T can be compared for equality with objects of \p InputIterator's \c value_type. - * - * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_copy to copy - * a sequence of numbers to an output range while omitting a value of interest. - * - * \code - * #include - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int result[N-2]; - * thrust::remove_copy(V, V + N, result, 0); - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-2, -1, 1, 2} - * \endcode - * - * \see http://www.sgi.com/tech/stl/remove_copy.html - * \see remove - * \see remove_if - * \see remove_copy_if - */ -template - OutputIterator remove_copy(InputIterator first, - InputIterator last, - OutputIterator result, - const T &value); - - -/*! \p remove_if removes from the range [first, last) every element \p x - * such that pred(x) is \c true. That is, \p remove_if returns an - * iterator \c new_last such that the range [first,new_last) contains - * no elements for which \p pred is \c true. The iterators in the range - * [new_last,last) are all still dereferenceable, but the elements that - * they point to are unspecified. \p remove_if is stable, meaning that the - * relative order of elements that are not removed is unchanged. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param pred A predicate to evaluate for each element of the range - * [first,last). Elements for which \p pred evaluates to - * \c false are removed from the sequence. - * \return A ForwardIterator pointing to the end of the resulting range of - * elements for which \p pred evaluated to \c true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * The following code snippet demonstrates how to use \p remove_if to remove - * all even numbers from an array of integers using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * int *new_end = thrust::remove_if(thrust::host, A, A + N, is_even()); - * // The first three values of A are now {1, 5, 7} - * // Values beyond new_end are unspecified - * \endcode - * - * \note The meaning of "removal" is somewhat subtle. \p remove_if does not - * destroy any iterators, and does not change the distance between \p first and - * \p last. (There's no way that it could do anything of the sort.) So, for - * example, if \c V is a device_vector, - * remove_if(V.begin(), V.end(), pred) does not change - * V.size(): \c V will contain just as many elements as it did before. - * \p remove_if returns an iterator that points to the end of the resulting - * range after elements have been removed from it; it follows that the elements - * after that iterator are of no interest, and may be discarded. If you are - * removing elements from a - * Sequence, you may - * simply erase them. That is, a reasonable way of removing elements from a - * Sequence is - * S.erase(remove_if(S.begin(), S.end(), pred), S.end()). - * - * \see http://www.sgi.com/tech/stl/remove_if.html - * \see remove - * \see remove_copy - * \see remove_copy_if - */ -template - ForwardIterator remove_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p remove_if removes from the range [first, last) every element \p x - * such that pred(x) is \c true. That is, \p remove_if returns an - * iterator \c new_last such that the range [first,new_last) contains - * no elements for which \p pred is \c true. The iterators in the range - * [new_last,last) are all still dereferenceable, but the elements that - * they point to are unspecified. \p remove_if is stable, meaning that the - * relative order of elements that are not removed is unchanged. - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param pred A predicate to evaluate for each element of the range - * [first,last). Elements for which \p pred evaluates to - * \c false are removed from the sequence. - * \return A ForwardIterator pointing to the end of the resulting range of - * elements for which \p pred evaluated to \c true. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * The following code snippet demonstrates how to use \p remove_if to remove - * all even numbers from an array of integers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * int *new_end = thrust::remove_if(A, A + N, is_even()); - * // The first three values of A are now {1, 5, 7} - * // Values beyond new_end are unspecified - * \endcode - * - * \note The meaning of "removal" is somewhat subtle. \p remove_if does not - * destroy any iterators, and does not change the distance between \p first and - * \p last. (There's no way that it could do anything of the sort.) So, for - * example, if \c V is a device_vector, - * remove_if(V.begin(), V.end(), pred) does not change - * V.size(): \c V will contain just as many elements as it did before. - * \p remove_if returns an iterator that points to the end of the resulting - * range after elements have been removed from it; it follows that the elements - * after that iterator are of no interest, and may be discarded. If you are - * removing elements from a - * Sequence, you may - * simply erase them. That is, a reasonable way of removing elements from a - * Sequence is - * S.erase(remove_if(S.begin(), S.end(), pred), S.end()). - * - * \see http://www.sgi.com/tech/stl/remove_if.html - * \see remove - * \see remove_copy - * \see remove_copy_if - */ -template - ForwardIterator remove_if(ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -/*! \p remove_copy_if copies elements from the range [first,last) to a - * range beginning at \p result, except that elements for which \p pred is - * \c true are not copied. The return value is the end of the resulting range. - * This operation is stable, meaning that the relative order of the elements that - * are copied is the same as the range [first,last). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param result The resulting range is copied to the sequence beginning at this - * location. - * \param pred A predicate to evaluate for each element of the range [first,last). - * Elements for which \p pred evaluates to \c false are not copied - * to the resulting sequence. - * \return An OutputIterator pointing to the end of the resulting range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_copy_if to copy - * a sequence of numbers to an output range while omitting even numbers using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int result[2]; - * thrust::remove_copy_if(thrust::host, V, V + N, result, is_even()); - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-1, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/remove_copy_if.html - * \see remove - * \see remove_copy - * \see remove_if - */ -template - OutputIterator remove_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - -/*! \p remove_copy_if copies elements from the range [first,last) to a - * range beginning at \p result, except that elements for which \p pred is - * \c true are not copied. The return value is the end of the resulting range. - * This operation is stable, meaning that the relative order of the elements that - * are copied is the same as the range [first,last). - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param result The resulting range is copied to the sequence beginning at this - * location. - * \param pred A predicate to evaluate for each element of the range [first,last). - * Elements for which \p pred evaluates to \c false are not copied - * to the resulting sequence. - * \return An OutputIterator pointing to the end of the resulting range. - * - * \tparam InputIterator is a model of Input Iterator, - * \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_copy_if to copy - * a sequence of numbers to an output range while omitting even numbers. - * - * \code - * #include - * ... - * struct is_even - * { - * __host__ __device__ - * bool operator()(const int x) - * { - * return (x % 2) == 0; - * } - * }; - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int result[2]; - * thrust::remove_copy_if(V, V + N, result, is_even()); - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-1, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/remove_copy_if.html - * \see remove - * \see remove_copy - * \see remove_if - */ -template - OutputIterator remove_copy_if(InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - -/*! \p remove_if removes from the range [first, last) every element \p x - * such that pred(x) is \c true. That is, \p remove_if returns an - * iterator \c new_last such that the range [first, new_last) contains - * no elements for which \p pred of the corresponding stencil value is \c true. - * The iterators in the range [new_last,last) are all still dereferenceable, - * but the elements that they point to are unspecified. \p remove_if is stable, - * meaning that the relative order of elements that are not removed is unchanged. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param stencil The beginning of the stencil sequence. - * \param pred A predicate to evaluate for each element of the range - * [stencil, stencil + (last - first)). Elements for which \p pred evaluates to - * \c false are removed from the sequence [first, last) - * \return A ForwardIterator pointing to the end of the resulting range of - * elements for which \p pred evaluated to \c true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). - * \pre The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_if to remove - * specific elements from an array of integers using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * int S[N] = {0, 1, 1, 1, 0, 0}; - * - * int *new_end = thrust::remove(thrust::host, A, A + N, S, thrust::identity()); - * // The first three values of A are now {1, 5, 7} - * // Values beyond new_end are unspecified - * \endcode - * - * \note The range [first, last) is not permitted to overlap with the range [stencil, stencil + (last - first)). - * - * \see http://www.sgi.com/tech/stl/remove_if.html - * \see remove - * \see remove_copy - * \see remove_copy_if - */ -template - ForwardIterator remove_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -/*! \p remove_if removes from the range [first, last) every element \p x - * such that pred(x) is \c true. That is, \p remove_if returns an - * iterator \c new_last such that the range [first, new_last) contains - * no elements for which \p pred of the corresponding stencil value is \c true. - * The iterators in the range [new_last,last) are all still dereferenceable, - * but the elements that they point to are unspecified. \p remove_if is stable, - * meaning that the relative order of elements that are not removed is unchanged. - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param stencil The beginning of the stencil sequence. - * \param pred A predicate to evaluate for each element of the range - * [stencil, stencil + (last - first)). Elements for which \p pred evaluates to - * \c false are removed from the sequence [first, last) - * \return A ForwardIterator pointing to the end of the resulting range of - * elements for which \p pred evaluated to \c true. - * - * \tparam ForwardIterator is a model of Forward Iterator - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). - * \pre The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_if to remove - * specific elements from an array of integers. - * - * \code - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * int S[N] = {0, 1, 1, 1, 0, 0}; - * - * int *new_end = thrust::remove(A, A + N, S, thrust::identity()); - * // The first three values of A are now {1, 5, 7} - * // Values beyond new_end are unspecified - * \endcode - * - * \note The range [first, last) is not permitted to overlap with the range [stencil, stencil + (last - first)). - * - * \see http://www.sgi.com/tech/stl/remove_if.html - * \see remove - * \see remove_copy - * \see remove_copy_if - */ -template - ForwardIterator remove_if(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -/*! \p remove_copy_if copies elements from the range [first,last) to a - * range beginning at \p result, except that elements for which \p pred of the - * corresponding stencil value is \c true are not copied. The return value is - * the end of the resulting range. This operation is stable, meaning that the - * relative order of the elements that are copied is the same as the - * range [first,last). - * - * The algorithm's execution policy is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param stencil The beginning of the stencil sequence. - * \param result The resulting range is copied to the sequence beginning at this - * location. - * \param pred A predicate to evaluate for each element of the range [first,last). - * Elements for which \p pred evaluates to \c false are not copied - * to the resulting sequence. - * \return An OutputIterator pointing to the end of the resulting range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_copy_if to copy - * a sequence of numbers to an output range while omitting specific elements using the \p thrust::host - * execution policy for parallelization. - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int S[N] = { 1, 1, 0, 1, 0, 1}; - * int result[2]; - * thrust::remove_copy_if(thrust::host, V, V + N, S, result, thrust::identity()); - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-1, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/remove_copy_if.html - * \see remove - * \see remove_copy - * \see remove_if - * \see copy_if - */ -template - OutputIterator remove_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -/*! \p remove_copy_if copies elements from the range [first,last) to a - * range beginning at \p result, except that elements for which \p pred of the - * corresponding stencil value is \c true are not copied. The return value is - * the end of the resulting range. This operation is stable, meaning that the - * relative order of the elements that are copied is the same as the - * range [first,last). - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param stencil The beginning of the stencil sequence. - * \param result The resulting range is copied to the sequence beginning at this - * location. - * \param pred A predicate to evaluate for each element of the range [first,last). - * Elements for which \p pred evaluates to \c false are not copied - * to the resulting sequence. - * \return An OutputIterator pointing to the end of the resulting range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * - * \pre The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)). - * - * The following code snippet demonstrates how to use \p remove_copy_if to copy - * a sequence of numbers to an output range while omitting specific elements. - * - * \code - * #include - * ... - * const int N = 6; - * int V[N] = {-2, 0, -1, 0, 1, 2}; - * int S[N] = { 1, 1, 0, 1, 0, 1}; - * int result[2]; - * thrust::remove_copy_if(V, V + N, S, result, thrust::identity()); - * // V remains {-2, 0, -1, 0, 1, 2} - * // result is now {-1, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/remove_copy_if.html - * \see remove - * \see remove_copy - * \see remove_if - * \see copy_if - */ -template - OutputIterator remove_copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -/*! \} // end stream_compaction - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/replace.h b/compat/thrust/replace.h deleted file mode 100644 index 48e3e49..0000000 --- a/compat/thrust/replace.h +++ /dev/null @@ -1,817 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file replace.h - * \brief Functions for replacing elements in a range with a particular value - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup transformations - * \addtogroup replacing - * \ingroup transformations - * \{ - */ - - -/*! \p replace replaces every element in the range [first, last) equal to \p old_value - * with \p new_value. That is: for every iterator \c i, if *i == old_value - * then it performs the assignment *i = new_value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence of interest. - * \param last The end of the sequence of interest. - * \param old_value The value to replace. - * \param new_value The new value to replace \p old_value. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam T is a model of Assignable, - * \p T is a model of EqualityComparable, - * objects of \p T may be compared for equality with objects of - * \p ForwardIterator's \c value_type, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p replace to replace - * a value of interest in a \c device_vector with another using the \p thrust::device - * execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = 2; - * A[2] = 3; - * A[3] = 1; - * - * thrust::replace(thrust::device, A.begin(), A.end(), 1, 99); - * - * // A contains [99, 2, 3, 99] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace.html - * \see \c replace_if - * \see \c replace_copy - * \see \c replace_copy_if - */ -template - void replace(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, ForwardIterator last, - const T &old_value, - const T &new_value); - - -/*! \p replace replaces every element in the range [first, last) equal to \p old_value - * with \p new_value. That is: for every iterator \c i, if *i == old_value - * then it performs the assignment *i = new_value. - * - * \param first The beginning of the sequence of interest. - * \param last The end of the sequence of interest. - * \param old_value The value to replace. - * \param new_value The new value to replace \p old_value. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam T is a model of Assignable, - * \p T is a model of EqualityComparable, - * objects of \p T may be compared for equality with objects of - * \p ForwardIterator's \c value_type, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p replace to replace - * a value of interest in a \c device_vector with another. - * - * \code - * #include - * #include - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = 2; - * A[2] = 3; - * A[3] = 1; - * - * thrust::replace(A.begin(), A.end(), 1, 99); - * - * // A contains [99, 2, 3, 99] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace.html - * \see \c replace_if - * \see \c replace_copy - * \see \c replace_copy_if - */ -template - void replace(ForwardIterator first, ForwardIterator last, const T &old_value, - const T &new_value); - - -/*! \p replace_if replaces every element in the range [first, last) for which - * \p pred returns \c true with \p new_value. That is: for every iterator \c i, if - * pred(*i) is \c true then it performs the assignment *i = new_value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence of interest. - * \param last The end of the sequence of interest. - * \param pred The predicate to test on every value of the range [first,last). - * \param new_value The new value to replace elements which pred(*i) evaluates - * to \c true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p replace_if to replace - * a \c device_vector's negative elements with \c 0 using the \p thrust::device execution policy - * for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = -3; - * A[2] = 2; - * A[3] = -1; - * - * is_less_than_zero pred; - * - * thrust::replace_if(thrust::device, A.begin(), A.end(), pred, 0); - * - * // A contains [1, 0, 2, 0] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_if.html - * \see \c replace - * \see \c replace_copy - * \see \c replace_copy_if - */ -template - void replace_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, ForwardIterator last, - Predicate pred, - const T &new_value); - - -/*! \p replace_if replaces every element in the range [first, last) for which - * \p pred returns \c true with \p new_value. That is: for every iterator \c i, if - * pred(*i) is \c true then it performs the assignment *i = new_value. - * - * \param first The beginning of the sequence of interest. - * \param last The end of the sequence of interest. - * \param pred The predicate to test on every value of the range [first,last). - * \param new_value The new value to replace elements which pred(*i) evaluates - * to \c true. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p replace_if to replace - * a \c device_vector's negative elements with \c 0. - * - * \code - * #include - * #include - * ... - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = -3; - * A[2] = 2; - * A[3] = -1; - * - * is_less_than_zero pred; - * - * thrust::replace_if(A.begin(), A.end(), pred, 0); - * - * // A contains [1, 0, 2, 0] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_if.html - * \see \c replace - * \see \c replace_copy - * \see \c replace_copy_if - */ -template - void replace_if(ForwardIterator first, ForwardIterator last, - Predicate pred, - const T &new_value); - - -/*! \p replace_if replaces every element in the range [first, last) for which - * pred(*s) returns \c true with \p new_value. That is: for every iterator - * \c i in the range [first, last), and \c s in the range [stencil, stencil + (last - first)), - * if pred(*s) is \c true then it performs the assignment *i = new_value. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence of interest. - * \param last The end of the sequence of interest. - * \param stencil The beginning of the stencil sequence. - * \param pred The predicate to test on every value of the range [first,last). - * \param new_value The new value to replace elements which pred(*i) evaluates - * to \c true. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p replace_if to replace - * a \c device_vector's element with \c 0 when its corresponding stencil element is less than zero - * using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 10; - * A[1] = 20; - * A[2] = 30; - * A[3] = 40; - * - * thrust::device_vector S(4); - * S[0] = -1; - * S[1] = 0; - * S[2] = -1; - * S[3] = 0; - * - * is_less_than_zero pred; - * thrust::replace_if(thrust::device, A.begin(), A.end(), S.begin(), pred, 0); - * - * // A contains [0, 20, 0, 40] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_if.html - * \see \c replace - * \see \c replace_copy - * \see \c replace_copy_if - */ -template - void replace_if(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, ForwardIterator last, - InputIterator stencil, - Predicate pred, - const T &new_value); - - -/*! \p replace_if replaces every element in the range [first, last) for which - * pred(*s) returns \c true with \p new_value. That is: for every iterator - * \c i in the range [first, last), and \c s in the range [stencil, stencil + (last - first)), - * if pred(*s) is \c true then it performs the assignment *i = new_value. - * - * \param first The beginning of the sequence of interest. - * \param last The end of the sequence of interest. - * \param stencil The beginning of the stencil sequence. - * \param pred The predicate to test on every value of the range [first,last). - * \param new_value The new value to replace elements which pred(*i) evaluates - * to \c true. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p replace_if to replace - * a \c device_vector's element with \c 0 when its corresponding stencil element is less than zero. - * - * \code - * #include - * #include - * - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 10; - * A[1] = 20; - * A[2] = 30; - * A[3] = 40; - * - * thrust::device_vector S(4); - * S[0] = -1; - * S[1] = 0; - * S[2] = -1; - * S[3] = 0; - * - * is_less_than_zero pred; - * thrust::replace_if(A.begin(), A.end(), S.begin(), pred, 0); - * - * // A contains [0, 20, 0, 40] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_if.html - * \see \c replace - * \see \c replace_copy - * \see \c replace_copy_if - */ -template - void replace_if(ForwardIterator first, ForwardIterator last, - InputIterator stencil, - Predicate pred, - const T &new_value); - - -/*! \p replace_copy copies elements from the range [first, last) to the range - * [result, result + (last-first)), except that any element equal to \p old_value - * is not copied; \p new_value is copied instead. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, \p replace_copy - * performs the assignment *(result+n) = new_value if *(first+n) == old_value, - * and *(result+n) = *(first+n) otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to copy from. - * \param last The end of the sequence to copy from. - * \param result The beginning of the sequence to copy to. - * \param old_value The value to replace. - * \param new_value The replacement value for which *i == old_value evaluates to \c true. - * \return result + (last-first) - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam T is a model of Assignable, - * \p T is a model of Equality Comparable, - * \p T may be compared for equality with \p InputIterator's \c value_type, - * and \p T is convertible to \p OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = 2; - * A[2] = 3; - * A[3] = 1; - * - * thrust::device_vector B(4); - * - * thrust::replace_copy(thrust::device, A.begin(), A.end(), B.begin(), 1, 99); - * - * // B contains [99, 2, 3, 99] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_copy.html - * \see \c copy - * \see \c replace - * \see \c replace_if - * \see \c replace_copy_if - */ -template - OutputIterator replace_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - const T &old_value, - const T &new_value); - - -/*! \p replace_copy copies elements from the range [first, last) to the range - * [result, result + (last-first)), except that any element equal to \p old_value - * is not copied; \p new_value is copied instead. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, \p replace_copy - * performs the assignment *(result+n) = new_value if *(first+n) == old_value, - * and *(result+n) = *(first+n) otherwise. - * - * \param first The beginning of the sequence to copy from. - * \param last The end of the sequence to copy from. - * \param result The beginning of the sequence to copy to. - * \param old_value The value to replace. - * \param new_value The replacement value for which *i == old_value evaluates to \c true. - * \return result + (last-first) - * - * \tparam InputIterator is a model of Input Iterator. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam T is a model of Assignable, - * \p T is a model of Equality Comparable, - * \p T may be compared for equality with \p InputIterator's \c value_type, - * and \p T is convertible to \p OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise. - * - * \code - * #include - * #include - * ... - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = 2; - * A[2] = 3; - * A[3] = 1; - * - * thrust::device_vector B(4); - * - * thrust::replace_copy(A.begin(), A.end(), B.begin(), 1, 99); - * - * // B contains [99, 2, 3, 99] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_copy.html - * \see \c copy - * \see \c replace - * \see \c replace_if - * \see \c replace_copy_if - */ -template - OutputIterator replace_copy(InputIterator first, InputIterator last, - OutputIterator result, const T &old_value, - const T &new_value); - - -/*! \p replace_copy_if copies elements from the range [first, last) to the range - * [result, result + (last-first)), except that any element for which \p pred - * is \c true is not copied; \p new_value is copied instead. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p replace_copy_if performs the assignment *(result+n) = new_value if - * pred(*(first+n)), and *(result+n) = *(first+n) otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to copy from. - * \param last The end of the sequence to copy from. - * \param result The beginning of the sequence to copy to. - * \param pred The predicate to test on every value of the range [first,last). - * \param new_value The replacement value to assign pred(*i) evaluates to \c true. - * \return result + (last-first) - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise. - * - * \code - * #include - * #include - * #include - * - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = -3; - * A[2] = 2; - * A[3] = -1; - - * thrust::device_vector B(4); - * is_less_than_zero pred; - * - * thrust::replace_copy_if(thrust::device, A.begin(), A.end(), B.begin(), pred, 0); - * - * // B contains [1, 0, 2, 0] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_copy_if.html - * \see \c replace - * \see \c replace_if - * \see \c replace_copy - */ -template - OutputIterator replace_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - Predicate pred, - const T &new_value); - - -/*! \p replace_copy_if copies elements from the range [first, last) to the range - * [result, result + (last-first)), except that any element for which \p pred - * is \c true is not copied; \p new_value is copied instead. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p replace_copy_if performs the assignment *(result+n) = new_value if - * pred(*(first+n)), and *(result+n) = *(first+n) otherwise. - * - * \param first The beginning of the sequence to copy from. - * \param last The end of the sequence to copy from. - * \param result The beginning of the sequence to copy to. - * \param pred The predicate to test on every value of the range [first,last). - * \param new_value The replacement value to assign pred(*i) evaluates to \c true. - * \return result + (last-first) - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise. - * - * \code - * #include - * #include - * - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 1; - * A[1] = -3; - * A[2] = 2; - * A[3] = -1; - - * thrust::device_vector B(4); - * is_less_than_zero pred; - * - * thrust::replace_copy_if(A.begin(), A.end(), B.begin(), pred, 0); - * - * // B contains [1, 0, 2, 0] - * \endcode - * - * \see http://www.sgi.com/tech/stl/replace_copy_if.html - * \see \c replace - * \see \c replace_if - * \see \c replace_copy - */ -template - OutputIterator replace_copy_if(InputIterator first, InputIterator last, - OutputIterator result, - Predicate pred, - const T &new_value); - - -/*! This version of \p replace_copy_if copies elements from the range [first, last) to the range - * [result, result + (last-first)), except that any element whose corresponding stencil - * element causes \p pred to be \c true is not copied; \p new_value is copied instead. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p replace_copy_if performs the assignment *(result+n) = new_value if - * pred(*(stencil+n)), and *(result+n) = *(first+n) otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence to copy from. - * \param last The end of the sequence to copy from. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the sequence to copy to. - * \param pred The predicate to test on every value of the range [stencil, stencil + (last - first)). - * \param new_value The replacement value to assign when pred(*s) evaluates to \c true. - * \return result + (last-first) - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator. - * \tparam InputIterator2 is a model of Input Iterator - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise. - * \pre \p stencil may equal \p result, but the ranges [stencil, stencil + (last - first)) and [result, result + (last - first)) shall not overlap otherwise. - * - * \code - * #include - * #include - * #include - * - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 10; - * A[1] = 20; - * A[2] = 30; - * A[3] = 40; - * - * thrust::device_vector S(4); - * S[0] = -1; - * S[1] = 0; - * S[2] = -1; - * S[3] = 0; - * - * thrust::device_vector B(4); - * is_less_than_zero pred; - * - * thrust::replace_if(thrust::device, A.begin(), A.end(), S.begin(), B.begin(), pred, 0); - * - * // B contains [0, 20, 0, 40] - * \endcode - * - * \see \c replace_copy - * \see \c replace_if - */ -template - OutputIterator replace_copy_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred, - const T &new_value); - - -/*! This version of \p replace_copy_if copies elements from the range [first, last) to the range - * [result, result + (last-first)), except that any element whose corresponding stencil - * element causes \p pred to be \c true is not copied; \p new_value is copied instead. - * - * More precisely, for every integer \c n such that 0 <= n < last-first, - * \p replace_copy_if performs the assignment *(result+n) = new_value if - * pred(*(stencil+n)), and *(result+n) = *(first+n) otherwise. - * - * \param first The beginning of the sequence to copy from. - * \param last The end of the sequence to copy from. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the sequence to copy to. - * \param pred The predicate to test on every value of the range [stencil, stencil + (last - first)). - * \param new_value The replacement value to assign when pred(*s) evaluates to \c true. - * \return result + (last-first) - * - * \tparam InputIterator1 is a model of Input Iterator. - * \tparam InputIterator2 is a model of Input Iterator - * and \p InputIterator2's \c value_type is convertible to \p Predicate's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam Predicate is a model of Predicate. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise. - * \pre \p stencil may equal \p result, but the ranges [stencil, stencil + (last - first)) and [result, result + (last - first)) shall not overlap otherwise. - * - * \code - * #include - * #include - * - * struct is_less_than_zero - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x < 0; - * } - * }; - * - * ... - * - * thrust::device_vector A(4); - * A[0] = 10; - * A[1] = 20; - * A[2] = 30; - * A[3] = 40; - * - * thrust::device_vector S(4); - * S[0] = -1; - * S[1] = 0; - * S[2] = -1; - * S[3] = 0; - * - * thrust::device_vector B(4); - * is_less_than_zero pred; - * - * thrust::replace_if(A.begin(), A.end(), S.begin(), B.begin(), pred, 0); - * - * // B contains [0, 20, 0, 40] - * \endcode - * - * \see \c replace_copy - * \see \c replace_if - */ -template - OutputIterator replace_copy_if(InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred, - const T &new_value); - - -/*! \} // end replacing - * \} // transformations - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/reverse.h b/compat/thrust/reverse.h deleted file mode 100644 index ba50c5d..0000000 --- a/compat/thrust/reverse.h +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reverse.h - * \brief Reverses the order of a range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reordering - * \ingroup algorithms - */ - - -/*! \p reverse reverses a range. That is: for every i such that - * 0 <= i <= (last - first) / 2, it exchanges *(first + i) - * and *(last - (i + 1)). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range to reverse. - * \param last The end of the range to reverse. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam BidirectionalIterator is a model of Bidirectional Iterator and - * \p BidirectionalIterator is mutable. - * - * The following code snippet demonstrates how to use \p reverse to reverse a - * \p device_vector of integers using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int data[N] = {0, 1, 2, 3, 4, 5}; - * thrust::device_vector v(data, data + N); - * thrust::reverse(thrust::device, v.begin(), v.end()); - * // v is now {5, 4, 3, 2, 1, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/reverse.html - * \see \p reverse_copy - * \see \p reverse_iterator - */ -template - void reverse(const thrust::detail::execution_policy_base &exec, - BidirectionalIterator first, - BidirectionalIterator last); - - -/*! \p reverse reverses a range. That is: for every i such that - * 0 <= i <= (last - first) / 2, it exchanges *(first + i) - * and *(last - (i + 1)). - * - * \param first The beginning of the range to reverse. - * \param last The end of the range to reverse. - * - * \tparam BidirectionalIterator is a model of Bidirectional Iterator and - * \p BidirectionalIterator is mutable. - * - * The following code snippet demonstrates how to use \p reverse to reverse a - * \p device_vector of integers. - * - * \code - * #include - * ... - * const int N = 6; - * int data[N] = {0, 1, 2, 3, 4, 5}; - * thrust::device_vector v(data, data + N); - * thrust::reverse(v.begin(), v.end()); - * // v is now {5, 4, 3, 2, 1, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/reverse.html - * \see \p reverse_copy - * \see \p reverse_iterator - */ -template - void reverse(BidirectionalIterator first, - BidirectionalIterator last); - - -/*! \p reverse_copy differs from \ref reverse only in that the reversed range - * is written to a different output range, rather than inplace. - * - * \p reverse_copy copies elements from the range [first, last) to the - * range [result, result + (last - first)) such that the copy is a - * reverse of the original range. Specifically: for every i such that - * 0 <= i < (last - first), \p reverse_copy performs the assignment - * *(result + (last - first) - i) = *(first + i). - * - * The return value is result + (last - first)). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range to reverse. - * \param last The end of the range to reverse. - * \param result The beginning of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam BidirectionalIterator is a model of Bidirectional Iterator, - * and \p BidirectionalIterator's \p value_type is convertible to \p OutputIterator's \p value_type. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The range [first, last) and the range [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p reverse_copy to reverse - * an input \p device_vector of integers to an output \p device_vector using the \p thrust::device - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int data[N] = {0, 1, 2, 3, 4, 5}; - * thrust::device_vector input(data, data + N); - * thrust::device_vector output(N); - * thrust::reverse_copy(thrust::device, v.begin(), v.end(), output.begin()); - * // input is still {0, 1, 2, 3, 4, 5} - * // output is now {5, 4, 3, 2, 1, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/reverse_copy.html - * \see \p reverse - * \see \p reverse_iterator - */ -template - OutputIterator reverse_copy(const thrust::detail::execution_policy_base &exec, - BidirectionalIterator first, - BidirectionalIterator last, - OutputIterator result); - - -/*! \p reverse_copy differs from \ref reverse only in that the reversed range - * is written to a different output range, rather than inplace. - * - * \p reverse_copy copies elements from the range [first, last) to the - * range [result, result + (last - first)) such that the copy is a - * reverse of the original range. Specifically: for every i such that - * 0 <= i < (last - first), \p reverse_copy performs the assignment - * *(result + (last - first) - i) = *(first + i). - * - * The return value is result + (last - first)). - * - * \param first The beginning of the range to reverse. - * \param last The end of the range to reverse. - * \param result The beginning of the output range. - * - * \tparam BidirectionalIterator is a model of Bidirectional Iterator, - * and \p BidirectionalIterator's \p value_type is convertible to \p OutputIterator's \p value_type. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The range [first, last) and the range [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p reverse_copy to reverse - * an input \p device_vector of integers to an output \p device_vector. - * - * \code - * #include - * ... - * const int N = 6; - * int data[N] = {0, 1, 2, 3, 4, 5}; - * thrust::device_vector input(data, data + N); - * thrust::device_vector output(N); - * thrust::reverse_copy(v.begin(), v.end(), output.begin()); - * // input is still {0, 1, 2, 3, 4, 5} - * // output is now {5, 4, 3, 2, 1, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/reverse_copy.html - * \see \p reverse - * \see \p reverse_iterator - */ -template - OutputIterator reverse_copy(BidirectionalIterator first, - BidirectionalIterator last, - OutputIterator result); - - -/*! \} // end reordering - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/scan.h b/compat/thrust/scan.h deleted file mode 100644 index 95074e6..0000000 --- a/compat/thrust/scan.h +++ /dev/null @@ -1,1552 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.h - * \brief Functions for computing prefix sums - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - - -/*! \addtogroup prefixsums Prefix Sums - * \ingroup algorithms - * \{ - */ - - -/*! \p inclusive_scan computes an inclusive prefix sum operation. The - * term 'inclusive' means that each result includes the corresponding - * input operand in the partial sum. More precisely, *first is - * assigned to *result and the sum of *first and - * *(first + 1) is assigned to *(result + 1), and so on. - * This version of \p inclusive_scan assumes plus as the associative operator. - * When the input and output sequences are the same, the scan is performed - * in-place. - - * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary - * difference between the two functions is that \c std::partial_sum guarantees - * a serial summation order, while \p inclusive_scan requires associativity of - * the binary operation to parallelize the prefix sum. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's - * \c value_type, then x + y is defined. If \c T is - * \c OutputIterator's \c value_type, then T(0) is - * defined. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan to compute an in-place - * prefix sum using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::inclusive_scan(thrust::host, data, data + 6, data); // in-place scan - * - * // data is now {1, 1, 3, 5, 6, 9} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - * - */ -template - OutputIterator inclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p inclusive_scan computes an inclusive prefix sum operation. The - * term 'inclusive' means that each result includes the corresponding - * input operand in the partial sum. More precisely, *first is - * assigned to *result and the sum of *first and - * *(first + 1) is assigned to *(result + 1), and so on. - * This version of \p inclusive_scan assumes plus as the associative operator. - * When the input and output sequences are the same, the scan is performed - * in-place. - - * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary - * difference between the two functions is that \c std::partial_sum guarantees - * a serial summation order, while \p inclusive_scan requires associativity of - * the binary operation to parallelize the prefix sum. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's - * \c value_type, then x + y is defined. If \c T is - * \c OutputIterator's \c value_type, then T(0) is - * defined. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan - * - * \code - * #include - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::inclusive_scan(data, data + 6, data); // in-place scan - * - * // data is now {1, 1, 3, 5, 6, 9} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - * - */ -template - OutputIterator inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p inclusive_scan computes an inclusive prefix sum operation. The - * term 'inclusive' means that each result includes the corresponding - * input operand in the partial sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary - * difference between the two functions is that \c std::partial_sum guarantees - * a serial summation order, while \p inclusive_scan requires associativity of - * the binary operation to parallelize the prefix sum. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator - * and \c OutputIterator's \c value_type is convertible to - * both \c AssociativeOperator's \c first_argument_type and - * \c second_argument_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan to compute an in-place - * prefix sum using the \p thrust::host execution policy for parallelization: - * - * \code - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * thrust::maximum binary_op; - * - * thrust::inclusive_scan(thrust::host, data, data + 10, data, binary_op); // in-place scan - * - * // data is now {-5, 0, 2, 2, 2, 4, 4, 4, 4, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator inclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - AssociativeOperator binary_op); - - -/*! \p inclusive_scan computes an inclusive prefix sum operation. The - * term 'inclusive' means that each result includes the corresponding - * input operand in the partial sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary - * difference between the two functions is that \c std::partial_sum guarantees - * a serial summation order, while \p inclusive_scan requires associativity of - * the binary operation to parallelize the prefix sum. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator - * and \c OutputIterator's \c value_type is convertible to - * both \c AssociativeOperator's \c first_argument_type and - * \c second_argument_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan - * - * \code - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * thrust::maximum binary_op; - * - * thrust::inclusive_scan(data, data + 10, data, binary_op); // in-place scan - * - * // data is now {-5, 0, 2, 2, 2, 4, 4, 4, 4, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - AssociativeOperator binary_op); - - -/*! \p exclusive_scan computes an exclusive prefix sum operation. The - * term 'exclusive' means that each result does not include the - * corresponding input operand in the partial sum. More precisely, - * 0 is assigned to *result and the sum of - * 0 and *first is assigned to *(result + 1), - * and so on. This version of \p exclusive_scan assumes plus as the - * associative operator and \c 0 as the initial value. When the input and - * output sequences are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's - * \c value_type, then x + y is defined. If \c T is - * \c OutputIterator's \c value_type, then T(0) is - * defined. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan to compute an in-place - * prefix sum using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::exclusive_scan(thrust::host, data, data + 6, data); // in-place scan - * - * // data is now {0, 1, 1, 3, 5, 6} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p exclusive_scan computes an exclusive prefix sum operation. The - * term 'exclusive' means that each result does not include the - * corresponding input operand in the partial sum. More precisely, - * 0 is assigned to *result and the sum of - * 0 and *first is assigned to *(result + 1), - * and so on. This version of \p exclusive_scan assumes plus as the - * associative operator and \c 0 as the initial value. When the input and - * output sequences are the same, the scan is performed in-place. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's - * \c value_type, then x + y is defined. If \c T is - * \c OutputIterator's \c value_type, then T(0) is - * defined. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan - * - * \code - * #include - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::exclusive_scan(data, data + 6, data); // in-place scan - * - * // data is now {0, 1, 1, 3, 5, 6} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p exclusive_scan computes an exclusive prefix sum operation. The - * term 'exclusive' means that each result does not include the - * corresponding input operand in the partial sum. More precisely, - * \p init is assigned to *result and the sum of \p init and - * *first is assigned to *(result + 1), and so on. - * This version of \p exclusive_scan assumes plus as the associative - * operator but requires an initial value \p init. When the input and - * output sequences are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param init The initial value. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's - * \c value_type, then x + y is defined. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan to compute an in-place - * prefix sum using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::exclusive_scan(thrust::host, data, data + 6, data, 4); // in-place scan - * - * // data is now {4, 5, 5, 7, 9, 10} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init); - - -/*! \p exclusive_scan computes an exclusive prefix sum operation. The - * term 'exclusive' means that each result does not include the - * corresponding input operand in the partial sum. More precisely, - * \p init is assigned to *result and the sum of \p init and - * *first is assigned to *(result + 1), and so on. - * This version of \p exclusive_scan assumes plus as the associative - * operator but requires an initial value \p init. When the input and - * output sequences are the same, the scan is performed in-place. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param init The initial value. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's - * \c value_type, then x + y is defined. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan - * - * \code - * #include - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::exclusive_scan(data, data + 6, data, 4); // in-place scan - * - * // data is now {4, 5, 5, 7, 9, 10} - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - T init); - - -/*! \p exclusive_scan computes an exclusive prefix sum operation. The - * term 'exclusive' means that each result does not include the - * corresponding input operand in the partial sum. More precisely, - * \p init is assigned to \*result and the value - * binary_op(init, \*first) is assigned to \*(result + 1), - * and so on. This version of the function requires both and associative - * operator and an initial value \p init. When the input and output - * sequences are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param init The initial value. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator - * and \c OutputIterator's \c value_type is convertible to - * both \c AssociativeOperator's \c first_argument_type and - * \c second_argument_type. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan to compute an in-place - * prefix sum using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * thrust::maximum binary_op; - * - * thrust::exclusive_scan(thrust::host, data, data + 10, data, 1, binary_op); // in-place scan - * - * // data is now {1, 1, 1, 2, 2, 2, 4, 4, 4, 4 } - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - AssociativeOperator binary_op); - - -/*! \p exclusive_scan computes an exclusive prefix sum operation. The - * term 'exclusive' means that each result does not include the - * corresponding input operand in the partial sum. More precisely, - * \p init is assigned to \*result and the value - * binary_op(init, \*first) is assigned to \*(result + 1), - * and so on. This version of the function requires both and associative - * operator and an initial value \p init. When the input and output - * sequences are the same, the scan is performed in-place. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param init The initial value. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to - * \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator - * and \c OutputIterator's \c value_type is convertible to - * both \c AssociativeOperator's \c first_argument_type and - * \c second_argument_type. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan - * - * \code - * #include - * #include - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * thrust::maximum binary_op; - * - * thrust::exclusive_scan(data, data + 10, data, 1, binary_op); // in-place scan - * - * // data is now {1, 1, 1, 2, 2, 2, 4, 4, 4, 4 } - * \endcode - * - * \see http://www.sgi.com/tech/stl/partial_sum.html - */ -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - T init, - AssociativeOperator binary_op); - - -/*! \addtogroup segmentedprefixsums Segmented Prefix Sums - * \ingroup prefixsums - * \{ - */ - - -/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix - * sum operation. The term 'inclusive' means that each result includes - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate inclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p inclusive_scan_by_key assumes \c equal_to as the binary - * predicate used to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1) - * belong to the same segment if *i == *(i+1), and belong to - * different segments otherwise. - * - * This version of \p inclusive_scan_by_key assumes \c plus as the associative - * operator used to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan_by_key using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * - * thrust::inclusive_scan_by_key(thrust::host, keys, keys + 10, vals, vals); // in-place scan - * - * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; - * \endcode - * - * \see inclusive_scan - * \see exclusive_scan_by_key - * - */ -template - OutputIterator inclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result); - - -/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix - * sum operation. The term 'inclusive' means that each result includes - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate inclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p inclusive_scan_by_key assumes \c equal_to as the binary - * predicate used to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1) - * belong to the same segment if *i == *(i+1), and belong to - * different segments otherwise. - * - * This version of \p inclusive_scan_by_key assumes \c plus as the associative - * operator used to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan_by_key - * - * \code - * #include - * - * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * - * thrust::inclusive_scan_by_key(keys, keys + 10, vals, vals); // in-place scan - * - * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; - * \endcode - * - * \see inclusive_scan - * \see exclusive_scan_by_key - * - */ -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result); - - -/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix - * sum operation. The term 'inclusive' means that each result includes - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate inclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p inclusive_scan_by_key uses the binary predicate - * \c pred to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1) - * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to - * different segments otherwise. - * - * This version of \p inclusive_scan_by_key assumes \c plus as the associative - * operator used to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param binary_pred The binary predicate used to determine equality of keys. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan_by_key using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * - * thrust::equal_to binary_pred; - * - * thrust::inclusive_scan_by_key(thrust::host, keys, keys + 10, vals, vals, binary_pred); // in-place scan - * - * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; - * \endcode - * - * \see inclusive_scan - * \see exclusive_scan_by_key - * - */ -template - OutputIterator inclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred); - - -/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix - * sum operation. The term 'inclusive' means that each result includes - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate inclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p inclusive_scan_by_key uses the binary predicate - * \c pred to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1) - * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to - * different segments otherwise. - * - * This version of \p inclusive_scan_by_key assumes \c plus as the associative - * operator used to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param binary_pred The binary predicate used to determine equality of keys. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan_by_key - * - * \code - * #include - * #include - * - * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * - * thrust::equal_to binary_pred; - * - * thrust::inclusive_scan_by_key(keys, keys + 10, vals, vals, binary_pred); // in-place scan - * - * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; - * \endcode - * - * \see inclusive_scan - * \see exclusive_scan_by_key - * - */ -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred); - - -/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix - * sum operation. The term 'inclusive' means that each result includes - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate inclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p inclusive_scan_by_key uses the binary predicate - * \c pred to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1) - * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to - * different segments otherwise. - * - * This version of \p inclusive_scan_by_key uses the associative operator - * \c binary_op to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param binary_pred The binary predicate used to determine equality of keys. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * \tparam BinaryPredicate is a model of Binary Predicate. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan_by_key using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * - * thrust::equal_to binary_pred; - * thrust::plus binary_op; - * - * thrust::inclusive_scan_by_key(thrust::host, keys, keys + 10, vals, vals, binary_pred, binary_op); // in-place scan - * - * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; - * \endcode - * - * \see inclusive_scan - * \see exclusive_scan_by_key - * - */ -template - OutputIterator inclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - AssociativeOperator binary_op); - - -/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix - * sum operation. The term 'inclusive' means that each result includes - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate inclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p inclusive_scan_by_key uses the binary predicate - * \c pred to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1) - * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to - * different segments otherwise. - * - * This version of \p inclusive_scan_by_key uses the associative operator - * \c binary_op to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param binary_pred The binary predicate used to determine equality of keys. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * \tparam BinaryPredicate is a model of Binary Predicate. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p inclusive_scan_by_key - * - * \code - * #include - * #include - * - * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * - * thrust::equal_to binary_pred; - * thrust::plus binary_op; - * - * thrust::inclusive_scan_by_key(keys, keys + 10, vals, vals, binary_pred, binary_op); // in-place scan - * - * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; - * \endcode - * - * \see inclusive_scan - * \see exclusive_scan_by_key - * - */ -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - AssociativeOperator binary_op); - - -/*! \p exclusive_scan_by_key computes an exclusive segmented prefix - * - * This version of \p exclusive_scan_by_key uses the value \c 0 to - * initialize the exclusive scan operation. - * - * This version of \p exclusive_scan_by_key assumes \c plus as the associative - * operator used to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * This version of \p exclusive_scan_by_key assumes \c equal_to as the binary - * predicate used to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1 - * belong to the same segment if *i == *(i+1), and belong to - * different segments otherwise. - * - * Refer to the most general form of \p exclusive_scan_by_key for additional details. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals); // in-place scan - * - * // vals is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3}; - * \endcode - * - * \see exclusive_scan - * - */ -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result); - - -/*! \p exclusive_scan_by_key computes an exclusive segmented prefix - * - * This version of \p exclusive_scan_by_key uses the value \c 0 to - * initialize the exclusive scan operation. - * - * This version of \p exclusive_scan_by_key assumes \c plus as the associative - * operator used to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * This version of \p exclusive_scan_by_key assumes \c equal_to as the binary - * predicate used to compare adjacent keys. Specifically, consecutive iterators - * i and i+1 in the range [first1, last1 - * belong to the same segment if *i == *(i+1), and belong to - * different segments otherwise. - * - * Refer to the most general form of \p exclusive_scan_by_key for additional details. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key. - * - * \code - * #include - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * thrust::exclusive_scan_by_key(key, key + 10, vals, vals); // in-place scan - * - * // vals is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3}; - * \endcode - * - * \see exclusive_scan - * - */ -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result); - - -/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix - * sum operation. The term 'exclusive' means that each result does not include - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate exclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p exclusive_scan_by_key uses the value \c init to - * initialize the exclusive scan operation. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param init The initial of the exclusive sum value. - * \return The end of the output sequence. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the \p - * thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * int init = 5; - * - * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals, init); // in-place scan - * - * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; - * \endcode - * - * \see exclusive_scan - * \see inclusive_scan_by_key - * - */ -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init); - - -/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix - * sum operation. The term 'exclusive' means that each result does not include - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate exclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p exclusive_scan_by_key uses the value \c init to - * initialize the exclusive scan operation. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param init The initial of the exclusive sum value. - * \return The end of the output sequence. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key - * - * \code - * #include - * #include - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * int init = 5; - * - * thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init); // in-place scan - * - * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; - * \endcode - * - * \see exclusive_scan - * \see inclusive_scan_by_key - * - */ -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init); - - -/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix - * sum operation. The term 'exclusive' means that each result does not include - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate exclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p exclusive_scan_by_key uses the value \c init to - * initialize the exclusive scan operation. - * - * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred - * to compare adjacent keys. Specifically, consecutive iterators i and - * i+1 in the range [first1, last1) belong to the same segment if - * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param init The initial of the exclusive sum value. - * \param binary_pred The binary predicate used to determine equality of keys. - * \return The end of the output sequence. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * int init = 5; - * - * thrust::equal_to binary_pred; - * - * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals, init, binary_pred); // in-place scan - * - * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; - * \endcode - * - * \see exclusive_scan - * \see inclusive_scan_by_key - * - */ -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred); - - -/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix - * sum operation. The term 'exclusive' means that each result does not include - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate exclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p exclusive_scan_by_key uses the value \c init to - * initialize the exclusive scan operation. - * - * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred - * to compare adjacent keys. Specifically, consecutive iterators i and - * i+1 in the range [first1, last1) belong to the same segment if - * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param init The initial of the exclusive sum value. - * \param binary_pred The binary predicate used to determine equality of keys. - * \return The end of the output sequence. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key - * - * \code - * #include - * #include - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * int init = 5; - * - * thrust::equal_to binary_pred; - * - * thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred); // in-place scan - * - * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; - * \endcode - * - * \see exclusive_scan - * \see inclusive_scan_by_key - * - */ -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred); - - -/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix - * sum operation. The term 'exclusive' means that each result does not include - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate exclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p exclusive_scan_by_key uses the value \c init to - * initialize the exclusive scan operation. - * - * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred - * to compare adjacent keys. Specifically, consecutive iterators i and - * i+1 in the range [first1, last1) belong to the same segment if - * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. - * - * This version of \p exclusive_scan_by_key uses the associative operator - * \c binary_op to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param init The initial of the exclusive sum value. - * \param binary_pred The binary predicate used to determine equality of keys. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * int init = 5; - * - * thrust::equal_to binary_pred; - * thrust::plus binary_op; - * - * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals, init, binary_pred, binary_op); // in-place scan - * - * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; - * \endcode - * - * \see exclusive_scan - * \see inclusive_scan_by_key - * - */ -template - OutputIterator exclusive_scan_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - AssociativeOperator binary_op); - - -/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix - * sum operation. The term 'exclusive' means that each result does not include - * the corresponding input operand in the partial sum. The term 'segmented' - * means that the partial sums are broken into distinct segments. In other - * words, within each segment a separate exclusive scan operation is computed. - * Refer to the code sample below for example usage. - * - * This version of \p exclusive_scan_by_key uses the value \c init to - * initialize the exclusive scan operation. - * - * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred - * to compare adjacent keys. Specifically, consecutive iterators i and - * i+1 in the range [first1, last1) belong to the same segment if - * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. - * - * This version of \p exclusive_scan_by_key uses the associative operator - * \c binary_op to perform the prefix sum. When the input and output sequences - * are the same, the scan is performed in-place. - * - * \param first1 The beginning of the key sequence. - * \param last1 The end of the key sequence. - * \param first2 The beginning of the input value sequence. - * \param result The beginning of the output value sequence. - * \param init The initial of the exclusive sum value. - * \param binary_pred The binary predicate used to determine equality of keys. - * \param binary_op The associatve operator used to 'sum' values. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam OutputIterator is a model of Output Iterator, - * and if \c x and \c y are objects of \c OutputIterator's \c value_type, then - * binary_op(x,y) is defined. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first1 may equal \p result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise. - * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p exclusive_scan_by_key - * - * \code - * #include - * #include - * - * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; - * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - * - * int init = 5; - * - * thrust::equal_to binary_pred; - * thrust::plus binary_op; - * - * thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred, binary_op); // in-place scan - * - * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; - * \endcode - * - * \see exclusive_scan - * \see inclusive_scan_by_key - * - */ -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - AssociativeOperator binary_op); - - -/*! \} // end segmentedprefixsums - */ - - -/*! \} // end prefix sums - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/scatter.h b/compat/thrust/scatter.h deleted file mode 100644 index 59604ca..0000000 --- a/compat/thrust/scatter.h +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scatter.h - * \brief Irregular copying to a destination range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup scattering - * \ingroup copying - * \{ - */ - - -/*! \p scatter copies elements from a source range into an output array - * according to a map. For each iterator \c i in the range [\p first, \p last), - * the value \c *i is assigned to output[*(map + (i - first))]. The - * output iterator must permit random access. If the same index - * appears more than once in the range [map, map + (last - first)), - * the result is undefined. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first Beginning of the sequence of values to scatter. - * \param last End of the sequence of values to scatter. - * \param map Beginning of the sequence of output indices. - * \param result Destination of the source elements. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam RandomAccessIterator must be a model of Random Access iterator. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The expression `result[*i]` shall be valid for all iterators in the range `[map,map + (last - first))`. - * - * The following code snippet demonstrates how to use \p scatter to - * reorder a range using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * // mark even indices with a 1; odd indices with a 0 - * int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * thrust::device_vector d_values(values, values + 10); - * - * // scatter all even indices into the first half of the - * // range, and odd indices vice versa - * int map[10] = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10); - * thrust::scatter(thrust::device, - * d_values.begin(), d_values.end(), - * d_map.begin(), d_output.begin()); - * // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * \endcode - * - * \note \p scatter is the inverse of thrust::gather. - */ -template - void scatter(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - RandomAccessIterator result); - - -/*! \p scatter copies elements from a source range into an output array - * according to a map. For each iterator \c i in the range [\p first, \p last), - * the value \c *i is assigned to output[*(map + (i - first))]. The - * output iterator must permit random access. If the same index - * appears more than once in the range [map, map + (last - first)), - * the result is undefined. - * - * \param first Beginning of the sequence of values to scatter. - * \param last End of the sequence of values to scatter. - * \param map Beginning of the sequence of output indices. - * \param result Destination of the source elements. - * - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam RandomAccessIterator must be a model of Random Access iterator. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The expression `result[*i]` shall be valid for all iterators in the range `[map,map + (last - first))`. - * - * The following code snippet demonstrates how to use \p scatter to - * reorder a range. - * - * \code - * #include - * #include - * ... - * // mark even indices with a 1; odd indices with a 0 - * int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * thrust::device_vector d_values(values, values + 10); - * - * // scatter all even indices into the first half of the - * // range, and odd indices vice versa - * int map[10] = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9}; - * thrust::device_vector d_map(map, map + 10); - * - * thrust::device_vector d_output(10); - * thrust::scatter(d_values.begin(), d_values.end(), - * d_map.begin(), d_output.begin()); - * // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} - * \endcode - * - * \note \p scatter is the inverse of thrust::gather. - */ -template - void scatter(InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - RandomAccessIterator result); - - -/*! \p scatter_if conditionally copies elements from a source range into an - * output array according to a map. For each iterator \c i in the - * range [first, last) such that *(stencil + (i - first)) is - * true, the value \c *i is assigned to output[*(map + (i - first))]. - * The output iterator must permit random access. If the same index - * appears more than once in the range [map, map + (last - first)) - * the result is undefined. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first Beginning of the sequence of values to scatter. - * \param last End of the sequence of values to scatter. - * \param map Beginning of the sequence of output indices. - * \param stencil Beginning of the sequence of predicate values. - * \param output Beginning of the destination range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c value_type must be convertible to \c bool. - * \tparam RandomAccessIterator must be a model of Random Access iterator. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `*(stencil + i) != false`. - * - * \code - * #include - * #include - * ... - * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; - * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; - * int S[8] = {1, 0, 1, 0, 1, 0, 1, 0}; - * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - * - * thrust::scatter_if(thrust::host, V, V + 8, M, S, D); - * - * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; - * \endcode - * - * \note \p scatter_if is the inverse of thrust::gather_if. - */ -template - void scatter_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output); - - -/*! \p scatter_if conditionally copies elements from a source range into an - * output array according to a map. For each iterator \c i in the - * range [first, last) such that *(stencil + (i - first)) is - * true, the value \c *i is assigned to output[*(map + (i - first))]. - * The output iterator must permit random access. If the same index - * appears more than once in the range [map, map + (last - first)) - * the result is undefined. - * - * \param first Beginning of the sequence of values to scatter. - * \param last End of the sequence of values to scatter. - * \param map Beginning of the sequence of output indices. - * \param stencil Beginning of the sequence of predicate values. - * \param output Beginning of the destination range. - * - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c value_type must be convertible to \c bool. - * \tparam RandomAccessIterator must be a model of Random Access iterator. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `*(stencil + i) != false`. - * - * \code - * #include - * ... - * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; - * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; - * int S[8] = {1, 0, 1, 0, 1, 0, 1, 0}; - * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - * - * thrust::scatter_if(V, V + 8, M, S, D); - * - * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; - * \endcode - * - * \note \p scatter_if is the inverse of thrust::gather_if. - */ -template - void scatter_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output); - - -/*! \p scatter_if conditionally copies elements from a source range into an - * output array according to a map. For each iterator \c i in the - * range [first, last) such that pred(*(stencil + (i - first))) is - * \c true, the value \c *i is assigned to output[*(map + (i - first))]. - * The output iterator must permit random access. If the same index - * appears more than once in the range [map, map + (last - first)) - * the result is undefined. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first Beginning of the sequence of values to scatter. - * \param last End of the sequence of values to scatter. - * \param map Beginning of the sequence of output indices. - * \param stencil Beginning of the sequence of predicate values. - * \param output Beginning of the destination range. - * \param pred Predicate to apply to the stencil values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c value_type must be convertible to \c Predicate's \c argument_type. - * \tparam RandomAccessIterator must be a model of Random Access iterator. - * \tparam Predicate must be a model of Predicate. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `pred(*(stencil + i)) != false`. - * - * \code - * #include - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return (x % 2) == 0; - * } - * }; - * - * ... - * - * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; - * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; - * int S[8] = {2, 1, 2, 1, 2, 1, 2, 1}; - * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - * - * is_even pred; - * thrust::scatter_if(thrust::host, V, V + 8, M, S, D, pred); - * - * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; - * \endcode - * - * \note \p scatter_if is the inverse of thrust::gather_if. - */ -template - void scatter_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output, - Predicate pred); - - -/*! \p scatter_if conditionally copies elements from a source range into an - * output array according to a map. For each iterator \c i in the - * range [first, last) such that pred(*(stencil + (i - first))) is - * \c true, the value \c *i is assigned to output[*(map + (i - first))]. - * The output iterator must permit random access. If the same index - * appears more than once in the range [map, map + (last - first)) - * the result is undefined. - * - * \param first Beginning of the sequence of values to scatter. - * \param last End of the sequence of values to scatter. - * \param map Beginning of the sequence of output indices. - * \param stencil Beginning of the sequence of predicate values. - * \param output Beginning of the destination range. - * \param pred Predicate to apply to the stencil values. - * - * \tparam InputIterator1 must be a model of Input Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. - * \tparam InputIterator2 must be a model of Input Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type. - * \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c value_type must be convertible to \c Predicate's \c argument_type. - * \tparam RandomAccessIterator must be a model of Random Access iterator. - * \tparam Predicate must be a model of Predicate. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. - * - * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `pred(*(stencil + i)) != false`. - * - * \code - * #include - * - * struct is_even - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return (x % 2) == 0; - * } - * }; - * - * ... - * - * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; - * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; - * int S[8] = {2, 1, 2, 1, 2, 1, 2, 1}; - * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - * - * is_even pred; - * thrust::scatter_if(V, V + 8, M, S, D, pred); - * - * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; - * \endcode - * - * \note \p scatter_if is the inverse of thrust::gather_if. - */ -template - void scatter_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output, - Predicate pred); - - -/*! \} // end scattering - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/sequence.h b/compat/thrust/sequence.h deleted file mode 100644 index 6c54a5b..0000000 --- a/compat/thrust/sequence.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file sequence.h - * \brief Fills a range with a sequence of numbers - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup transformations - * \{ - */ - - -/*! \p sequence fills the range [first, last) with a sequence of numbers. - * - * For each iterator \c i in the range [first, last), this version of - * \p sequence performs the assignment *i = (i - first). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * - * The following code snippet demonstrates how to use \p sequence to fill a range - * with a sequence of numbers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::sequence(thrust::host, A, A + 10); - * // A is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - * \endcode - * - * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no - * guarantee on order of execution. - * - * \see http://www.sgi.com/tech/stl/iota.html - */ -template - void sequence(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last); - - -/*! \p sequence fills the range [first, last) with a sequence of numbers. - * - * For each iterator \c i in the range [first, last), this version of - * \p sequence performs the assignment *i = (i - first). - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * - * The following code snippet demonstrates how to use \p sequence to fill a range - * with a sequence of numbers. - * - * \code - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::sequence(A, A + 10); - * // A is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - * \endcode - * - * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no - * guarantee on order of execution. - * - * \see http://www.sgi.com/tech/stl/iota.html - */ -template - void sequence(ForwardIterator first, - ForwardIterator last); - - -/*! \p sequence fills the range [first, last) with a sequence of numbers. - * - * For each iterator \c i in the range [first, last), this version of - * \p sequence performs the assignment *i = init + (i - first). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param init The first value of the sequence of numbers. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p sequence to fill a range - * with a sequence of numbers starting from the value 1 using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::sequence(thrust::host, A, A + 10, 1); - * // A is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * \endcode - * - * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no - * guarantee on order of execution. - * - * \see http://www.sgi.com/tech/stl/iota.html - */ -template - void sequence(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - T init); - - -/*! \p sequence fills the range [first, last) with a sequence of numbers. - * - * For each iterator \c i in the range [first, last), this version of - * \p sequence performs the assignment *i = init + (i - first). - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param init The first value of the sequence of numbers. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p sequence to fill a range - * with a sequence of numbers starting from the value 1. - * - * \code - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::sequence(A, A + 10, 1); - * // A is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - * \endcode - * - * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no - * guarantee on order of execution. - * - * \see http://www.sgi.com/tech/stl/iota.html - */ -template - void sequence(ForwardIterator first, - ForwardIterator last, - T init); - - -/*! \p sequence fills the range [first, last) with a sequence of numbers. - * - * For each iterator \c i in the range [first, last), this version of - * \p sequence performs the assignment *i = init + step * (i - first). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param init The first value of the sequence of numbers - * \param step The difference between consecutive elements. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p sequence to fill a range - * with a sequence of numbers starting from the value 1 with a step size of 3 using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::sequence(thrust::host, A, A + 10, 1, 3); - * // A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28} - * \endcode - * - * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no - * guarantee on order of execution. - * - * \see http://www.sgi.com/tech/stl/iota.html - */ -template - void sequence(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - T init, - T step); - - -/*! \p sequence fills the range [first, last) with a sequence of numbers. - * - * For each iterator \c i in the range [first, last), this version of - * \p sequence performs the assignment *i = init + step * (i - first). - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param init The first value of the sequence of numbers - * \param step The difference between consecutive elements. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * \tparam T is a model of Assignable, - * and \p T is convertible to \p ForwardIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p sequence to fill a range - * with a sequence of numbers starting from the value 1 with a step size of 3. - * - * \code - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::sequence(A, A + 10, 1, 3); - * // A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28} - * \endcode - * - * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no - * guarantee on order of execution. - * - * \see http://www.sgi.com/tech/stl/iota.html - */ -template - void sequence(ForwardIterator first, - ForwardIterator last, - T init, - T step); - - -/*! \} // end transformations - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/set_operations.h b/compat/thrust/set_operations.h deleted file mode 100644 index a7ee624..0000000 --- a/compat/thrust/set_operations.h +++ /dev/null @@ -1,2947 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file set_operations.h - * \brief Set theoretic operations for sorted ranges - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup set_operations Set Operations - * \ingroup algorithms - * \{ - */ - - -/*! \p set_difference constructs a sorted range that is the set difference of the sorted - * ranges [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_difference performs the "difference" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1) and not contained in [first2, last1). The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [first1, last1) range shall be copied to the output range. - * - * This version of \p set_difference compares elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_difference to compute the - * set difference of two sets of integers sorted in ascending order using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {0, 1, 3, 4, 5, 6, 9}; - * int A2[5] = {1, 3, 5, 7, 9}; - * - * int result[3]; - * - * int *result_end = thrust::set_difference(thrust::host, A1, A1 + 6, A2, A2 + 5, result); - * // result is now {0, 4, 6} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_difference.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_difference constructs a sorted range that is the set difference of the sorted - * ranges [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_difference performs the "difference" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1) and not contained in [first2, last1). The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [first1, last1) range shall be copied to the output range. - * - * This version of \p set_difference compares elements using \c operator<. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_difference to compute the - * set difference of two sets of integers sorted in ascending order. - * - * \code - * #include - * ... - * int A1[6] = {0, 1, 3, 4, 5, 6, 9}; - * int A2[5] = {1, 3, 5, 7, 9}; - * - * int result[3]; - * - * int *result_end = thrust::set_difference(A1, A1 + 6, A2, A2 + 5, result); - * // result is now {0, 4, 6} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_difference.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_difference constructs a sorted range that is the set difference of the sorted - * ranges [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_difference performs the "difference" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1) and not contained in [first2, last1). The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [first1, last1) range shall be copied to the output range. - * - * This version of \p set_difference compares elements using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_difference to compute the - * set difference of two sets of integers sorted in descending order using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A1[6] = {9, 6, 5, 4, 3, 1, 0}; - * int A2[5] = {9, 7, 5, 3, 1}; - * - * int result[3]; - * - * int *result_end = thrust::set_difference(thrust::host, A1, A1 + 6, A2, A2 + 5, result, thrust::greater()); - * // result is now {6, 4, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_difference.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_difference constructs a sorted range that is the set difference of the sorted - * ranges [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_difference performs the "difference" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1) and not contained in [first2, last1). The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [first1, last1) range shall be copied to the output range. - * - * This version of \p set_difference compares elements using a function object \p comp. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_difference to compute the - * set difference of two sets of integers sorted in descending order. - * - * \code - * #include - * #include - * ... - * int A1[6] = {9, 6, 5, 4, 3, 1, 0}; - * int A2[5] = {9, 7, 5, 3, 1}; - * - * int result[3]; - * - * int *result_end = thrust::set_difference(A1, A1 + 6, A2, A2 + 5, result, thrust::greater()); - * // result is now {6, 4, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_difference.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_intersection constructs a sorted range that is the - * intersection of sorted ranges [first1, last1) and - * [first2, last2). The return value is the end of the - * output range. - * - * In the simplest case, \p set_intersection performs the - * "intersection" operation from set theory: the output range - * contains a copy of every element that is contained in both - * [first1, last1) and [first2, last2). The - * general case is more complicated, because the input ranges may - * contain duplicate elements. The generalization is that if a value - * appears \c m times in [first1, last1) and \c n times in - * [first2, last2) (where \c m may be zero), then it - * appears min(m,n) times in the output range. - * \p set_intersection is stable, meaning that both elements are - * copied from the first range rather than the second, and that the - * relative order of elements in the output range is the same as in - * the first input range. - * - * This version of \p set_intersection compares objects using - * \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_intersection to compute the - * set intersection of two sets of integers sorted in ascending order using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {1, 3, 5, 7, 9, 11}; - * int A2[7] = {1, 1, 2, 3, 5, 8, 13}; - * - * int result[7]; - * - * int *result_end = thrust::set_intersection(thrust::host, A1, A1 + 6, A2, A2 + 7, result); - * // result is now {1, 3, 5} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_intersection.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_intersection(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_intersection constructs a sorted range that is the - * intersection of sorted ranges [first1, last1) and - * [first2, last2). The return value is the end of the - * output range. - * - * In the simplest case, \p set_intersection performs the - * "intersection" operation from set theory: the output range - * contains a copy of every element that is contained in both - * [first1, last1) and [first2, last2). The - * general case is more complicated, because the input ranges may - * contain duplicate elements. The generalization is that if a value - * appears \c m times in [first1, last1) and \c n times in - * [first2, last2) (where \c m may be zero), then it - * appears min(m,n) times in the output range. - * \p set_intersection is stable, meaning that both elements are - * copied from the first range rather than the second, and that the - * relative order of elements in the output range is the same as in - * the first input range. - * - * This version of \p set_intersection compares objects using - * \c operator<. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_intersection to compute the - * set intersection of two sets of integers sorted in ascending order. - * - * \code - * #include - * ... - * int A1[6] = {1, 3, 5, 7, 9, 11}; - * int A2[7] = {1, 1, 2, 3, 5, 8, 13}; - * - * int result[7]; - * - * int *result_end = thrust::set_intersection(A1, A1 + 6, A2, A2 + 7, result); - * // result is now {1, 3, 5} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_intersection.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_intersection(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_intersection constructs a sorted range that is the - * intersection of sorted ranges [first1, last1) and - * [first2, last2). The return value is the end of the - * output range. - * - * In the simplest case, \p set_intersection performs the - * "intersection" operation from set theory: the output range - * contains a copy of every element that is contained in both - * [first1, last1) and [first2, last2). The - * general case is more complicated, because the input ranges may - * contain duplicate elements. The generalization is that if a value - * appears \c m times in [first1, last1) and \c n times in - * [first2, last2) (where \c m may be zero), then it - * appears min(m,n) times in the output range. - * \p set_intersection is stable, meaning that both elements are - * copied from the first range rather than the second, and that the - * relative order of elements in the output range is the same as in - * the first input range. - * - * This version of \p set_intersection compares elements using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * The following code snippet demonstrates how to use \p set_intersection to compute - * the set intersection of sets of integers sorted in descending order using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {11, 9, 7, 5, 3, 1}; - * int A2[7] = {13, 8, 5, 3, 2, 1, 1}; - * - * int result[3]; - * - * int *result_end = thrust::set_intersection(thrust::host, A1, A1 + 6, A2, A2 + 7, result, thrust::greater()); - * // result is now {5, 3, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_intersection.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_intersection(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_intersection constructs a sorted range that is the - * intersection of sorted ranges [first1, last1) and - * [first2, last2). The return value is the end of the - * output range. - * - * In the simplest case, \p set_intersection performs the - * "intersection" operation from set theory: the output range - * contains a copy of every element that is contained in both - * [first1, last1) and [first2, last2). The - * general case is more complicated, because the input ranges may - * contain duplicate elements. The generalization is that if a value - * appears \c m times in [first1, last1) and \c n times in - * [first2, last2) (where \c m may be zero), then it - * appears min(m,n) times in the output range. - * \p set_intersection is stable, meaning that both elements are - * copied from the first range rather than the second, and that the - * relative order of elements in the output range is the same as in - * the first input range. - * - * This version of \p set_intersection compares elements using a function object \p comp. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * The following code snippet demonstrates how to use \p set_intersection to compute - * the set intersection of sets of integers sorted in descending order. - * - * \code - * #include - * ... - * int A1[6] = {11, 9, 7, 5, 3, 1}; - * int A2[7] = {13, 8, 5, 3, 2, 1, 1}; - * - * int result[3]; - * - * int *result_end = thrust::set_intersection(A1, A1 + 6, A2, A2 + 7, result, thrust::greater()); - * // result is now {5, 3, 1} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_intersection.html - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_intersection(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_symmetric_difference constructs a sorted range that is the set symmetric - * difference of the sorted ranges [first1, last1) and [first2, last2). - * The return value is the end of the output range. - * - * In the simplest case, \p set_symmetric_difference performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [first1, last1) but not [first2, last1), and a copy of - * every element that is contained in [first2, last2) but not [first1, last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements that are - * equivalent to each other and [first2, last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [first1, last1) if m > n, and - * the last n - m of these elements from [first2, last2) if m < n. - * - * This version of \p set_union compares elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference to compute - * the symmetric difference of two sets of integers sorted in ascending order using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {0, 1, 2, 2, 4, 6, 7}; - * int A2[5] = {1, 1, 2, 5, 8}; - * - * int result[6]; - * - * int *result_end = thrust::set_symmetric_difference(thrust::host, A1, A1 + 6, A2, A2 + 5, result); - * // result = {0, 4, 5, 6, 7, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_symmetric_difference.html - * \see \p merge - * \see \p includes - * \see \p set_difference - * \see \p set_union - * \see \p set_intersection - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_symmetric_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_symmetric_difference constructs a sorted range that is the set symmetric - * difference of the sorted ranges [first1, last1) and [first2, last2). - * The return value is the end of the output range. - * - * In the simplest case, \p set_symmetric_difference performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [first1, last1) but not [first2, last1), and a copy of - * every element that is contained in [first2, last2) but not [first1, last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements that are - * equivalent to each other and [first2, last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [first1, last1) if m > n, and - * the last n - m of these elements from [first2, last2) if m < n. - * - * This version of \p set_union compares elements using \c operator<. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference to compute - * the symmetric difference of two sets of integers sorted in ascending order. - * - * \code - * #include - * ... - * int A1[6] = {0, 1, 2, 2, 4, 6, 7}; - * int A2[5] = {1, 1, 2, 5, 8}; - * - * int result[6]; - * - * int *result_end = thrust::set_symmetric_difference(A1, A1 + 6, A2, A2 + 5, result); - * // result = {0, 4, 5, 6, 7, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_symmetric_difference.html - * \see \p merge - * \see \p includes - * \see \p set_difference - * \see \p set_union - * \see \p set_intersection - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_symmetric_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_symmetric_difference constructs a sorted range that is the set symmetric - * difference of the sorted ranges [first1, last1) and [first2, last2). - * The return value is the end of the output range. - * - * In the simplest case, \p set_symmetric_difference performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [first1, last1) but not [first2, last1), and a copy of - * every element that is contained in [first2, last2) but not [first1, last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements that are - * equivalent to each other and [first2, last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [first1, last1) if m > n, and - * the last n - m of these elements from [first2, last2) if m < n. - * - * This version of \p set_union compares elements using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference to compute - * the symmetric difference of two sets of integers sorted in descending order using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {7, 6, 4, 2, 2, 1, 0}; - * int A2[5] = {8, 5, 2, 1, 1}; - * - * int result[6]; - * - * int *result_end = thrust::set_symmetric_difference(thrust::host, A1, A1 + 6, A2, A2 + 5, result); - * // result = {8, 7, 6, 5, 4, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_symmetric_difference.html - * \see \p merge - * \see \p includes - * \see \p set_difference - * \see \p set_union - * \see \p set_intersection - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_symmetric_difference(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_symmetric_difference constructs a sorted range that is the set symmetric - * difference of the sorted ranges [first1, last1) and [first2, last2). - * The return value is the end of the output range. - * - * In the simplest case, \p set_symmetric_difference performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [first1, last1) but not [first2, last1), and a copy of - * every element that is contained in [first2, last2) but not [first1, last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements that are - * equivalent to each other and [first2, last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [first1, last1) if m > n, and - * the last n - m of these elements from [first2, last2) if m < n. - * - * This version of \p set_union compares elements using a function object \p comp. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference to compute - * the symmetric difference of two sets of integers sorted in descending order. - * - * \code - * #include - * ... - * int A1[6] = {7, 6, 4, 2, 2, 1, 0}; - * int A2[5] = {8, 5, 2, 1, 1}; - * - * int result[6]; - * - * int *result_end = thrust::set_symmetric_difference(A1, A1 + 6, A2, A2 + 5, result); - * // result = {8, 7, 6, 5, 4, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_symmetric_difference.html - * \see \p merge - * \see \p includes - * \see \p set_difference - * \see \p set_union - * \see \p set_intersection - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_symmetric_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_union constructs a sorted range that is the union of the sorted ranges - * [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_union performs the "union" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1), [first2, last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * This version of \p set_union compares elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_union to compute the union of - * two sets of integers sorted in ascending order using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * ... - * int A1[6] = {0, 2, 4, 6, 8, 10, 12}; - * int A2[5] = {1, 3, 5, 7, 9}; - * - * int result[11]; - * - * int *result_end = thrust::set_union(thrust::host, A1, A1 + 6, A2, A2 + 5, result); - * // result = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_union.html - * \see \p merge - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_union(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_union constructs a sorted range that is the union of the sorted ranges - * [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_union performs the "union" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1), [first2, last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * This version of \p set_union compares elements using \c operator<. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_union to compute the union of - * two sets of integers sorted in ascending order. - * - * \code - * #include - * ... - * int A1[6] = {0, 2, 4, 6, 8, 10, 12}; - * int A2[5] = {1, 3, 5, 7, 9}; - * - * int result[11]; - * - * int *result_end = thrust::set_union(A1, A1 + 6, A2, A2 + 5, result); - * // result = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_union.html - * \see \p merge - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_union(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -/*! \p set_union constructs a sorted range that is the union of the sorted ranges - * [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_union performs the "union" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1), [first2, last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * This version of \p set_union compares elements using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_union to compute the union of - * two sets of integers sorted in ascending order using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A1[6] = {12, 10, 8, 6, 4, 2, 0}; - * int A2[5] = {9, 7, 5, 3, 1}; - * - * int result[11]; - * - * int *result_end = thrust::set_union(thrust::host, A1, A1 + 6, A2, A2 + 5, result, thrust::greater()); - * // result = {12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_union.html - * \see \p merge - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_union(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_union constructs a sorted range that is the union of the sorted ranges - * [first1, last1) and [first2, last2). The return value is the - * end of the output range. - * - * In the simplest case, \p set_union performs the "union" operation from set - * theory: the output range contains a copy of every element that is contained in - * [first1, last1), [first2, last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [first1, last1) contains \c m elements - * that are equivalent to each other and if [first2, last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * This version of \p set_union compares elements using a function object \p comp. - * - * \param first1 The beginning of the first input range. - * \param last1 The end of the first input range. - * \param first2 The beginning of the second input range. - * \param last2 The end of the second input range. - * \param result The beginning of the output range. - * \param comp Comparison operator. - * \return The end of the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1's \c value_type is convertable to \p StrictWeakCompare's \c first_argument_type. - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2's \c value_type is convertable to \p StrictWeakCompare's \c second_argument_type. - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. - * \pre The resulting range shall not overlap with either input range. - * - * The following code snippet demonstrates how to use \p set_union to compute the union of - * two sets of integers sorted in ascending order. - * - * \code - * #include - * #include - * ... - * int A1[6] = {12, 10, 8, 6, 4, 2, 0}; - * int A2[5] = {9, 7, 5, 3, 1}; - * - * int result[11]; - * - * int *result_end = thrust::set_union(A1, A1 + 6, A2, A2 + 5, result, thrust::greater()); - * // result = {12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - * \endcode - * - * \see http://www.sgi.com/tech/stl/set_union.html - * \see \p merge - * \see \p includes - * \see \p set_union - * \see \p set_intersection - * \see \p set_symmetric_difference - * \see \p sort - * \see \p is_sorted - */ -template - OutputIterator set_union(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakCompare comp); - - -/*! \p set_difference_by_key performs a key-value difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_difference_by_key performs the "difference" operation from set - * theory: the keys output range contains a copy of every element that is contained in - * [keys_first1, keys_last1) and not contained in [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [keys_first1, keys_last1) range shall be copied to the output range. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_difference_by_key compares key elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_difference_by_key to compute the - * set difference of two sets of integers sorted in ascending order with their values using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {0, 1, 3, 4, 5, 6, 9}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {1, 3, 5, 7, 9}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[3]; - * int vals_result[3]; - * - * thrust::pair end = thrust::set_difference_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {0, 4, 6} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_difference_by_key performs a key-value difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_difference_by_key performs the "difference" operation from set - * theory: the keys output range contains a copy of every element that is contained in - * [keys_first1, keys_last1) and not contained in [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [keys_first1, keys_last1) range shall be copied to the output range. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_difference_by_key compares key elements using \c operator<. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_difference_by_key to compute the - * set difference of two sets of integers sorted in ascending order with their values. - * - * \code - * #include - * ... - * int A_keys[6] = {0, 1, 3, 4, 5, 6, 9}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {1, 3, 5, 7, 9}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[3]; - * int vals_result[3]; - * - * thrust::pair end = thrust::set_difference_by_key(A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {0, 4, 6} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_difference_by_key performs a key-value difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_difference_by_key performs the "difference" operation from set - * theory: the keys output range contains a copy of every element that is contained in - * [keys_first1, keys_last1) and not contained in [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [keys_first1, keys_last1) range shall be copied to the output range. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_difference_by_key compares key elements using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_difference_by_key to compute the - * set difference of two sets of integers sorted in descending order with their values using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A_keys[6] = {9, 6, 5, 4, 3, 1, 0}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {9, 7, 5, 3, 1}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[3]; - * int vals_result[3]; - * - * thrust::pair end = thrust::set_difference_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result, thrust::greater()); - * // keys_result is now {0, 4, 6} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_difference_by_key performs a key-value difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_difference_by_key performs the "difference" operation from set - * theory: the keys output range contains a copy of every element that is contained in - * [keys_first1, keys_last1) and not contained in [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, the last max(m-n,0) elements from - * [keys_first1, keys_last1) range shall be copied to the output range. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_difference_by_key compares key elements using a function object \p comp. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_difference_by_key to compute the - * set difference of two sets of integers sorted in descending order with their values. - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {9, 6, 5, 4, 3, 1, 0}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {9, 7, 5, 3, 1}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[3]; - * int vals_result[3]; - * - * thrust::pair end = thrust::set_difference_by_key(A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result, thrust::greater()); - * // keys_result is now {0, 4, 6} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_intersection_by_key performs a key-value intersection operation from set theory. - * \p set_intersection_by_key constructs a sorted range that is the intersection of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_intersection_by_key performs the "intersection" operation from set - * theory: the keys output range contains a copy of every element that is contained in both - * [keys_first1, keys_last1) [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if an element appears \c m times in [keys_first1, keys_last1) - * and \c n times in [keys_first2, keys_last2) (where \c m may be zero), then it - * appears min(m,n) times in the keys output range. - * \p set_intersection_by_key is stable, meaning both that elements are copied from the first - * input range rather than the second, and that the relative order of elements in the output range - * is the same as the first input range. - * - * Each time a key element is copied from [keys_first1, keys_last1) to the keys output range, - * the corresponding value element is copied from [values_first1, values_last1) to the values - * output range. - * - * This version of \p set_intersection_by_key compares objects using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \note Unlike the other key-value set operations, \p set_intersection_by_key is unique in that it has no - * \c values_first2 parameter because elements from the second input range are never copied to the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_intersection_by_key to compute the - * set intersection of two sets of integers sorted in ascending order with their values using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {1, 3, 5, 7, 9, 11}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13}; - * - * int keys_result[7]; - * int vals_result[7]; - * - * thrust::pair end = thrust::set_intersection_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, keys_result, vals_result); - * - * // keys_result is now {1, 3, 5} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_difference_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_intersection_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_intersection_by_key performs a key-value intersection operation from set theory. - * \p set_intersection_by_key constructs a sorted range that is the intersection of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_intersection_by_key performs the "intersection" operation from set - * theory: the keys output range contains a copy of every element that is contained in both - * [keys_first1, keys_last1) [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if an element appears \c m times in [keys_first1, keys_last1) - * and \c n times in [keys_first2, keys_last2) (where \c m may be zero), then it - * appears min(m,n) times in the keys output range. - * \p set_intersection_by_key is stable, meaning both that elements are copied from the first - * input range rather than the second, and that the relative order of elements in the output range - * is the same as the first input range. - * - * Each time a key element is copied from [keys_first1, keys_last1) to the keys output range, - * the corresponding value element is copied from [values_first1, values_last1) to the values - * output range. - * - * This version of \p set_intersection_by_key compares objects using \c operator<. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \note Unlike the other key-value set operations, \p set_intersection_by_key is unique in that it has no - * \c values_first2 parameter because elements from the second input range are never copied to the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_intersection_by_key to compute the - * set intersection of two sets of integers sorted in ascending order with their values. - * - * \code - * #include - * ... - * int A_keys[6] = {1, 3, 5, 7, 9, 11}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13}; - * - * int keys_result[7]; - * int vals_result[7]; - * - * thrust::pair end = thrust::set_intersection_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, keys_result, vals_result); - * - * // keys_result is now {1, 3, 5} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_difference_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_intersection_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_intersection_by_key performs a key-value intersection operation from set theory. - * \p set_intersection_by_key constructs a sorted range that is the intersection of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_intersection_by_key performs the "intersection" operation from set - * theory: the keys output range contains a copy of every element that is contained in both - * [keys_first1, keys_last1) [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if an element appears \c m times in [keys_first1, keys_last1) - * and \c n times in [keys_first2, keys_last2) (where \c m may be zero), then it - * appears min(m,n) times in the keys output range. - * \p set_intersection_by_key is stable, meaning both that elements are copied from the first - * input range rather than the second, and that the relative order of elements in the output range - * is the same as the first input range. - * - * Each time a key element is copied from [keys_first1, keys_last1) to the keys output range, - * the corresponding value element is copied from [values_first1, values_last1) to the values - * output range. - * - * This version of \p set_intersection_by_key compares objects using a function object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \note Unlike the other key-value set operations, \p set_intersection_by_key is unique in that it has no - * \c values_first2 parameter because elements from the second input range are never copied to the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_intersection_by_key to compute the - * set intersection of two sets of integers sorted in descending order with their values using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A_keys[6] = {11, 9, 7, 5, 3, 1}; - * int A_vals[6] = { 0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1}; - * - * int keys_result[7]; - * int vals_result[7]; - * - * thrust::pair end = thrust::set_intersection_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, keys_result, vals_result, thrust::greater()); - * - * // keys_result is now {5, 3, 1} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_difference_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_intersection_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_intersection_by_key performs a key-value intersection operation from set theory. - * \p set_intersection_by_key constructs a sorted range that is the intersection of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_intersection_by_key performs the "intersection" operation from set - * theory: the keys output range contains a copy of every element that is contained in both - * [keys_first1, keys_last1) [keys_first2, keys_last2). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if an element appears \c m times in [keys_first1, keys_last1) - * and \c n times in [keys_first2, keys_last2) (where \c m may be zero), then it - * appears min(m,n) times in the keys output range. - * \p set_intersection_by_key is stable, meaning both that elements are copied from the first - * input range rather than the second, and that the relative order of elements in the output range - * is the same as the first input range. - * - * Each time a key element is copied from [keys_first1, keys_last1) to the keys output range, - * the corresponding value element is copied from [values_first1, values_last1) to the values - * output range. - * - * This version of \p set_intersection_by_key compares objects using a function object \p comp. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \note Unlike the other key-value set operations, \p set_intersection_by_key is unique in that it has no - * \c values_first2 parameter because elements from the second input range are never copied to the output range. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_intersection_by_key to compute the - * set intersection of two sets of integers sorted in descending order with their values. - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {11, 9, 7, 5, 3, 1}; - * int A_vals[6] = { 0, 0, 0, 0, 0, 0}; - * - * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1}; - * - * int keys_result[7]; - * int vals_result[7]; - * - * thrust::pair end = thrust::set_intersection_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, keys_result, vals_result, thrust::greater()); - * - * // keys_result is now {5, 3, 1} - * // vals_result is now {0, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_difference_by_key - * \see \p set_symmetric_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_intersection_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_symmetric_difference_by_key performs a key-value symmetric difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the symmetric difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_symmetric_difference_by_key performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [keys_first1, keys_last1) but not [keys_first2, keys_last1), and a copy of - * every element that is contained in [keys_first2, keys_last2) but not [keys_first1, keys_last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements that are - * equivalent to each other and [keys_first2, keys_last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [keys_first1, keys_last1) if m > n, and - * the last n - m of these elements from [keys_first2, keys_last2) if m < n. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_symmetric_difference_by_key compares key elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in ascending order with their values using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {0, 1, 2, 2, 4, 6, 7}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {1, 1, 2, 5, 8}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[6]; - * int vals_result[6]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {0, 4, 5, 6, 7, 8} - * // vals_result is now {0, 0, 1, 0, 0, 1} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_symmetric_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_symmetric_difference_by_key performs a key-value symmetric difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the symmetric difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_symmetric_difference_by_key performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [keys_first1, keys_last1) but not [keys_first2, keys_last1), and a copy of - * every element that is contained in [keys_first2, keys_last2) but not [keys_first1, keys_last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements that are - * equivalent to each other and [keys_first2, keys_last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [keys_first1, keys_last1) if m > n, and - * the last n - m of these elements from [keys_first2, keys_last2) if m < n. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_symmetric_difference_by_key compares key elements using \c operator<. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in ascending order with their values. - * - * \code - * #include - * ... - * int A_keys[6] = {0, 1, 2, 2, 4, 6, 7}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {1, 1, 2, 5, 8}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[6]; - * int vals_result[6]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {0, 4, 5, 6, 7, 8} - * // vals_result is now {0, 0, 1, 0, 0, 1} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_symmetric_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_symmetric_difference_by_key performs a key-value symmetric difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the symmetric difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_symmetric_difference_by_key performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [keys_first1, keys_last1) but not [keys_first2, keys_last1), and a copy of - * every element that is contained in [keys_first2, keys_last2) but not [keys_first1, keys_last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements that are - * equivalent to each other and [keys_first2, keys_last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [keys_first1, keys_last1) if m > n, and - * the last n - m of these elements from [keys_first2, keys_last2) if m < n. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_symmetric_difference_by_key compares key elements using a function object \c comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in descending order with their values using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A_keys[6] = {7, 6, 4, 2, 2, 1, 0}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {8, 5, 2, 1, 1}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[6]; - * int vals_result[6]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {8, 7, 6, 5, 4, 0} - * // vals_result is now {1, 0, 0, 1, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_symmetric_difference_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_symmetric_difference_by_key performs a key-value symmetric difference operation from set theory. - * \p set_difference_by_key constructs a sorted range that is the symmetric difference of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_symmetric_difference_by_key performs a set theoretic calculation: - * it constructs the union of the two sets A - B and B - A, where A and B are the two - * input ranges. That is, the output range contains a copy of every element that is - * contained in [keys_first1, keys_last1) but not [keys_first2, keys_last1), and a copy of - * every element that is contained in [keys_first2, keys_last2) but not [keys_first1, keys_last1). - * The general case is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements that are - * equivalent to each other and [keys_first2, keys_last1) contains \c n elements that are - * equivalent to them, then |m - n| of those elements shall be copied to the output - * range: the last m - n elements from [keys_first1, keys_last1) if m > n, and - * the last n - m of these elements from [keys_first2, keys_last2) if m < n. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_symmetric_difference_by_key compares key elements using a function object \c comp. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in descending order with their values. - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {7, 6, 4, 2, 2, 1, 0}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {8, 5, 2, 1, 1}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[6]; - * int vals_result[6]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {8, 7, 6, 5, 4, 0} - * // vals_result is now {1, 0, 0, 1, 0, 0} - * \endcode - * - * \see \p set_union_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_symmetric_difference_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_union_by_key performs a key-value union operation from set theory. - * \p set_union_by_key constructs a sorted range that is the union of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_union_by_key performs the "union" operation from set theory: - * the output range contains a copy of every element that is contained in - * [keys_first1, keys_last1), [keys_first2, keys_last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_union_by_key compares key elements using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in ascending order with their values using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {0, 2, 4, 6, 8, 10, 12}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {1, 3, 5, 7, 9}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[11]; - * int vals_result[11]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12} - * // vals_result is now {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0} - * \endcode - * - * \see \p set_symmetric_difference_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_union_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_union_by_key performs a key-value union operation from set theory. - * \p set_union_by_key constructs a sorted range that is the union of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_union_by_key performs the "union" operation from set theory: - * the output range contains a copy of every element that is contained in - * [keys_first1, keys_last1), [keys_first2, keys_last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_union_by_key compares key elements using \c operator<. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to operator<. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in ascending order with their values. - * - * \code - * #include - * ... - * int A_keys[6] = {0, 2, 4, 6, 8, 10, 12}; - * int A_vals[6] = {0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {1, 3, 5, 7, 9}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[11]; - * int vals_result[11]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result); - * // keys_result is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12} - * // vals_result is now {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0} - * \endcode - * - * \see \p set_symmetric_difference_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_union_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p set_union_by_key performs a key-value union operation from set theory. - * \p set_union_by_key constructs a sorted range that is the union of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_union_by_key performs the "union" operation from set theory: - * the output range contains a copy of every element that is contained in - * [keys_first1, keys_last1), [keys_first2, keys_last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_union_by_key compares key elements using a function object \c comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in descending order with their values using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * int A_keys[6] = {12, 10, 8, 6, 4, 2, 0}; - * int A_vals[6] = { 0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {9, 7, 5, 3, 1}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[11]; - * int vals_result[11]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(thrust::host, A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result, thrust::greater()); - * // keys_result is now {12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - * // vals_result is now { 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0} - * \endcode - * - * \see \p set_symmetric_difference_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_union_by_key(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \p set_union_by_key performs a key-value union operation from set theory. - * \p set_union_by_key constructs a sorted range that is the union of the sorted - * ranges [keys_first1, keys_last1) and [keys_first2, keys_last2). Associated - * with each element from the input and output key ranges is a value element. The associated input - * value ranges need not be sorted. - * - * In the simplest case, \p set_union_by_key performs the "union" operation from set theory: - * the output range contains a copy of every element that is contained in - * [keys_first1, keys_last1), [keys_first2, keys_last1), or both. The general case - * is more complicated, because the input ranges may contain duplicate elements. - * The generalization is that if [keys_first1, keys_last1) contains \c m elements - * that are equivalent to each other and if [keys_first2, keys_last2) contains \c n - * elements that are equivalent to them, then all \c m elements from the first - * range shall be copied to the output range, in order, and then max(n - m, 0) - * elements from the second range shall be copied to the output, in order. - * - * Each time a key element is copied from [keys_first1, keys_last1) or - * [keys_first2, keys_last2) is copied to the keys output range, the - * corresponding value element is copied from the corresponding values input range (beginning at - * \p values_first1 or \p values_first2) to the values output range. - * - * This version of \p set_union_by_key compares key elements using a function object \c comp. - * - * \param keys_first1 The beginning of the first input range of keys. - * \param keys_last1 The end of the first input range of keys. - * \param keys_first2 The beginning of the second input range of keys. - * \param keys_last2 The end of the second input range of keys. - * \param values_first1 The beginning of the first input range of values. - * \param values_first2 The beginning of the first input range of values. - * \param keys_result The beginning of the output range of keys. - * \param values_result The beginning of the output range of values. - * \param comp Comparison operator. - * \return A \p pair \c p such that p.first is the end of the output range of keys, - * and such that p.second is the end of the output range of values. - * - * \tparam InputIterator1 is a model of Input Iterator, - * \p InputIterator1 and \p InputIterator2 have the same \c value_type, - * \p InputIterator1's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator1's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator2 is a model of Input Iterator, - * \p InputIterator2 and \p InputIterator1 have the same \c value_type, - * \p InputIterator2's \c value_type is a model of LessThan Comparable, - * the ordering on \p InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, - * and \p InputIterator2's \c value_type is convertable to a type in \p OutputIterator's set of \c value_types. - * \tparam InputIterator3 is a model of Input Iterator, - * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam InputIterator4 is a model of Input Iterator, - * and \p InputIterator4's \c value_type is convertible to a type in \p OutputIterator2's set of \c value_types. - * \tparam OutputIterator1 is a model of Output Iterator. - * \tparam OutputIterator2 is a model of Output Iterator. - * \tparam StrictWeakCompare is a model of Strict Weak Ordering. - * - * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with respect to \p comp. - * \pre The resulting ranges shall not overlap with any input range. - * - * The following code snippet demonstrates how to use \p set_symmetric_difference_by_key to compute the - * symmetric difference of two sets of integers sorted in descending order with their values. - * - * \code - * #include - * #include - * ... - * int A_keys[6] = {12, 10, 8, 6, 4, 2, 0}; - * int A_vals[6] = { 0, 0, 0, 0, 0, 0, 0}; - * - * int B_keys[5] = {9, 7, 5, 3, 1}; - * int B_vals[5] = {1, 1, 1, 1, 1}; - * - * int keys_result[11]; - * int vals_result[11]; - * - * thrust::pair end = thrust::set_symmetric_difference_by_key(A_keys, A_keys + 6, B_keys, B_keys + 5, A_vals, B_vals, keys_result, vals_result, thrust::greater()); - * // keys_result is now {12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - * // vals_result is now { 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0} - * \endcode - * - * \see \p set_symmetric_difference_by_key - * \see \p set_intersection_by_key - * \see \p set_difference_by_key - * \see \p sort_by_key - * \see \p is_sorted - */ -template - thrust::pair - set_union_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakCompare comp); - - -/*! \} // end set_operations - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/sort.h b/compat/thrust/sort.h deleted file mode 100644 index e8edfcd..0000000 --- a/compat/thrust/sort.h +++ /dev/null @@ -1,1349 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file sort.h - * \brief Functions for reorganizing ranges into sorted order - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup sorting - * \ingroup algorithms - * \{ - */ - - -/*! \p sort sorts the elements in [first, last) into - * ascending order, meaning that if \c i and \c j are any two valid - * iterators in [first, last) such that \c i precedes \c j, - * then \c *j is not less than \c *i. Note: \c sort is not guaranteed - * to be stable. That is, suppose that \c *i and \c *j are equivalent: - * neither one is less than the other. It is not guaranteed that the - * relative order of these two elements will be preserved by \p sort. - * - * This version of \p sort compares objects using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * - * The following code snippet demonstrates how to use \p sort to sort - * a sequence of integers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::sort(thrust::host, A, A + N); - * // A is now {1, 2, 4, 5, 7, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort - * \see \p sort_by_key - */ -template - void sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last); - - -/*! \p sort sorts the elements in [first, last) into - * ascending order, meaning that if \c i and \c j are any two valid - * iterators in [first, last) such that \c i precedes \c j, - * then \c *j is not less than \c *i. Note: \c sort is not guaranteed - * to be stable. That is, suppose that \c *i and \c *j are equivalent: - * neither one is less than the other. It is not guaranteed that the - * relative order of these two elements will be preserved by \p sort. - * - * This version of \p sort compares objects using \c operator<. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * - * The following code snippet demonstrates how to use \p sort to sort - * a sequence of integers. - * - * \code - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::sort(A, A + N); - * // A is now {1, 2, 4, 5, 7, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort - * \see \p sort_by_key - */ -template - void sort(RandomAccessIterator first, - RandomAccessIterator last); - - -/*! \p sort sorts the elements in [first, last) into - * ascending order, meaning that if \c i and \c j are any two valid - * iterators in [first, last) such that \c i precedes \c j, - * then \c *j is not less than \c *i. Note: \c sort is not guaranteed - * to be stable. That is, suppose that \c *i and \c *j are equivalent: - * neither one is less than the other. It is not guaranteed that the - * relative order of these two elements will be preserved by \p sort. - * - * This version of \p sort compares objects using a function object - * \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp Comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code demonstrates how to sort integers in descending order - * using the greater comparison operator using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::sort(thrust::host, A, A + N, thrust::greater()); - * // A is now {8, 7, 5, 4, 2, 1}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort - * \see \p sort_by_key - */ -template - void sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - - -/*! \p sort sorts the elements in [first, last) into - * ascending order, meaning that if \c i and \c j are any two valid - * iterators in [first, last) such that \c i precedes \c j, - * then \c *j is not less than \c *i. Note: \c sort is not guaranteed - * to be stable. That is, suppose that \c *i and \c *j are equivalent: - * neither one is less than the other. It is not guaranteed that the - * relative order of these two elements will be preserved by \p sort. - * - * This version of \p sort compares objects using a function object - * \p comp. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp Comparison operator. - * - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code demonstrates how to sort integers in descending order - * using the greater comparison operator. - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::sort(A, A + N, thrust::greater()); - * // A is now {8, 7, 5, 4, 2, 1}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort - * \see \p sort_by_key - */ -template - void sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - - -/*! \p stable_sort is much like \c sort: it sorts the elements in - * [first, last) into ascending order, meaning that if \c i - * and \c j are any two valid iterators in [first, last) such - * that \c i precedes \c j, then \c *j is not less than \c *i. - * - * As the name suggests, \p stable_sort is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [first, last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort is that \c x - * still precedes \c y. - * - * This version of \p stable_sort compares objects using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * - * The following code snippet demonstrates how to use \p sort to sort - * a sequence of integers using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::stable_sort(thrust::host, A, A + N); - * // A is now {1, 2, 4, 5, 7, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_sort.html - * \see \p sort - * \see \p stable_sort_by_key - */ -template - void stable_sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last); - - -/*! \p stable_sort is much like \c sort: it sorts the elements in - * [first, last) into ascending order, meaning that if \c i - * and \c j are any two valid iterators in [first, last) such - * that \c i precedes \c j, then \c *j is not less than \c *i. - * - * As the name suggests, \p stable_sort is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [first, last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort is that \c x - * still precedes \c y. - * - * This version of \p stable_sort compares objects using \c operator<. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * - * The following code snippet demonstrates how to use \p sort to sort - * a sequence of integers. - * - * \code - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::stable_sort(A, A + N); - * // A is now {1, 2, 4, 5, 7, 8} - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_sort.html - * \see \p sort - * \see \p stable_sort_by_key - */ -template - void stable_sort(RandomAccessIterator first, - RandomAccessIterator last); - - -/*! \p stable_sort is much like \c sort: it sorts the elements in - * [first, last) into ascending order, meaning that if \c i - * and \c j are any two valid iterators in [first, last) such - * that \c i precedes \c j, then \c *j is not less than \c *i. - * - * As the name suggests, \p stable_sort is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [first, last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort is that \c x - * still precedes \c y. - * - * This version of \p stable_sort compares objects using a function object - * \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp Comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code demonstrates how to sort integers in descending order - * using the greater comparison operator using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::sort(A, A + N, thrust::greater()); - * // A is now {8, 7, 5, 4, 2, 1}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_sort.html - * \see \p sort - * \see \p stable_sort_by_key - */ -template - void stable_sort(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - - -/*! \p stable_sort is much like \c sort: it sorts the elements in - * [first, last) into ascending order, meaning that if \c i - * and \c j are any two valid iterators in [first, last) such - * that \c i precedes \c j, then \c *j is not less than \c *i. - * - * As the name suggests, \p stable_sort is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [first, last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort is that \c x - * still precedes \c y. - * - * This version of \p stable_sort compares objects using a function object - * \p comp. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp Comparison operator. - * - * \tparam RandomAccessIterator is a model of Random Access Iterator, - * \p RandomAccessIterator is mutable, - * and \p RandomAccessIterator's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * The following code demonstrates how to sort integers in descending order - * using the greater comparison operator. - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int A[N] = {1, 4, 2, 8, 5, 7}; - * thrust::sort(A, A + N, thrust::greater()); - * // A is now {8, 7, 5, 4, 2, 1}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/stable_sort.html - * \see \p sort - * \see \p stable_sort_by_key - */ -template - void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - - -/////////////// -// Key Value // -/////////////// - - -/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the - * elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that - * \c *i and \c *j are equivalent: neither one is less than the other. It is not - * guaranteed that the relative order of these two keys or the relative - * order of their corresponding values will be preserved by \p sort_by_key. - * - * This version of \p sort_by_key compares key objects using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p sort_by_key to sort - * an array of character values using integers as sorting keys using the \p thrust::host execution policy - * for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::sort_by_key(thrust::host, keys, keys + N, values); - * // keys is now { 1, 2, 4, 5, 7, 8} - * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort_by_key - * \see \p sort - */ -template - void sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - - -/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the - * elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that - * \c *i and \c *j are equivalent: neither one is less than the other. It is not - * guaranteed that the relative order of these two keys or the relative - * order of their corresponding values will be preserved by \p sort_by_key. - * - * This version of \p sort_by_key compares key objects using \c operator<. - * - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p sort_by_key to sort - * an array of character values using integers as sorting keys. - * - * \code - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::sort_by_key(keys, keys + N, values); - * // keys is now { 1, 2, 4, 5, 7, 8} - * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort_by_key - * \see \p sort - */ -template - void sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - - -/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the - * elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that - * \c *i and \c *j are equivalent: neither one is less than the other. It is not - * guaranteed that the relative order of these two keys or the relative - * order of their corresponding values will be preserved by \p sort_by_key. - * - * This version of \p sort_by_key compares key objects using a function object - * \c comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * \param comp Comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p sort_by_key to sort - * an array of character values using integers as sorting keys using the \p thrust::host execution policy - * for parallelization.The keys are sorted in descending order using the greater comparison operator. - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::sort_by_key(thrust::host, keys, keys + N, values, thrust::greater()); - * // keys is now { 8, 7, 5, 4, 2, 1} - * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort_by_key - * \see \p sort - */ -template - void sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - - -/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the - * elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that - * \c *i and \c *j are equivalent: neither one is less than the other. It is not - * guaranteed that the relative order of these two keys or the relative - * order of their corresponding values will be preserved by \p sort_by_key. - * - * This version of \p sort_by_key compares key objects using a function object - * \c comp. - * - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * \param comp Comparison operator. - * - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p sort_by_key to sort - * an array of character values using integers as sorting keys. The keys - * are sorted in descending order using the greater comparison operator. - * - * \code - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::sort_by_key(keys, keys + N, values, thrust::greater()); - * // keys is now { 8, 7, 5, 4, 2, 1} - * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p stable_sort_by_key - * \see \p sort - */ -template - void sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - - -/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key - * sorts the elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * As the name suggests, \p stable_sort_by_key is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [keys_first, keys_last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort_by_key is that \c x - * still precedes \c y. - * - * This version of \p stable_sort_by_key compares key objects using \c operator<. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p stable_sort_by_key to sort - * an array of characters using integers as sorting keys using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::stable_sort_by_key(thrust::host, keys, keys + N, values); - * // keys is now { 1, 2, 4, 5, 7, 8} - * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p sort_by_key - * \see \p stable_sort - */ -template - void stable_sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - - -/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key - * sorts the elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * As the name suggests, \p stable_sort_by_key is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [keys_first, keys_last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort_by_key is that \c x - * still precedes \c y. - * - * This version of \p stable_sort_by_key compares key objects using \c operator<. - * - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, - * and the ordering relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the - * LessThan Comparable requirements. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p stable_sort_by_key to sort - * an array of characters using integers as sorting keys. - * - * \code - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::stable_sort_by_key(keys, keys + N, values); - * // keys is now { 1, 2, 4, 5, 7, 8} - * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} - * \endcode - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p sort_by_key - * \see \p stable_sort - */ -template - void stable_sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - - -/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key - * sorts the elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * As the name suggests, \p stable_sort_by_key is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [keys_first, keys_last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort_by_key is that \c x - * still precedes \c y. - * - * This version of \p stable_sort_by_key compares key objects using the function - * object \p comp. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * \param comp Comparison operator. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p sort_by_key to sort - * an array of character values using integers as sorting keys using the \p thrust::host execution policy for - * parallelization. The keys are sorted in descending order using the greater comparison operator. - * - * \code - * #include - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::stable_sort_by_key(thrust::host, keys, keys + N, values, thrust::greater()); - * // keys is now { 8, 7, 5, 4, 2, 1} - * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} - * \endcode - * - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p sort_by_key - * \see \p stable_sort - */ -template - void stable_sort_by_key(const thrust::detail::execution_policy_base &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - - -/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key - * sorts the elements in [keys_first, keys_last) and [values_first, - * values_first + (keys_last - keys_first)) into ascending key order, - * meaning that if \c i and \c j are any two valid iterators in [keys_first, - * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators - * in [values_first, values_first + (keys_last - keys_first)) - * corresponding to \c i and \c j respectively, then \c *j is not less than - * \c *i. - * - * As the name suggests, \p stable_sort_by_key is stable: it preserves the - * relative ordering of equivalent elements. That is, if \c x and \c y - * are elements in [keys_first, keys_last) such that \c x precedes \c y, - * and if the two elements are equivalent (neither x < y nor - * y < x) then a postcondition of \p stable_sort_by_key is that \c x - * still precedes \c y. - * - * This version of \p stable_sort_by_key compares key objects using the function - * object \p comp. - * - * \param keys_first The beginning of the key sequence. - * \param keys_last The end of the key sequence. - * \param values_first The beginning of the value sequence. - * \param comp Comparison operator. - * - * \tparam RandomAccessIterator1 is a model of Random Access Iterator, - * \p RandomAccessIterator1 is mutable, - * and \p RandomAccessIterator1's \c value_type is convertible to \p StrictWeakOrdering's - * \c first_argument_type and \c second_argument_type. - * \tparam RandomAccessIterator2 is a model of Random Access Iterator, - * and \p RandomAccessIterator2 is mutable. - * \tparam StrictWeakOrdering is a model of Strict Weak Ordering. - * - * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + (keys_last - keys_first)). - * - * The following code snippet demonstrates how to use \p sort_by_key to sort - * an array of character values using integers as sorting keys. The keys - * are sorted in descending order using the greater comparison operator. - * - * \code - * #include - * ... - * const int N = 6; - * int keys[N] = { 1, 4, 2, 8, 5, 7}; - * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; - * thrust::stable_sort_by_key(keys, keys + N, values, thrust::greater()); - * // keys is now { 8, 7, 5, 4, 2, 1} - * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} - * \endcode - * - * - * \see http://www.sgi.com/tech/stl/sort.html - * \see \p sort_by_key - * \see \p stable_sort - */ -template - void stable_sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - - -/*! \} // end sorting - */ - - -/*! \addtogroup reductions - * \{ - * \addtogroup predicates - * \{ - */ - - -/*! \p is_sorted returns \c true if the range [first, last) is - * sorted in ascending order, and \c false otherwise. - * - * Specifically, this version of \p is_sorted returns \c false if for - * some iterator \c i in the range [first, last - 1) the - * expression *(i + 1) < *i is \c true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return \c true, if the sequence is sorted; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator's \c value_type is a model of LessThan Comparable, - * and the ordering on objects of \p ForwardIterator's \c value_type is a strict weak ordering, as defined - * in the LessThan Comparable requirements. - * - * - * The following code demonstrates how to use \p is_sorted to test whether the - * contents of a \c device_vector are stored in ascending order using the \p thrust::device execution policy - * for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector v(6); - * v[0] = 1; - * v[1] = 4; - * v[2] = 2; - * v[3] = 8; - * v[4] = 5; - * v[5] = 7; - * - * bool result = thrust::is_sorted(thrust::device, v.begin(), v.end()); - * - * // result == false - * - * thrust::sort(v.begin(), v.end()); - * result = thrust::is_sorted(thrust::device, v.begin(), v.end()); - * - * // result == true - * \endcode - * - * \see http://www.sgi.com/tech/stl/is_sorted.html - * \see is_sorted_until - * \see \c sort - * \see \c stable_sort - * \see \c less - */ -template - bool is_sorted(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last); - - -/*! \p is_sorted returns \c true if the range [first, last) is - * sorted in ascending order, and \c false otherwise. - * - * Specifically, this version of \p is_sorted returns \c false if for - * some iterator \c i in the range [first, last - 1) the - * expression *(i + 1) < *i is \c true. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \return \c true, if the sequence is sorted; \c false, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator's \c value_type is a model of LessThan Comparable, - * and the ordering on objects of \p ForwardIterator's \c value_type is a strict weak ordering, as defined - * in the LessThan Comparable requirements. - * - * - * The following code demonstrates how to use \p is_sorted to test whether the - * contents of a \c device_vector are stored in ascending order. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector v(6); - * v[0] = 1; - * v[1] = 4; - * v[2] = 2; - * v[3] = 8; - * v[4] = 5; - * v[5] = 7; - * - * bool result = thrust::is_sorted(v.begin(), v.end()); - * - * // result == false - * - * thrust::sort(v.begin(), v.end()); - * result = thrust::is_sorted(v.begin(), v.end()); - * - * // result == true - * \endcode - * - * \see http://www.sgi.com/tech/stl/is_sorted.html - * \see is_sorted_until - * \see \c sort - * \see \c stable_sort - * \see \c less - */ -template - bool is_sorted(ForwardIterator first, - ForwardIterator last); - - -/*! \p is_sorted returns \c true if the range [first, last) is sorted in ascending - * order accoring to a user-defined comparison operation, and \c false otherwise. - * - * Specifically, this version of \p is_sorted returns \c false if for some iterator \c i in - * the range [first, last - 1) the expression comp(*(i + 1), *i) is \c true. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp Comparison operator. - * \return \c true, if the sequence is sorted according to comp; \c false, otherwise. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \c StrictWeakOrdering's \c first_argument_type - * and \c second_argument_type. - * \tparam Compare is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p is_sorted to test whether the - * contents of a \c device_vector are stored in descending order using the \p thrust::device execution - * policy for parallelization: - * - * \code - * #include - * #include - * #include - * #include - * ... - * thrust::device_vector v(6); - * v[0] = 1; - * v[1] = 4; - * v[2] = 2; - * v[3] = 8; - * v[4] = 5; - * v[5] = 7; - * - * thrust::greater comp; - * bool result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp); - * - * // result == false - * - * thrust::sort(v.begin(), v.end(), comp); - * result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp); - * - * // result == true - * \endcode - * - * \see http://www.sgi.com/tech/stl/is_sorted.html - * \see \c sort - * \see \c stable_sort - * \see \c less - */ -template - bool is_sorted(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp); - - -/*! \p is_sorted returns \c true if the range [first, last) is sorted in ascending - * order accoring to a user-defined comparison operation, and \c false otherwise. - * - * Specifically, this version of \p is_sorted returns \c false if for some iterator \c i in - * the range [first, last - 1) the expression comp(*(i + 1), *i) is \c true. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param comp Comparison operator. - * \return \c true, if the sequence is sorted according to comp; \c false, otherwise. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator's \c value_type is convertible to both \c StrictWeakOrdering's \c first_argument_type - * and \c second_argument_type. - * \tparam Compare is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p is_sorted to test whether the - * contents of a \c device_vector are stored in descending order. - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector v(6); - * v[0] = 1; - * v[1] = 4; - * v[2] = 2; - * v[3] = 8; - * v[4] = 5; - * v[5] = 7; - * - * thrust::greater comp; - * bool result = thrust::is_sorted(v.begin(), v.end(), comp); - * - * // result == false - * - * thrust::sort(v.begin(), v.end(), comp); - * result = thrust::is_sorted(v.begin(), v.end(), comp); - * - * // result == true - * \endcode - * - * \see http://www.sgi.com/tech/stl/is_sorted.html - * \see \c sort - * \see \c stable_sort - * \see \c less - */ -template - bool is_sorted(ForwardIterator first, - ForwardIterator last, - Compare comp); - - -/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for - * which the range [first,last) is sorted using \c operator<. If distance(first,last) < 2, - * \p is_sorted_until simply returns \p last. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \return The last iterator in the input range for which it is sorted. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator and - * \p ForwardIterator's \c value_type is a model of LessThan Comparable. - * - * The following code snippet demonstrates how to use \p is_sorted_until to find the first position - * in an array where the data becomes unsorted using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * - * ... - * - * int A[8] = {0, 1, 2, 3, 0, 1, 2, 3}; - * - * int * B = thrust::is_sorted_until(thrust::host, A, A + 8); - * - * // B - A is 4 - * // [A, B) is sorted - * \endcode - * - * \see \p is_sorted - * \see \p sort - * \see \p sort_by_key - * \see \p stable_sort - * \see \p stable_sort_by_key - */ -template - ForwardIterator is_sorted_until(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last); - - -/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for - * which the range [first,last) is sorted using \c operator<. If distance(first,last) < 2, - * \p is_sorted_until simply returns \p last. - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \return The last iterator in the input range for which it is sorted. - * - * \tparam ForwardIterator is a model of Forward Iterator and - * \p ForwardIterator's \c value_type is a model of LessThan Comparable. - * - * The following code snippet demonstrates how to use \p is_sorted_until to find the first position - * in an array where the data becomes unsorted: - * - * \code - * #include - * - * ... - * - * int A[8] = {0, 1, 2, 3, 0, 1, 2, 3}; - * - * int * B = thrust::is_sorted_until(A, A + 8); - * - * // B - A is 4 - * // [A, B) is sorted - * \endcode - * - * \see \p is_sorted - * \see \p sort - * \see \p sort_by_key - * \see \p stable_sort - * \see \p stable_sort_by_key - */ -template - ForwardIterator is_sorted_until(ForwardIterator first, - ForwardIterator last); - - -/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for - * which the range [first,last) is sorted using the function object \c comp. If distance(first,last) < 2, - * \p is_sorted_until simply returns \p last. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization: - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param comp The function object to use for comparison. - * \return The last iterator in the input range for which it is sorted. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator and - * \p ForwardIterator's \c value_type is convertible to \p Compare's \c argument_type. - * \tparam Compare is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p is_sorted_until to find the first position - * in an array where the data becomes unsorted in descending order using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * ... - * - * int A[8] = {3, 2, 1, 0, 3, 2, 1, 0}; - * - * thrust::greater comp; - * int * B = thrust::is_sorted_until(thrust::host, A, A + 8, comp); - * - * // B - A is 4 - * // [A, B) is sorted in descending order - * \endcode - * - * \see \p is_sorted - * \see \p sort - * \see \p sort_by_key - * \see \p stable_sort - * \see \p stable_sort_by_key - */ -template - ForwardIterator is_sorted_until(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp); - - -/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for - * which the range [first,last) is sorted using the function object \c comp. If distance(first,last) < 2, - * \p is_sorted_until simply returns \p last. - * - * \param first The beginning of the range of interest. - * \param last The end of the range of interest. - * \param comp The function object to use for comparison. - * \return The last iterator in the input range for which it is sorted. - * - * \tparam ForwardIterator is a model of Forward Iterator and - * \p ForwardIterator's \c value_type is convertible to \p Compare's \c argument_type. - * \tparam Compare is a model of Strict Weak Ordering. - * - * The following code snippet demonstrates how to use \p is_sorted_until to find the first position - * in an array where the data becomes unsorted in descending order: - * - * \code - * #include - * #include - * - * ... - * - * int A[8] = {3, 2, 1, 0, 3, 2, 1, 0}; - * - * thrust::greater comp; - * int * B = thrust::is_sorted_until(A, A + 8, comp); - * - * // B - A is 4 - * // [A, B) is sorted in descending order - * \endcode - * - * \see \p is_sorted - * \see \p sort - * \see \p sort_by_key - * \see \p stable_sort - * \see \p stable_sort_by_key - */ -template - ForwardIterator is_sorted_until(ForwardIterator first, - ForwardIterator last, - Compare comp); - - -/*! \} // end predicates - * \} // end reductions - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/swap.h b/compat/thrust/swap.h deleted file mode 100644 index 085e546..0000000 --- a/compat/thrust/swap.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file swap.h - * \brief Functions for swapping the value of elements - */ - -#pragma once - -#include -#include - -// empty Doxygen comment below so namespace thrust's documentation will be extracted - -/*! - */ -namespace thrust -{ - -/*! \addtogroup utility - * \{ - */ - -/*! \addtogroup swap - * \{ - */ - -/*! \p swap assigns the contents of \c a to \c b and the - * contents of \c b to \c a. This is used as a primitive operation - * by many other algorithms. - * - * \param a The first value of interest. After completion, - * the value of b will be returned here. - * \param b The second value of interest. After completion, - * the value of a will be returned here. - * - * \tparam Assignable is a model of Assignable. - * - * The following code snippet demonstrates how to use \p swap to - * swap the contents of two variables. - * - * \code - * #include - * ... - * int x = 1; - * int y = 2; - * thrust::swap(x,h); - * - * // x == 2, y == 1 - * \endcode - */ -template -__host__ __device__ -inline void swap(Assignable1 &a, Assignable2 &b); - -/*! \} // swap - */ - -/*! \} // utility - */ - - -/*! \addtogroup copying - * \{ - */ - - -/*! \p swap_ranges swaps each of the elements in the range [first1, last1) - * with the corresponding element in the range [first2, first2 + (last1 - first1)). - * That is, for each integer \c n such that 0 <= n < (last1 - first1), it swaps - * *(first1 + n) and *(first2 + n). The return value is - * first2 + (last1 - first1). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first sequence to swap. - * \param last1 One position past the last element of the first sequence to swap. - * \param first2 The beginning of the second sequence to swap. - * \return An iterator pointing to one position past the last element of the second - * sequence to swap. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator1 is a model of Forward Iterator, - * and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type. - * \tparam ForwardIterator2 is a model of Forward Iterator, - * and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type. - * - * \pre \p first1 may equal \p first2, but the range [first1, last1) shall not overlap the range [first2, first2 + (last1 - first1)) otherwise. - * - * The following code snippet demonstrates how to use \p swap_ranges to - * swap the contents of two \c thrust::device_vectors using the \p thrust::device execution - * policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * thrust::device_vector v1(2), v2(2); - * v1[0] = 1; - * v1[1] = 2; - * v2[0] = 3; - * v2[1] = 4; - * - * thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin()); - * - * // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2 - * \endcode - * - * \see http://www.sgi.com/tech/stl/swap_ranges.html - * \see \c swap - */ -template - ForwardIterator2 swap_ranges(const thrust::detail::execution_policy_base &exec, - ForwardIterator1 first1, - ForwardIterator1 last1, - ForwardIterator2 first2); - - -/*! \p swap_ranges swaps each of the elements in the range [first1, last1) - * with the corresponding element in the range [first2, first2 + (last1 - first1)). - * That is, for each integer \c n such that 0 <= n < (last1 - first1), it swaps - * *(first1 + n) and *(first2 + n). The return value is - * first2 + (last1 - first1). - * - * \param first1 The beginning of the first sequence to swap. - * \param last1 One position past the last element of the first sequence to swap. - * \param first2 The beginning of the second sequence to swap. - * \return An iterator pointing to one position past the last element of the second - * sequence to swap. - * - * \tparam ForwardIterator1 is a model of Forward Iterator, - * and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type. - * \tparam ForwardIterator2 is a model of Forward Iterator, - * and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type. - * - * \pre \p first1 may equal \p first2, but the range [first1, last1) shall not overlap the range [first2, first2 + (last1 - first1)) otherwise. - * - * The following code snippet demonstrates how to use \p swap_ranges to - * swap the contents of two \c thrust::device_vectors. - * - * \code - * #include - * #include - * ... - * thrust::device_vector v1(2), v2(2); - * v1[0] = 1; - * v1[1] = 2; - * v2[0] = 3; - * v2[1] = 4; - * - * thrust::swap_ranges(v1.begin(), v1.end(), v2.begin()); - * - * // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2 - * \endcode - * - * \see http://www.sgi.com/tech/stl/swap_ranges.html - * \see \c swap - */ -template - ForwardIterator2 swap_ranges(ForwardIterator1 first1, - ForwardIterator1 last1, - ForwardIterator2 first2); - - -/*! \} // copying - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/system/cpp/detail/adjacent_difference.h b/compat/thrust/system/cpp/detail/adjacent_difference.h deleted file mode 100644 index ea212ff..0000000 --- a/compat/thrust/system/cpp/detail/adjacent_difference.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file adjacent_difference.h - * \brief C++ implementation of adjacent_difference. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -OutputIterator adjacent_difference(execution_policy &, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::adjacent_difference(first, last, result, binary_op); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/assign_value.h b/compat/thrust/system/cpp/detail/assign_value.h deleted file mode 100644 index 847fc97..0000000 --- a/compat/thrust/system/cpp/detail/assign_value.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -__host__ __device__ - void assign_value(thrust::system::cpp::detail::execution_policy &, Pointer1 dst, Pointer2 src) -{ - *thrust::raw_pointer_cast(dst) = *thrust::raw_pointer_cast(src); -} // end assign_value() - -} // end detail -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/binary_search.h b/compat/thrust/system/cpp/detail/binary_search.h deleted file mode 100644 index 37af539..0000000 --- a/compat/thrust/system/cpp/detail/binary_search.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file binary_search.h - * \brief C++ implementation of binary search algorithms. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -ForwardIterator lower_bound(tag, - ForwardIterator first, - ForwardIterator last, - const T& val, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::lower_bound(first, last, val, comp); -} - - -template -ForwardIterator upper_bound(tag, - ForwardIterator first, - ForwardIterator last, - const T& val, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::upper_bound(first, last, val, comp); -} - -template -bool binary_search(tag, - ForwardIterator first, - ForwardIterator last, - const T& val, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::binary_search(first, last, val, comp); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/copy.h b/compat/thrust/system/cpp/detail/copy.h deleted file mode 100644 index 7299bbb..0000000 --- a/compat/thrust/system/cpp/detail/copy.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file copy.h - * \brief C++ implementations of copy functions. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - OutputIterator copy(tag, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - return thrust::system::detail::internal::scalar::copy(first, last, result); -} - -template - OutputIterator copy_n(tag, - InputIterator first, - Size n, - OutputIterator result) -{ - return thrust::system::detail::internal::scalar::copy_n(first, n, result); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/copy_if.h b/compat/thrust/system/cpp/detail/copy_if.h deleted file mode 100644 index 2faadfa..0000000 --- a/compat/thrust/system/cpp/detail/copy_if.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -template - OutputIterator copy_if(tag, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::copy_if(first, last, stencil, result, pred); -} - -} // end detail -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/count.h b/compat/thrust/system/cpp/detail/count.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/count.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/dispatch/sort.h b/compat/thrust/system/cpp/detail/dispatch/sort.h deleted file mode 100644 index 2a03cf6..0000000 --- a/compat/thrust/system/cpp/detail/dispatch/sort.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include -#include - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ -namespace dispatch -{ - -//////////////// -// Radix Sort // -//////////////// - -template -void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp, - thrust::detail::true_type) -{ - thrust::system::detail::internal::scalar::stable_radix_sort(first, last); - - // if comp is greater then reverse the keys - typedef typename thrust::iterator_traits::value_type KeyType; - const static bool reverse = thrust::detail::is_same >::value; - - if (reverse) - thrust::reverse(first, last); -} - -template -void stable_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp, - thrust::detail::true_type) -{ - // if comp is greater then reverse the keys and values - typedef typename thrust::iterator_traits::value_type KeyType; - const static bool reverse = thrust::detail::is_same >::value; - - // note, we also have to reverse the (unordered) input to preserve stability - if (reverse) - { - thrust::reverse(first1, last1); - thrust::reverse(first2, first2 + (last1 - first1)); - } - - thrust::system::detail::internal::scalar::stable_radix_sort_by_key(first1, last1, first2); - - if (reverse) - { - thrust::reverse(first1, last1); - thrust::reverse(first2, first2 + (last1 - first1)); - } -} - -//////////////// -// Merge Sort // -//////////////// - -template -void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp, - thrust::detail::false_type) -{ - thrust::system::detail::internal::scalar::stable_merge_sort(first, last, comp); -} - -template -void stable_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp, - thrust::detail::false_type) -{ - thrust::system::detail::internal::scalar::stable_merge_sort_by_key(first1, last1, first2, comp); -} - -} // end namespace dispatch -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/equal.h b/compat/thrust/system/cpp/detail/equal.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/equal.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/execution_policy.h b/compat/thrust/system/cpp/detail/execution_policy.h deleted file mode 100644 index 229ff5c..0000000 --- a/compat/thrust/system/cpp/detail/execution_policy.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -// put the canonical tag in the same ns as the backend's entry points -namespace cpp -{ -namespace detail -{ - -// this awkward sequence of definitions arise -// from the desire both for tag to derive -// from execution_policy and for execution_policy -// to convert to tag (when execution_policy is not -// an ancestor of tag) - -// forward declaration of tag -struct tag; - -// forward declaration of execution_policy -template struct execution_policy; - -// specialize execution_policy for tag -template<> - struct execution_policy - : thrust::execution_policy -{}; - -// tag's definition comes before the -// generic definition of execution_policy -struct tag : execution_policy {}; - -// allow conversion to tag when it is not a successor -template - struct execution_policy - : thrust::execution_policy -{ - // allow conversion to tag - inline operator tag () const - { - return tag(); - } -}; - -} // end detail - -// alias execution_policy and tag here -using thrust::system::cpp::detail::execution_policy; -using thrust::system::cpp::detail::tag; - -} // end cpp -} // end system - -// alias items at top-level -namespace cpp -{ - -using thrust::system::cpp::execution_policy; -using thrust::system::cpp::tag; - -} // end cpp -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/extrema.h b/compat/thrust/system/cpp/detail/extrema.h deleted file mode 100644 index 3eab6d4..0000000 --- a/compat/thrust/system/cpp/detail/extrema.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file extrema.h - * \brief C++ implementations of extrema functions. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -ForwardIterator min_element(execution_policy &, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - return thrust::system::detail::internal::scalar::min_element(first, last, comp); -} - - -template -ForwardIterator max_element(execution_policy &, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - return thrust::system::detail::internal::scalar::max_element(first, last, comp); -} - - -template -thrust::pair minmax_element(execution_policy &, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - return thrust::system::detail::internal::scalar::minmax_element(first, last, comp); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/fill.h b/compat/thrust/system/cpp/detail/fill.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/fill.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/find.h b/compat/thrust/system/cpp/detail/find.h deleted file mode 100644 index 9698524..0000000 --- a/compat/thrust/system/cpp/detail/find.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file find.h - * \brief C++ implementation of find_if. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -InputIterator find_if(tag, - InputIterator first, - InputIterator last, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::find_if(first, last, pred); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/for_each.h b/compat/thrust/system/cpp/detail/for_each.h deleted file mode 100644 index 8d4e1c7..0000000 --- a/compat/thrust/system/cpp/detail/for_each.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -template -InputIterator for_each(thrust::system::cpp::detail::execution_policy &, - InputIterator first, - InputIterator last, - UnaryFunction f) -{ - return thrust::system::detail::internal::scalar::for_each(first, last, f); -} - -template -InputIterator for_each_n(thrust::system::cpp::detail::execution_policy &, - InputIterator first, - Size n, - UnaryFunction f) -{ - return thrust::system::detail::internal::scalar::for_each_n(first, n, f); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/gather.h b/compat/thrust/system/cpp/detail/gather.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/gather.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/generate.h b/compat/thrust/system/cpp/detail/generate.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/generate.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/get_value.h b/compat/thrust/system/cpp/detail/get_value.h deleted file mode 100644 index 5ddb2c8..0000000 --- a/compat/thrust/system/cpp/detail/get_value.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -template -__host__ __device__ - typename thrust::iterator_value::type - get_value(thrust::system::cpp::detail::execution_policy &, Pointer ptr) -{ - return *thrust::raw_pointer_cast(ptr); -} // end get_value() - - -} // end detail -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/inner_product.h b/compat/thrust/system/cpp/detail/inner_product.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/inner_product.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/iter_swap.h b/compat/thrust/system/cpp/detail/iter_swap.h deleted file mode 100644 index 257276f..0000000 --- a/compat/thrust/system/cpp/detail/iter_swap.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -template -__host__ __device__ - void iter_swap(tag, Pointer1 a, Pointer2 b) -{ - using thrust::swap; - swap(*thrust::raw_pointer_cast(a), *thrust::raw_pointer_cast(b)); -} // end iter_swap() - - -} // end detail -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/logical.h b/compat/thrust/system/cpp/detail/logical.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/logical.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/malloc_and_free.h b/compat/thrust/system/cpp/detail/malloc_and_free.h deleted file mode 100644 index 4f8ae82..0000000 --- a/compat/thrust/system/cpp/detail/malloc_and_free.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include // for malloc & free -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -// note that malloc returns a raw pointer to avoid -// depending on the heavyweight thrust/system/cpp/memory.h header -template - void *malloc(execution_policy &, std::size_t n) -{ - return std::malloc(n); -} // end malloc() - - -template - void free(execution_policy &, Pointer ptr) -{ - std::free(thrust::raw_pointer_cast(ptr)); -} // end free() - - -} // end detail -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/memory.inl b/compat/thrust/system/cpp/detail/memory.inl deleted file mode 100644 index 7f9a48d..0000000 --- a/compat/thrust/system/cpp/detail/memory.inl +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ - -// XXX WAR an issue with MSVC 2005 (cl v14.00) incorrectly implementing -// pointer_raw_pointer for pointer by specializing it here -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400) -namespace detail -{ - -template - struct pointer_raw_pointer< thrust::cpp::pointer > -{ - typedef typename thrust::cpp::pointer::raw_pointer type; -}; // end pointer_raw_pointer - -} // end detail -#endif - -namespace system -{ -namespace cpp -{ - - -template - template - reference & - reference - ::operator=(const reference &other) -{ - return super_t::operator=(other); -} // end reference::operator=() - -template - reference & - reference - ::operator=(const value_type &x) -{ - return super_t::operator=(x); -} // end reference::operator=() - -template -__host__ __device__ -void swap(reference a, reference b) -{ - a.swap(b); -} // end swap() - -pointer malloc(std::size_t n) -{ - tag t; - return pointer(thrust::system::cpp::detail::malloc(t, n)); -} // end malloc() - -template -pointer malloc(std::size_t n) -{ - pointer raw_ptr = thrust::system::cpp::malloc(sizeof(T) * n); - return pointer(reinterpret_cast(raw_ptr.get())); -} // end malloc() - -void free(pointer ptr) -{ - tag t; - return thrust::system::cpp::detail::free(t, ptr); -} // end free() - -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/merge.h b/compat/thrust/system/cpp/detail/merge.h deleted file mode 100644 index 7f01c07..0000000 --- a/compat/thrust/system/cpp/detail/merge.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -OutputIterator merge(execution_policy &, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::merge(first1, last1, first2, last2, result, comp); -} - -template -thrust::pair - merge_by_key(execution_policy &, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::merge_by_key(keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, comp); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/mismatch.h b/compat/thrust/system/cpp/detail/mismatch.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/mismatch.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/par.h b/compat/thrust/system/cpp/detail/par.h deleted file mode 100644 index 953e527..0000000 --- a/compat/thrust/system/cpp/detail/par.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -struct par_t : thrust::system::cpp::detail::execution_policy -{ - par_t() : thrust::system::cpp::detail::execution_policy() {} - - template - thrust::detail::execute_with_allocator - operator()(Allocator &alloc) const - { - return thrust::detail::execute_with_allocator(alloc); - } -}; - - -} // end detail - - -static const detail::par_t par; - - -} // end cpp -} // end system - - -// alias par here -namespace cpp -{ - - -using thrust::system::cpp::par; - - -} // end cpp -} // end thrust - diff --git a/compat/thrust/system/cpp/detail/partition.h b/compat/thrust/system/cpp/detail/partition.h deleted file mode 100644 index 25a4f1c..0000000 --- a/compat/thrust/system/cpp/detail/partition.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file partition.h - * \brief cpp implementations of partition functions - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - ForwardIterator stable_partition(tag, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::stable_partition(first, last, pred); -} - -template - ForwardIterator stable_partition(tag, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::stable_partition(first, last, stencil, pred); -} - -template - thrust::pair - stable_partition_copy(tag, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::stable_partition_copy(first, last, out_true, out_false, pred); -} - -template - thrust::pair - stable_partition_copy(tag, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::stable_partition_copy(first, last, stencil, out_true, out_false, pred); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/reduce.h b/compat/thrust/system/cpp/detail/reduce.h deleted file mode 100644 index 5428206..0000000 --- a/compat/thrust/system/cpp/detail/reduce.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief C++ implementation of reduce algorithms. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - OutputType reduce(execution_policy &, - InputIterator begin, - InputIterator end, - OutputType init, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::reduce(begin, end, init, binary_op); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/reduce_by_key.h b/compat/thrust/system/cpp/detail/reduce_by_key.h deleted file mode 100644 index 22dc2d9..0000000 --- a/compat/thrust/system/cpp/detail/reduce_by_key.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - thrust::pair - reduce_by_key(execution_policy &, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::reduce_by_key(keys_first, keys_last, values_first, keys_output, values_output, binary_pred, binary_op); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/remove.h b/compat/thrust/system/cpp/detail/remove.h deleted file mode 100644 index cf2202b..0000000 --- a/compat/thrust/system/cpp/detail/remove.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - ForwardIterator remove_if(tag, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::remove_if(first, last, pred); -} - - -template - ForwardIterator remove_if(tag, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::remove_if(first, last, stencil, pred); -} - - -template - OutputIterator remove_copy_if(tag, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::remove_copy_if(first, last, result, pred); -} - - - -template - OutputIterator remove_copy_if(tag, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - return thrust::system::detail::internal::scalar::remove_copy_if(first, last, stencil, result, pred); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/replace.h b/compat/thrust/system/cpp/detail/replace.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/replace.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/reverse.h b/compat/thrust/system/cpp/detail/reverse.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/reverse.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/scan.h b/compat/thrust/system/cpp/detail/scan.h deleted file mode 100644 index d4bae1e..0000000 --- a/compat/thrust/system/cpp/detail/scan.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.h - * \brief C++ implementations of scan functions. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - OutputIterator inclusive_scan(execution_policy &, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::inclusive_scan(first, last, result, binary_op); -} - - -template - OutputIterator exclusive_scan(execution_policy &, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::exclusive_scan(first, last, result, init, binary_op); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/scan_by_key.h b/compat/thrust/system/cpp/detail/scan_by_key.h deleted file mode 100644 index 4165d84..0000000 --- a/compat/thrust/system/cpp/detail/scan_by_key.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - OutputIterator inclusive_scan_by_key(tag, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::inclusive_scan_by_key(first1, last1, first2, result, binary_pred, binary_op); -} - - -template - OutputIterator exclusive_scan_by_key(tag, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - return thrust::system::detail::internal::scalar::exclusive_scan_by_key(first1, last1, first2, result, init, binary_pred, binary_op); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/scatter.h b/compat/thrust/system/cpp/detail/scatter.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/scatter.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/sequence.h b/compat/thrust/system/cpp/detail/sequence.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/sequence.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/set_operations.h b/compat/thrust/system/cpp/detail/set_operations.h deleted file mode 100644 index 07ce712..0000000 --- a/compat/thrust/system/cpp/detail/set_operations.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - - -template - OutputIterator set_difference(execution_policy &, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::set_difference(first1, last1, first2, last2, result, comp); -} - - -template - OutputIterator set_intersection(execution_policy &, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::set_intersection(first1, last1, first2, last2, result, comp); -} - - -template - OutputIterator set_symmetric_difference(execution_policy &, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::set_symmetric_difference(first1, last1, first2, last2, result, comp); -} - - -template - OutputIterator set_union(execution_policy &, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - return thrust::system::detail::internal::scalar::set_union(first1, last1, first2, last2, result, comp); -} - - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/sort.h b/compat/thrust/system/cpp/detail/sort.h deleted file mode 100644 index 60244e2..0000000 --- a/compat/thrust/system/cpp/detail/sort.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - void stable_sort(execution_policy &, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - thrust::system::detail::internal::scalar::stable_sort(first, last, comp); -} - -template - void stable_sort_by_key(execution_policy &, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - thrust::system::detail::internal::scalar::stable_sort_by_key(keys_first, keys_last, values_first, comp); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/swap_ranges.h b/compat/thrust/system/cpp/detail/swap_ranges.h deleted file mode 100644 index a834a2c..0000000 --- a/compat/thrust/system/cpp/detail/swap_ranges.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// cpp has no special swap_ranges - diff --git a/compat/thrust/system/cpp/detail/tabulate.h b/compat/thrust/system/cpp/detail/tabulate.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/tabulate.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/temporary_buffer.h b/compat/thrust/system/cpp/detail/temporary_buffer.h deleted file mode 100644 index 628bd75..0000000 --- a/compat/thrust/system/cpp/detail/temporary_buffer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special temporary buffer functions - diff --git a/compat/thrust/system/cpp/detail/transform.h b/compat/thrust/system/cpp/detail/transform.h deleted file mode 100644 index 5909d4a..0000000 --- a/compat/thrust/system/cpp/detail/transform.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// cpp has no special transform - diff --git a/compat/thrust/system/cpp/detail/transform_reduce.h b/compat/thrust/system/cpp/detail/transform_reduce.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/transform_reduce.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/transform_scan.h b/compat/thrust/system/cpp/detail/transform_scan.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/transform_scan.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/uninitialized_copy.h b/compat/thrust/system/cpp/detail/uninitialized_copy.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/uninitialized_copy.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/uninitialized_fill.h b/compat/thrust/system/cpp/detail/uninitialized_fill.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cpp/detail/uninitialized_fill.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cpp/detail/unique.h b/compat/thrust/system/cpp/detail/unique.h deleted file mode 100644 index cf74049..0000000 --- a/compat/thrust/system/cpp/detail/unique.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - ForwardIterator unique(execution_policy &, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - return thrust::system::detail::internal::scalar::unique(first, last, binary_pred); -} - -template - OutputIterator unique_copy(execution_policy &, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - return thrust::system::detail::internal::scalar::unique_copy(first, last, output, binary_pred); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/unique_by_key.h b/compat/thrust/system/cpp/detail/unique_by_key.h deleted file mode 100644 index a9f13d6..0000000 --- a/compat/thrust/system/cpp/detail/unique_by_key.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template - thrust::pair - unique_by_key(execution_policy &, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - return thrust::system::detail::internal::scalar::unique_by_key(keys_first, keys_last, values_first, binary_pred); -} - - -template - thrust::pair - unique_by_key_copy(execution_policy &, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - return thrust::system::detail::internal::scalar::unique_by_key_copy(keys_first, keys_last, values_first, keys_output, values_output, binary_pred); -} - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cpp/detail/vector.inl b/compat/thrust/system/cpp/detail/vector.inl deleted file mode 100644 index 03bffcd..0000000 --- a/compat/thrust/system/cpp/detail/vector.inl +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ - -template - vector - ::vector() - : super_t() -{} - -template - vector - ::vector(size_type n) - : super_t(n) -{} - -template - vector - ::vector(size_type n, const value_type &value) - : super_t(n,value) -{} - -template - vector - ::vector(const vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(const thrust::detail::vector_base &x) - : super_t(x) -{} - -template - template - vector - ::vector(const std::vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(InputIterator first, InputIterator last) - : super_t(first,last) -{} - -template - template - vector & - vector - ::operator=(const std::vector &x) -{ - super_t::operator=(x); - return *this; -} - -template - template - vector & - vector - ::operator=(const thrust::detail::vector_base &x) -{ - super_t::operator=(x); - return *this; -} - -} // end cpp -} // end system -} // end thrust - diff --git a/compat/thrust/system/cpp/execution_policy.h b/compat/thrust/system/cpp/execution_policy.h deleted file mode 100644 index f192eb9..0000000 --- a/compat/thrust/system/cpp/execution_policy.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -/*! \file thrust/system/cpp/execution_policy.h - * \brief Execution policies for Thrust's standard C++ system. - */ - -#include - -// get the execution policies definitions first -#include - -// get the definition of par -#include - -// now get all the algorithm definitions - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// define these entities here for the purpose of Doxygenating them -// they are actually defined elsewhere -#if 0 -namespace thrust -{ -namespace system -{ -namespace cpp -{ - - -/*! \addtogroup execution_policies - * \{ - */ - - -/*! \p thrust::system::cpp::execution_policy is the base class for all Thrust parallel execution - * policies which are derived from Thrust's standard C++ backend system. - */ -template -struct execution_policy : thrust::execution_policy -{}; - - -/*! \p thrust::system::cpp::tag is a type representing Thrust's standard C++ backend system in C++'s type system. - * Iterators "tagged" with a type which is convertible to \p cpp::tag assert that they may be - * "dispatched" to algorithm implementations in the \p cpp system. - */ -struct tag : thrust::system::cpp::execution_policy { unspecified }; - - -/*! - * \p thrust::system::cpp::par is the parallel execution policy associated with Thrust's standard - * C++ backend system. - * - * Instead of relying on implicit algorithm dispatch through iterator system tags, users may - * directly target Thrust's C++ backend system by providing \p thrust::cpp::par as an algorithm - * parameter. - * - * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such - * as \p thrust::cpp::vector. - * - * The type of \p thrust::cpp::par is implementation-defined. - * - * The following code snippet demonstrates how to use \p thrust::cpp::par to explicitly dispatch an - * invocation of \p thrust::for_each to the standard C++ backend system: - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * printf("%d\n"); - * } - * }; - * ... - * int vec[3]; - * vec[0] = 0; vec[1] = 1; vec[2] = 2; - * - * thrust::for_each(thrust::cpp::par, vec.begin(), vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - */ -static const unspecified par; - - -/*! \} - */ - - -} // end cpp -} // end system -} // end thrust -#endif - - diff --git a/compat/thrust/system/cpp/memory.h b/compat/thrust/system/cpp/memory.h deleted file mode 100644 index f3a58b8..0000000 --- a/compat/thrust/system/cpp/memory.h +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/cpp/memory.h - * \brief Managing memory associated with Thrust's standard C++ system. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ - -template class pointer; - -} // end cpp -} // end system -} // end thrust - - -/*! \cond - */ - -// specialize std::iterator_traits to avoid problems with the name of -// pointer's constructor shadowing its nested pointer type -// do this before pointer is defined so the specialization is correctly -// used inside the definition -namespace std -{ - -template - struct iterator_traits > -{ - private: - typedef thrust::system::cpp::pointer ptr; - - public: - typedef typename ptr::iterator_category iterator_category; - typedef typename ptr::value_type value_type; - typedef typename ptr::difference_type difference_type; - typedef ptr pointer; - typedef typename ptr::reference reference; -}; // end iterator_traits - -} // end std - -/*! \endcond - */ - - -namespace thrust -{ -namespace system -{ - -/*! \addtogroup system_backends Systems - * \ingroup system - * \{ - */ - -/*! \namespace thrust::system::cpp - * \brief \p thrust::system::cpp is the namespace containing functionality for allocating, manipulating, - * and deallocating memory available to Thrust's standard C++ backend system. - * The identifiers are provided in a separate namespace underneath thrust::system - * for import convenience but are also aliased in the top-level thrust::cpp - * namespace for easy access. - * - */ -namespace cpp -{ - -// forward declaration of reference for pointer -template class reference; - -/*! \cond - */ - -// XXX nvcc + msvc have trouble instantiating reference below -// this is a workaround -namespace detail -{ - -template - struct reference_msvc_workaround -{ - typedef thrust::system::cpp::reference type; -}; // end reference_msvc_workaround - -} // end detail - -/*! \endcond - */ - - -/*! \p pointer stores a pointer to an object allocated in memory available to the cpp system. - * This type provides type safety when dispatching standard algorithms on ranges resident - * in cpp memory. - * - * \p pointer has pointer semantics: it may be dereferenced and manipulated with pointer arithmetic. - * - * \p pointer can be created with the function \p cpp::malloc, or by explicitly calling its constructor - * with a raw pointer. - * - * The raw pointer encapsulated by a \p pointer may be obtained by eiter its get member function - * or the \p raw_pointer_cast function. - * - * \note \p pointer is not a "smart" pointer; it is the programmer's responsibility to deallocate memory - * pointed to by \p pointer. - * - * \tparam T specifies the type of the pointee. - * - * \see cpp::malloc - * \see cpp::free - * \see raw_pointer_cast - */ -template - class pointer - : public thrust::pointer< - T, - thrust::system::cpp::tag, - thrust::system::cpp::reference, - thrust::system::cpp::pointer - > -{ - /*! \cond - */ - - private: - typedef thrust::pointer< - T, - thrust::system::cpp::tag, - //thrust::system::cpp::reference, - typename detail::reference_msvc_workaround::type, - thrust::system::cpp::pointer - > super_t; - - /*! \endcond - */ - - public: - // note that cpp::pointer's member functions need __host__ __device__ - // to interoperate with nvcc + iterators' dereference member function - - /*! \p pointer's no-argument constructor initializes its encapsulated pointer to \c 0. - */ - __host__ __device__ - pointer() : super_t() {} - - /*! This constructor allows construction of a pointer from a T*. - * - * \param ptr A raw pointer to copy from, presumed to point to a location in memory - * accessible by the \p cpp system. - * \tparam OtherT \p OtherT shall be convertible to \p T. - */ - template - __host__ __device__ - explicit pointer(OtherT *ptr) : super_t(ptr) {} - - /*! This constructor allows construction from another pointer-like object with related type. - * - * \param other The \p OtherPointer to copy. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::cpp::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type * = 0) : super_t(other) {} - - /*! Assignment operator allows assigning from another pointer-like object with related type. - * - * \param other The other pointer-like object to assign from. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::cpp::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - pointer & - >::type - operator=(const OtherPointer &other) - { - return super_t::operator=(other); - } -}; // end pointer - - -/*! \p reference is a wrapped reference to an object stored in memory available to the \p cpp system. - * \p reference is the type of the result of dereferencing a \p cpp::pointer. - * - * \tparam T Specifies the type of the referenced object. - */ -template - class reference - : public thrust::reference< - T, - thrust::system::cpp::pointer, - thrust::system::cpp::reference - > -{ - /*! \cond - */ - - private: - typedef thrust::reference< - T, - thrust::system::cpp::pointer, - thrust::system::cpp::reference - > super_t; - - /*! \endcond - */ - - public: - /*! \cond - */ - - typedef typename super_t::value_type value_type; - typedef typename super_t::pointer pointer; - - /*! \endcond - */ - - /*! This constructor initializes this \p reference to refer to an object - * pointed to by the given \p pointer. After this \p reference is constructed, - * it shall refer to the object pointed to by \p ptr. - * - * \param ptr A \p pointer to copy from. - */ - __host__ __device__ - explicit reference(const pointer &ptr) - : super_t(ptr) - {} - - /*! This constructor accepts a const reference to another \p reference of related type. - * After this \p reference is constructed, it shall refer to the same object as \p other. - * - * \param other A \p reference to copy from. - * \tparam OtherT The element type of the other \p reference. - * - * \note This constructor is templated primarily to allow initialization of reference - * from reference. - */ - template - __host__ __device__ - reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type * = 0) - : super_t(other) - {} - - /*! Copy assignment operator copy assigns from another \p reference of related type. - * - * \param other The other \p reference to assign from. - * \return *this - * \tparam OtherT The element type of the other \p reference. - */ - template - reference &operator=(const reference &other); - - /*! Assignment operator assigns from a \p value_type. - * - * \param x The \p value_type to assign from. - * \return *this - */ - reference &operator=(const value_type &x); -}; // end reference - -/*! Exchanges the values of two objects referred to by \p reference. - * \p x The first \p reference of interest. - * \p y The second \p reference ot interest. - */ -template -__host__ __device__ -void swap(reference x, reference y); - -/*! Allocates an area of memory available to Thrust's cpp system. - * \param n Number of bytes to allocate. - * \return A cpp::pointer pointing to the beginning of the newly - * allocated memory. A null cpp::pointer is returned if - * an error occurs. - * \note The cpp::pointer returned by this function must be - * deallocated with \p cpp::free. - * \see cpp::free - * \see std::malloc - */ -inline pointer malloc(std::size_t n); - -/*! Allocates a typed area of memory available to Thrust's cpp system. - * \param n Number of elements to allocate. - * \return A cpp::pointer pointing to the beginning of the newly - * allocated elements. A null cpp::pointer is returned if - * an error occurs. - * \note The cpp::pointer returned by this function must be - * deallocated with \p cpp::free. - * \see cpp::free - * \see std::malloc - */ -template -inline pointer malloc(std::size_t n); - -/*! Deallocates an area of memory previously allocated by cpp::malloc. - * \param ptr A cpp::pointer pointing to the beginning of an area - * of memory previously allocated with cpp::malloc. - * \see cpp::malloc - * \see std::free - */ -inline void free(pointer ptr); - -// XXX upon c++11 -// template using allocator = thrust::detail::malloc_allocator >; - -/*! \p cpp::allocator is the default allocator used by the \p cpp system's containers such as - * cpp::vector if no user-specified allocator is provided. \p cpp::allocator allocates - * (deallocates) storage with \p cpp::malloc (\p cpp::free). - */ -template - struct allocator - : thrust::detail::malloc_allocator< - T, - tag, - pointer - > -{ - /*! The \p rebind metafunction provides the type of an \p allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p allocator. - */ - typedef allocator other; - }; - - /*! No-argument constructor has no effect. - */ - __host__ __device__ - inline allocator() {} - - /*! Copy constructor has no effect. - */ - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Constructor from other \p allocator has no effect. - */ - template - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Destructor has no effect. - */ - __host__ __device__ - inline ~allocator() {} -}; // end allocator - -} // end cpp - -/*! \} - */ - -} // end system - -/*! \namespace thrust::cpp - * \brief \p thrust::cpp is a top-level alias for thrust::system::cpp. - */ -namespace cpp -{ - -using thrust::system::cpp::pointer; -using thrust::system::cpp::reference; -using thrust::system::cpp::malloc; -using thrust::system::cpp::free; -using thrust::system::cpp::allocator; - -} // end cpp - -} // end thrust - -#include - diff --git a/compat/thrust/system/cpp/vector.h b/compat/thrust/system/cpp/vector.h deleted file mode 100644 index 4282df9..0000000 --- a/compat/thrust/system/cpp/vector.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/cpp/vector.h - * \brief A dynamically-sizable array of elements which reside in memory available to - * Thrust's standard C++ system. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -// forward declaration of host_vector -template class host_vector; - -namespace system -{ -namespace cpp -{ - -// XXX upon c++11 -// template > using vector = thrust::detail::vector_base; - -/*! \p cpp::vector is a container that supports random access to elements, - * constant time removal of elements at the end, and linear time insertion - * and removal of elements at the beginning or in the middle. The number of - * elements in a \p cpp::vector may vary dynamically; memory management is - * automatic. The elements contained in a \p cpp::vector reside in memory - * available to the \p cpp system. - * - * \tparam T The element type of the \p cpp::vector. - * \tparam Allocator The allocator type of the \p cpp::vector. Defaults to \p cpp::allocator. - * - * \see http://www.sgi.com/tech/stl/Vector.html - * \see host_vector For the documentation of the complete interface which is - * shared by \p cpp::vector - * \see device_vector - */ -template > - class vector - : public thrust::detail::vector_base -{ - /*! \cond - */ - private: - typedef thrust::detail::vector_base super_t; - /*! \endcond - */ - - public: - - /*! \cond - */ - typedef typename super_t::size_type size_type; - typedef typename super_t::value_type value_type; - - /*! \endcond - */ - - /*! This constructor creates an empty \p cpp::vector. - */ - vector(); - - /*! This constructor creates a \p cpp::vector with \p n default-constructed elements. - * \param n The size of the \p cpp::vector to create. - */ - explicit vector(size_type n); - - /*! This constructor creates a \p cpp::vector with \p n copies of \p value. - * \param n The size of the \p cpp::vector to create. - * \param value An element to copy. - */ - explicit vector(size_type n, const value_type &value); - - /*! Copy constructor copies from another \p cpp::vector. - * \param x The other \p cpp::vector to copy. - */ - vector(const vector &x); - - /*! This constructor copies from another Thrust vector-like object. - * \param x The other object to copy from. - */ - template - vector(const thrust::detail::vector_base &x); - - /*! This constructor copies from a \c std::vector. - * \param x The \c std::vector to copy from. - */ - template - vector(const std::vector &x); - - /*! This constructor creates a \p cpp::vector by copying from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - vector(InputIterator first, InputIterator last); - - // XXX vector_base should take a Derived type so we don't have to define these superfluous assigns - - /*! Assignment operator assigns from a \c std::vector. - * \param x The \c std::vector to assign from. - * \return *this - */ - template - vector &operator=(const std::vector &x); - - /*! Assignment operator assigns from another Thrust vector-like object. - * \param x The other object to assign from. - * \return *this - */ - template - vector &operator=(const thrust::detail::vector_base &x); -}; // end vector - -} // end cpp -} // end system - -// alias system::cpp names at top-level -namespace cpp -{ - -using thrust::system::cpp::vector; - -} // end cpp - -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/adjacent_difference.h b/compat/thrust/system/cuda/detail/adjacent_difference.h deleted file mode 100644 index ec51794..0000000 --- a/compat/thrust/system/cuda/detail/adjacent_difference.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file adjacent_difference.h - * \brief CUDA implementation of adjacent_difference. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template -OutputIterator adjacent_difference(execution_policy &exec, - InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/adjacent_difference.inl b/compat/thrust/system/cuda/detail/adjacent_difference.inl deleted file mode 100644 index 9e4756a..0000000 --- a/compat/thrust/system/cuda/detail/adjacent_difference.inl +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -struct last_index_in_each_interval : public thrust::unary_function -{ - typedef typename Decomposition::index_type index_type; - - Decomposition decomp; - - last_index_in_each_interval(Decomposition decomp) : decomp(decomp) {} - - __host__ __device__ - index_type operator()(index_type interval) - { - return decomp[interval].end() - 1; - } -}; - -template -struct adjacent_difference_closure -{ - InputIterator1 input; - InputIterator2 input_copy; - OutputIterator output; - BinaryFunction binary_op; - Decomposition decomp; - Context context; - - typedef Context context_type; - - adjacent_difference_closure(InputIterator1 input, - InputIterator2 input_copy, - OutputIterator output, - BinaryFunction binary_op, - Decomposition decomp, - Context context = Context()) - : input(input), input_copy(input_copy), output(output), binary_op(binary_op), decomp(decomp), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename thrust::iterator_value::type InputType; - typedef typename Decomposition::index_type index_type; - - // this block processes results in [range.begin(), range.end()) - thrust::system::detail::internal::index_range range = decomp[context.block_index()]; - - input_copy += context.block_index() - 1; - - // prime the temp values for all threads so we don't need to launch a default constructor - InputType next_left = (context.block_index() == 0) ? *input : *input_copy; - - index_type base = range.begin(); - index_type i = range.begin() + context.thread_index(); - - if (i < range.end()) - { - if (context.thread_index() > 0) - { - InputIterator1 temp = input + (i - 1); - next_left = *temp; - } - } - - input += i; - output += i; - - while (base < range.end()) - { - InputType curr_left = next_left; - - if (i + context.block_dimension() < range.end()) - { - InputIterator1 temp = input + (context.block_dimension() - 1); - next_left = *temp; - } - - context.barrier(); - - if (i < range.end()) - { - if (i == 0) - *output = *input; - else - { - InputType x = *input; - *output = binary_op(x, curr_left); - } - } - - i += context.block_dimension(); - base += context.block_dimension(); - input += context.block_dimension(); - output += context.block_dimension(); - } - } -}; - -} // end namespace detail - - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - -template -OutputIterator adjacent_difference(execution_policy &exec, - InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_value::type InputType; - typedef typename thrust::iterator_difference::type IndexType; - typedef thrust::system::detail::internal::uniform_decomposition Decomposition; - - IndexType n = last - first; - - if (n == 0) - return result; - - Decomposition decomp = default_decomposition(last - first); - - // allocate temporary storage - thrust::detail::temporary_array temp(exec, decomp.size() - 1); - - // gather last value in each interval - detail::last_index_in_each_interval unary_op(decomp); - thrust::gather(exec, - thrust::make_transform_iterator(thrust::counting_iterator(0), unary_op), - thrust::make_transform_iterator(thrust::counting_iterator(0), unary_op) + (decomp.size() - 1), - first, - temp.begin()); - - - typedef typename thrust::detail::temporary_array::iterator InputIterator2; - typedef detail::blocked_thread_array Context; - typedef detail::adjacent_difference_closure Closure; - - Closure closure(first, temp.begin(), result, binary_op, decomp); - - detail::launch_closure(closure, decomp.size()); - - return result + n; -} - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/assign_value.h b/compat/thrust/system/cuda/detail/assign_value.h deleted file mode 100644 index c90cf65..0000000 --- a/compat/thrust/system/cuda/detail/assign_value.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -// XXX WAR an issue with msvc 2005 (cl v14.00) which creates multiply-defined -// symbols resulting from assign_value -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400) - -namespace -{ - -template -inline __host__ __device__ - void assign_value_msvc2005_war(thrust::cuda::execution_policy &exec, Pointer1 dst, Pointer2 src) -{ - // XXX war nvbugs/881631 - struct war_nvbugs_881631 - { - __host__ inline static void host_path(thrust::cuda::execution_policy &exec, Pointer1 dst, Pointer2 src) - { - thrust::copy(exec, src, src + 1, dst); - } - - __device__ inline static void device_path(thrust::cuda::execution_policy &, Pointer1 dst, Pointer2 src) - { - *thrust::raw_pointer_cast(dst) = *thrust::raw_pointer_cast(src); - } - }; - -#ifndef __CUDA_ARCH__ - war_nvbugs_881631::host_path(exec,dst,src); -#else - war_nvbugs_881631::device_path(exec,dst,src); -#endif // __CUDA_ARCH__ -} // end assign_value_msvc2005_war() - -} // end anon namespace - -template -inline __host__ __device__ - void assign_value(thrust::cuda::execution_policy &exec, Pointer1 dst, Pointer2 src) -{ - return assign_value_msvc2005_war(exec,dst,src); -} // end assign_value() - -#else - -template -inline __host__ __device__ - void assign_value(thrust::cuda::execution_policy &exec, Pointer1 dst, Pointer2 src) -{ - // XXX war nvbugs/881631 - struct war_nvbugs_881631 - { - __host__ inline static void host_path(thrust::cuda::execution_policy &exec, Pointer1 dst, Pointer2 src) - { - thrust::copy(exec, src, src + 1, dst); - } - - __device__ inline static void device_path(thrust::cuda::execution_policy &, Pointer1 dst, Pointer2 src) - { - *thrust::raw_pointer_cast(dst) = *thrust::raw_pointer_cast(src); - } - }; - -#ifndef __CUDA_ARCH__ - war_nvbugs_881631::host_path(exec,dst,src); -#else - war_nvbugs_881631::device_path(exec,dst,src); -#endif // __CUDA_ARCH__ -} // end assign_value() - -#endif // msvc 2005 WAR - - -// XXX WAR an issue with msvc 2005 (cl v14.00) which creates multiply-defined -// symbols resulting from assign_value -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400) - -namespace -{ - - -template -inline __host__ __device__ - void assign_value_msvc2005_war(cross_system &systems, Pointer1 dst, Pointer2 src) -{ - // XXX war nvbugs/881631 - struct war_nvbugs_881631 - { - __host__ inline static void host_path(cross_system &systems, Pointer1 dst, Pointer2 src) - { - // rotate the systems so that they are ordered the same as (src, dst) - // for the call to thrust::copy - cross_system rotated_systems = systems.rotate(); - thrust::copy(rotated_systems, src, src + 1, dst); - } - - __device__ inline static void device_path(cross_system &systems, Pointer1 dst, Pointer2 src) - { - // XXX forward the true cuda::execution_policy inside systems here - // instead of materializing a tag - thrust::cuda::tag cuda_tag; - thrust::system::cuda::detail::assign_value(cuda_tag, dst, src); - } - }; - -#if __CUDA_ARCH__ - war_nvbugs_881631::device_path(systems,dst,src); -#else - war_nvbugs_881631::host_path(systems,dst,src); -#endif -} // end assign_value_msvc2005_war - - -} // end anon namespace - - -template -inline __host__ __device__ - void assign_value(cross_system &systems, Pointer1 dst, Pointer2 src) -{ - return assign_value_msvc2005_war(systems,dst,src); -} // end assign_value() - - -#else - - -template -inline __host__ __device__ - void assign_value(cross_system &systems, Pointer1 dst, Pointer2 src) -{ - // XXX war nvbugs/881631 - struct war_nvbugs_881631 - { - __host__ inline static void host_path(cross_system &systems, Pointer1 dst, Pointer2 src) - { - // rotate the systems so that they are ordered the same as (src, dst) - // for the call to thrust::copy - cross_system rotated_systems = systems.rotate(); - thrust::copy(rotated_systems, src, src + 1, dst); - } - - __device__ inline static void device_path(cross_system &systems, Pointer1 dst, Pointer2 src) - { - // XXX forward the true cuda::execution_policy inside systems here - // instead of materializing a tag - thrust::cuda::tag cuda_tag; - thrust::system::cuda::detail::assign_value(cuda_tag, dst, src); - } - }; - -#if __CUDA_ARCH__ - war_nvbugs_881631::device_path(systems,dst,src); -#else - war_nvbugs_881631::host_path(systems,dst,src); -#endif -} // end assign_value() - - -#endif // msvc 2005 WAR - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/binary_search.h b/compat/thrust/system/cuda/detail/binary_search.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/binary_search.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/block/copy.h b/compat/thrust/system/cuda/detail/block/copy.h deleted file mode 100644 index 9cc786b..0000000 --- a/compat/thrust/system/cuda/detail/block/copy.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file copy.h - * \brief CUDA implementation of device-to-device copy, - * based on Gregory Diamos' memcpy code. - */ - -#pragma once - -#include - -#include - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - -namespace trivial_copy_detail -{ - - -template - inline __device__ thrust::pair quotient_and_remainder(Size n, Size d) -{ - Size quotient = n / d; - Size remainder = n - d * quotient; - return thrust::make_pair(quotient,remainder); -} // end quotient_and_remainder() - - -// assumes the addresses dst & src are aligned to T boundaries -template -__device__ __thrust_forceinline__ -void aligned_copy(Context context, T *dst, const T *src, unsigned int num_elements) -{ - for(unsigned int i = context.thread_index(); - i < num_elements; - i += context.block_dimension()) - { - dst[i] = src[i]; - } -} // end aligned_copy() - - -} // end namespace trivial_copy_detail - - -template -__device__ __thrust_forceinline__ -void trivial_copy(Context context, void* destination_, const void* source_, size_t num_bytes) -{ - // reinterpret at bytes - char* destination = reinterpret_cast(destination_); - const char* source = reinterpret_cast(source_); - - // TODO replace this with uint64 -#if THRUST_DEVICE_COMPILER != THRUST_DEVICE_COMPILER_NVCC - typedef long long int2; - typedef long long uint2; -#endif // THRUST_DEVICE_COMPILER_NVCC - - // check alignment - // XXX can we do this in three steps? - // 1. copy until alignment is met - // 2. go hog wild - // 3. get the remainder - if(reinterpret_cast(destination) % sizeof(uint2) != 0 || reinterpret_cast(source) % sizeof(uint2) != 0) - { - for(unsigned int i = context.thread_index(); i < num_bytes; i += context.block_dimension()) - { - destination[i] = source[i]; - } - } - else - { - // it's aligned; do a wide copy - - // this pair stores the number of int2s in the aligned portion of the arrays - // and the number of bytes in the remainder - const thrust::pair num_wide_elements_and_remainder_bytes = trivial_copy_detail::quotient_and_remainder(num_bytes, sizeof(int2)); - - // copy int2 elements - trivial_copy_detail::aligned_copy(context, - reinterpret_cast(destination), - reinterpret_cast(source), - num_wide_elements_and_remainder_bytes.first); - - // XXX we could copy int elements here - - // copy remainder byte by byte - - // to find the beginning of the remainder arrays, we need to point at the beginning, and then skip the number of bytes in the aligned portion - // this is sizeof(int2) times the number of int2s comprising the aligned portion - const char *remainder_first = reinterpret_cast(source + sizeof(int2) * num_wide_elements_and_remainder_bytes.first); - char *remainder_result = reinterpret_cast(destination + sizeof(int2) * num_wide_elements_and_remainder_bytes.first); - - trivial_copy_detail::aligned_copy(context, remainder_result, remainder_first, num_wide_elements_and_remainder_bytes.second); - } -} // end trivial_copy() - - -namespace detail -{ -namespace dispatch -{ - -template - __thrust_forceinline__ __device__ - RandomAccessIterator2 copy(Context context, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - RandomAccessIterator2 result, - thrust::detail::true_type is_trivial_copy) -{ - typedef typename thrust::iterator_value::type T; - - const T *src = &thrust::raw_reference_cast(*first); - T *dst = &thrust::raw_reference_cast(*result); - - size_t n = (last - first); - thrust::system::cuda::detail::block::trivial_copy(context, dst, src, n * sizeof(T)); - return result + n; -} // end copy() - -template - __thrust_forceinline__ __device__ - RandomAccessIterator2 copy(Context context, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - RandomAccessIterator2 result, - thrust::detail::false_type is_trivial_copy) -{ - RandomAccessIterator2 end_of_output = result + (last - first); - - // advance iterators - first += context.thread_index(); - result += context.thread_index(); - - for(; - first < last; - first += context.block_dimension(), - result += context.block_dimension()) - { - *result = *first; - } // end for - - return end_of_output; -} // end copy() - -} // end namespace dispatch -} // end namespace detail - -template - __thrust_forceinline__ __device__ - RandomAccessIterator2 copy(Context context, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - RandomAccessIterator2 result) -{ - return detail::dispatch::copy(context, first, last, result, -#if __CUDA_ARCH__ < 200 - // does not work reliably on pre-Fermi due to "Warning: ... assuming global memory space" issues - thrust::detail::false_type() -#else - typename thrust::detail::dispatch::is_trivial_copy::type() -#endif - ); -} // end copy() - - -template -inline __device__ -RandomAccessIterator2 copy_n(Context &ctx, RandomAccessIterator1 first, Size n, RandomAccessIterator2 result) -{ - for(Size i = ctx.thread_index(); i < n; i += ctx.block_dimension()) - { - result[i] = first[i]; - } - - ctx.barrier(); - - return result + n; -} - - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/block/exclusive_scan.h b/compat/thrust/system/cuda/detail/block/exclusive_scan.h deleted file mode 100644 index 580a757..0000000 --- a/compat/thrust/system/cuda/detail/block/exclusive_scan.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - - -template -inline __device__ -typename thrust::iterator_value::type - inplace_exclusive_scan(Context &ctx, RandomAccessIterator first, T init, BinaryFunction op) -{ - // perform an inclusive scan, then shift right - block::inplace_inclusive_scan(ctx, first, op); - - typename thrust::iterator_value::type carry = first[ctx.block_dimension() - 1]; - - ctx.barrier(); - - typename thrust::iterator_value::type left = (ctx.thread_index() == 0) ? init : first[ctx.thread_index() - 1]; - - ctx.barrier(); - - first[ctx.thread_index()] = left; - - ctx.barrier(); - - return carry; -} - - -template -inline __device__ - typename thrust::iterator_value::type - inplace_exclusive_scan(Context &ctx, Iterator first, T init) -{ - return block::inplace_exclusive_scan(ctx, first, init, thrust::plus::type>()); -} - - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/block/inclusive_scan.h b/compat/thrust/system/cuda/detail/block/inclusive_scan.h deleted file mode 100644 index 012f7cd..0000000 --- a/compat/thrust/system/cuda/detail/block/inclusive_scan.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - -template -__device__ __thrust_forceinline__ -void inclusive_scan(Context context, - InputIterator first, - BinaryFunction binary_op) -{ - // TODO generalize to arbitrary n - // TODO support dynamic block_size - const unsigned int block_size = Context::ThreadsPerBlock::value; - - typename thrust::iterator_value::type val = first[context.thread_index()]; - - if(block_size > 1) { if (context.thread_index() >= 1) { val = binary_op(first[context.thread_index() - 1], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 2) { if (context.thread_index() >= 2) { val = binary_op(first[context.thread_index() - 2], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 4) { if (context.thread_index() >= 4) { val = binary_op(first[context.thread_index() - 4], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 8) { if (context.thread_index() >= 8) { val = binary_op(first[context.thread_index() - 8], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 16) { if (context.thread_index() >= 16) { val = binary_op(first[context.thread_index() - 16], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 32) { if (context.thread_index() >= 32) { val = binary_op(first[context.thread_index() - 32], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 64) { if (context.thread_index() >= 64) { val = binary_op(first[context.thread_index() - 64], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 128) { if (context.thread_index() >= 128) { val = binary_op(first[context.thread_index() - 128], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 256) { if (context.thread_index() >= 256) { val = binary_op(first[context.thread_index() - 256], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 512) { if (context.thread_index() >= 512) { val = binary_op(first[context.thread_index() - 512], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } - if(block_size > 1024) { if (context.thread_index() >= 1024) { val = binary_op(first[context.thread_index() - 1024], val); } context.barrier(); first[context.thread_index()] = val; context.barrier(); } -} // end inclusive_scan() - - -template -__device__ __thrust_forceinline__ -void inclusive_scan_n(Context context, - InputIterator first, - Size n, - BinaryFunction binary_op) -{ - // TODO support n > context.block_dimension() - typename thrust::iterator_value::type val = first[context.thread_index()]; - - for (unsigned int i = 1; i < n; i <<= 1) - { - if (context.thread_index() < n && context.thread_index() >= i) - val = binary_op(first[context.thread_index() - i], val); - - context.barrier(); - - first[context.thread_index()] = val; - - context.barrier(); - } -} // end inclusive_scan() - - -template -__device__ __thrust_forceinline__ -void inclusive_scan_by_flag(Context context, - InputIterator1 first1, - InputIterator2 first2, - BinaryFunction binary_op) -{ - // TODO generalize to arbitrary n - // TODO support dynamic block_size - const unsigned int block_size = Context::ThreadsPerBlock::value; - - typename thrust::iterator_value::type flg = first1[context.thread_index()]; - typename thrust::iterator_value::type val = first2[context.thread_index()]; - - if(block_size > 1) { if (context.thread_index() >= 1) { if (!flg) { flg |= first1[context.thread_index() - 1]; val = binary_op(first2[context.thread_index() - 1], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 2) { if (context.thread_index() >= 2) { if (!flg) { flg |= first1[context.thread_index() - 2]; val = binary_op(first2[context.thread_index() - 2], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 4) { if (context.thread_index() >= 4) { if (!flg) { flg |= first1[context.thread_index() - 4]; val = binary_op(first2[context.thread_index() - 4], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 8) { if (context.thread_index() >= 8) { if (!flg) { flg |= first1[context.thread_index() - 8]; val = binary_op(first2[context.thread_index() - 8], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 16) { if (context.thread_index() >= 16) { if (!flg) { flg |= first1[context.thread_index() - 16]; val = binary_op(first2[context.thread_index() - 16], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 32) { if (context.thread_index() >= 32) { if (!flg) { flg |= first1[context.thread_index() - 32]; val = binary_op(first2[context.thread_index() - 32], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 64) { if (context.thread_index() >= 64) { if (!flg) { flg |= first1[context.thread_index() - 64]; val = binary_op(first2[context.thread_index() - 64], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 128) { if (context.thread_index() >= 128) { if (!flg) { flg |= first1[context.thread_index() - 128]; val = binary_op(first2[context.thread_index() - 128], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 256) { if (context.thread_index() >= 256) { if (!flg) { flg |= first1[context.thread_index() - 256]; val = binary_op(first2[context.thread_index() - 256], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 512) { if (context.thread_index() >= 512) { if (!flg) { flg |= first1[context.thread_index() - 512]; val = binary_op(first2[context.thread_index() - 512], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } - if(block_size > 1024) { if (context.thread_index() >= 1024) { if (!flg) { flg |= first1[context.thread_index() - 1024]; val = binary_op(first2[context.thread_index() - 1024], val); } } context.barrier(); first1[context.thread_index()] = flg; first2[context.thread_index()] = val; context.barrier(); } -} // end inclusive_scan_by_flag() - - -template -__device__ __thrust_forceinline__ -void inclusive_scan_by_flag_n(Context context, - InputIterator1 first1, - InputIterator2 first2, - Size n, - BinaryFunction binary_op) -{ - // TODO support n > context.block_dimension() - typename thrust::iterator_value::type flg = first1[context.thread_index()]; - typename thrust::iterator_value::type val = first2[context.thread_index()]; - - for (unsigned int i = 1; i < n; i <<= 1) - { - if (context.thread_index() < n && context.thread_index() >= i) - { - if (!flg) - { - flg |= first1[context.thread_index() - i]; - val = binary_op(first2[context.thread_index() - i], val); - } - } - - context.barrier(); - - first1[context.thread_index()] = flg; - first2[context.thread_index()] = val; - - context.barrier(); - } -} // end inclusive_scan_by_flag() - - -template -__device__ __thrust_forceinline__ -void inplace_inclusive_scan(Context &ctx, RandomAccessIterator first, BinaryFunction op) -{ - typename thrust::iterator_value::type x = first[ctx.thread_index()]; - - for(unsigned int offset = 1; offset < ctx.block_dimension(); offset *= 2) - { - if(ctx.thread_index() >= offset) - { - x = op(first[ctx.thread_index() - offset], x); - } - - ctx.barrier(); - - first[ctx.thread_index()] = x; - - ctx.barrier(); - } -} - - -template -__device__ __thrust_forceinline__ -void inplace_inclusive_scan(Context &ctx, RandomAccessIterator first) -{ - block::inplace_inclusive_scan(ctx, first, thrust::plus::type>()); -} - - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/block/merge.h b/compat/thrust/system/cuda/detail/block/merge.h deleted file mode 100644 index 9af0b7b..0000000 --- a/compat/thrust/system/cuda/detail/block/merge.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - -template -__device__ __thrust_forceinline__ - RandomAccessIterator3 merge(Context context, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - StrictWeakOrdering comp); - -// XXX assumes that context.block_dimension() <= n1 and -// context.block_dimension() <= n2 -// This algorithm is analogous to inplace_merge -// but instead of working on the ranges -// [first, middle) and [middle, last) -// it works on the ranges -// [first, first + n1) and [first + n1, first + n1 + n2) -template -__device__ __thrust_forceinline__ - void inplace_merge_by_key_n(Context context, - RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - Size1 n1, - Size2 n2, - StrictWeakOrdering comp); - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/block/merge.inl b/compat/thrust/system/cuda/detail/block/merge.inl deleted file mode 100644 index 5eae2b5..0000000 --- a/compat/thrust/system/cuda/detail/block/merge.inl +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - -template -__device__ __thrust_forceinline__ - RandomAccessIterator3 merge(Context context, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_difference::type difference1; - typedef typename thrust::iterator_difference::type difference2; - - difference1 n1 = last1 - first1; - difference2 n2 = last2 - first2; - - // find the rank of each element in the other array - difference2 rank2 = 0; - if(context.thread_index() < n1) - { - RandomAccessIterator1 x = first1; - x += context.thread_index(); - - // lower_bound ensures that x sorts before any equivalent element of input2 - // this ensures stability - rank2 = thrust::system::detail::generic::scalar::lower_bound(first2, last2, raw_reference_cast(*x), comp) - first2; - } // end if - - difference1 rank1 = 0; - if(context.thread_index() < n2) - { - RandomAccessIterator2 x = first2 + context.thread_index(); - - // upper_bound ensures that x sorts before any equivalent element of input1 - // this ensures stability - rank1 = thrust::system::detail::generic::scalar::upper_bound(first1, last1, raw_reference_cast(*x), comp) - first1; - } // end if - - if(context.thread_index() < n1) - { - // scatter each element from input1 - RandomAccessIterator1 src = first1 + context.thread_index(); - RandomAccessIterator3 dst = result + context.thread_index() + rank2; - - *dst = *src; - } - - if(context.thread_index() < n2) - { - // scatter each element from input2 - RandomAccessIterator2 src = first2 + context.thread_index(); - RandomAccessIterator3 dst = result + context.thread_index() + rank1; - - *dst = *src; - } - - return result + n1 + n2; -} // end merge - - -template -__device__ __thrust_forceinline__ - void inplace_merge_by_key_n(Context context, - RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - Size1 n1, - Size2 n2, - StrictWeakOrdering comp) -{ - RandomAccessIterator1 input1 = keys_first; - RandomAccessIterator1 input2 = keys_first + n1; - - RandomAccessIterator2 input1val = values_first; - RandomAccessIterator2 input2val = values_first + n1; - - typedef typename thrust::iterator_value::type KeyType; - typedef typename thrust::iterator_value::type ValueType; - - // XXX use uninitialized here - KeyType inp1 = input1[context.thread_index()]; ValueType inp1val = input1val[context.thread_index()]; - KeyType inp2 = input2[context.thread_index()]; ValueType inp2val = input2val[context.thread_index()]; - - // to merge input1 and input2, use binary search to find the rank of inp1 & inp2 in arrays input2 & input1, respectively - // as before, the "end" variables point to one element after the last element of the arrays - - // start by looking through input2 for inp1's rank - unsigned int start_1 = 0; - - // don't do the search if our value is beyond the end of input1 - if(context.thread_index() < n1) - { - start_1 = thrust::system::detail::generic::scalar::lower_bound_n(input2, n2, inp1, comp) - input2; - } // end if - - // now look through input1 for inp2's rank - unsigned int start_2 = 0; - - // don't do the search if our value is beyond the end of input2 - if(context.thread_index() < n2) - { - // upper_bound ensures that equivalent elements in the first range sort before the second - start_2 = thrust::system::detail::generic::scalar::upper_bound_n(input1, n1, inp2, comp) - input1; - } // end if - - context.barrier(); - - // Write back into the right position to the input arrays; can be done in place since we read in - // the input arrays into registers before. - if(context.thread_index() < n1) - { - input1[start_1 + context.thread_index()] = inp1; - input1val[start_1 + context.thread_index()] = inp1val; - } // end if - - if(context.thread_index() < n2) - { - input1[start_2 + context.thread_index()] = inp2; - input1val[start_2 + context.thread_index()] = inp2val; - } // end if -} // end inplace_merge_by_key_n() - - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/block/merging_sort.h b/compat/thrust/system/cuda/detail/block/merging_sort.h deleted file mode 100644 index 8f8f999..0000000 --- a/compat/thrust/system/cuda/detail/block/merging_sort.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file merging_sort.h - * \brief Block version of merge sort - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - - -template -__device__ void conditional_swap(RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - const unsigned int i, - const unsigned int end, - bool pred, - Compare comp) -{ - typedef typename thrust::iterator_traits::value_type KeyType; - typedef typename thrust::iterator_traits::value_type ValueType; - - if(pred && i+1 -__device__ void transposition_sort(Context context, - RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - const unsigned int i, - const unsigned int end, - const unsigned int size, - Compare comp) -{ - const bool is_odd = i&0x1; - - for(unsigned int round=size/2; round>0; --round) - { - // ODDS - conditional_swap(keys_first, values_first, i, end, is_odd, comp); - context.barrier(); - - // EVENS - conditional_swap(keys_first, values_first, i, end, !is_odd, comp); - context.barrier(); - } -} - -template -__device__ void merge(Context context, - RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - const unsigned int i, - const unsigned int n, - unsigned int begin, - unsigned int end, - unsigned int h, - StrictWeakOrdering cmp) -{ - // INVARIANT: Every element i resides within a sequence [begin,end) - // of length h which is already sorted - while( h::value_type KeyType; - typedef typename thrust::iterator_traits::value_type ValueType; - - KeyType key; - ValueType value; - - unsigned int rank = i - begin; - - // prevent out-of-bounds access - if(i < new_end) - { - key = keys_first[i]; - - if(begin==new_begin) // in the left side of merging pair - { - RandomAccessIterator1 result = thrust::system::detail::generic::scalar::lower_bound_n(keys_first+end, new_end-end, key, cmp); - rank += (result - (keys_first+end)); - } - else // in the right side of merging pair - { - RandomAccessIterator1 result = thrust::system::detail::generic::scalar::upper_bound_n(keys_first+new_begin, begin-new_begin, key, cmp); - rank += (result - (keys_first+new_begin)); - } - - value = values_first[i]; - } - - context.barrier(); - - if(i < new_end) - { - keys_first[new_begin+rank] = key; - values_first[new_begin+rank] = value; - } - - context.barrier(); - - begin = new_begin; - end = new_end; - } -} - - -/*! Block-wise implementation of merge sort. - * It provides the same external interface as odd_even_sort. - */ -template -__device__ void merging_sort(Context context, - RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - const unsigned int n, - StrictWeakOrdering comp) -{ - // Phase 1: Sort subsequences of length 32 using odd-even - // transposition sort. The code below assumes that h is a - // power of 2. Empirically, 32 delivers best results, - // which is not surprising since that's the warp width. - unsigned int i = context.thread_index(); - unsigned int h = 32; - unsigned int begin=i&(~(h-1)), end=min(n,begin+h); - - transposition_sort(context, keys_first, values_first, i, end, h, comp); - - // Phase 2: Apply merge tree to produce final sorted results - merge(context, keys_first, values_first, i, n, begin, end, h, comp); -} // end merging_sort() - - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/block/odd_even_sort.h b/compat/thrust/system/cuda/detail/block/odd_even_sort.h deleted file mode 100644 index 0fa0ea0..0000000 --- a/compat/thrust/system/cuda/detail/block/odd_even_sort.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file odd_even_sort.h - * \brief Block versions of Batcher's Odd-Even Merge Sort - */ - -#pragma once - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - - -/*! Block-wise implementation of Batcher's Odd-Even Merge Sort - * This implementation is based on Nadathur Satish's. - */ -template - __device__ void odd_even_sort(KeyType *keys, - ValueType *data, - const unsigned int n, - StrictWeakOrdering comp) -{ - for(unsigned int p = blockDim.x>>1; p > 0; p >>= 1) - { - unsigned int q = blockDim.x>>1, r = 0, d = p; - - while(q >= p) - { - unsigned int j = threadIdx.x + d; - - // if j lies beyond the end of the array, we consider it "sorted" wrt i - // regardless of whether i lies beyond the end of the array - if(threadIdx.x < (blockDim.x-d) && (threadIdx.x & p) == r && j < n) - { - KeyType xikey = keys[threadIdx.x]; - KeyType xjkey = keys[j]; - - ValueType xivalue = data[threadIdx.x]; - ValueType xjvalue = data[j]; - - // does xj sort before xi? - if(comp(xjkey, xikey)) - { - keys[threadIdx.x] = xjkey; - keys[j] = xikey; - - data[threadIdx.x] = xjvalue; - data[j] = xivalue; - } // end if - } // end if - - d = q - p; - q >>= 1; - r = p; - - __syncthreads(); - } // end while - } // end for p -} // end odd_even_sort() - -template - __device__ void stable_odd_even_sort(KeyType *keys, - ValueType *data, - const unsigned int n, - StrictWeakOrdering comp) -{ - for(unsigned int i = 0; - i < blockDim.x>>1; - ++i) - { - bool thread_is_odd = threadIdx.x & 0x1; - - // do odds first - if(thread_is_odd && threadIdx.x + 1 < n) - { - KeyType xikey = keys[threadIdx.x]; - KeyType xjkey = keys[threadIdx.x + 1]; - - ValueType xivalue = data[threadIdx.x]; - ValueType xjvalue = data[threadIdx.x + 1]; - - // does xj sort before xi? - if(comp(xjkey, xikey)) - { - keys[threadIdx.x] = xjkey; - keys[threadIdx.x + 1] = xikey; - - data[threadIdx.x] = xjvalue; - data[threadIdx.x + 1] = xivalue; - } // end if - } // end if - - __syncthreads(); - - // do evens second - if(!thread_is_odd && threadIdx.x + 1 < n) - { - KeyType xikey = keys[threadIdx.x]; - KeyType xjkey = keys[threadIdx.x + 1]; - - ValueType xivalue = data[threadIdx.x]; - ValueType xjvalue = data[threadIdx.x + 1]; - - // does xj sort before xi? - if(comp(xjkey, xikey)) - { - keys[threadIdx.x] = xjkey; - keys[threadIdx.x + 1] = xikey; - - data[threadIdx.x] = xjvalue; - data[threadIdx.x + 1] = xivalue; - } // end if - } // end if - - __syncthreads(); - } // end for i -} // end stable_odd_even_sort() - - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/block/reduce.h b/compat/thrust/system/cuda/detail/block/reduce.h deleted file mode 100644 index e0a1901..0000000 --- a/compat/thrust/system/cuda/detail/block/reduce.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace block -{ - -/* Reduces [data, data + n) using binary_op and stores the result in data[0] - * - * Upon return the elements in [data + 1, data + n) have unspecified values. - */ -template -__device__ __thrust_forceinline__ -void reduce_n(Context context, ValueIterator data, unsigned int n, BinaryFunction binary_op) -{ - if (context.block_dimension() < n) - { - for (unsigned int i = context.block_dimension() + context.thread_index(); i < n; i += context.block_dimension()) - data[context.thread_index()] = binary_op(data[context.thread_index()], data[i]); - - context.barrier(); - } - - while (n > 1) - { - unsigned int half = n / 2; - - if (context.thread_index() < half) - data[context.thread_index()] = binary_op(data[context.thread_index()], data[n - context.thread_index() - 1]); - - context.barrier(); - - n = n - half; - } -} - -} // end namespace block -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/copy.h b/compat/thrust/system/cuda/detail/copy.h deleted file mode 100644 index 8f7ee97..0000000 --- a/compat/thrust/system/cuda/detail/copy.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template - OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template - OutputIterator copy(cross_system exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template - OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result); - - -template - OutputIterator copy_n(cross_system exec, - InputIterator first, - Size n, - OutputIterator result); - - -} // end detail -} // end cuda -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/copy.inl b/compat/thrust/system/cuda/detail/copy.inl deleted file mode 100644 index 125eebd..0000000 --- a/compat/thrust/system/cuda/detail/copy.inl +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template - OutputIterator copy(execution_policy &system, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - return thrust::system::cuda::detail::copy_device_to_device(system,first,last,result); -} // end copy() - - -template - OutputIterator copy(cross_system systems, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - return thrust::system::cuda::detail::copy_cross_system(systems,first,last,result); -} // end copy() - - -template - OutputIterator copy_n(execution_policy &system, - InputIterator first, - Size n, - OutputIterator result) -{ - return thrust::system::cuda::detail::copy_device_to_device(system,first,first+n,result); -} // end copy_n() - - -template - OutputIterator copy_n(cross_system systems, - InputIterator first, - Size n, - OutputIterator result) -{ - return thrust::system::cuda::detail::copy_cross_system_n(systems,first,n,result); -} // end copy_n() - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/copy_cross_system.h b/compat/thrust/system/cuda/detail/copy_cross_system.h deleted file mode 100644 index f68ea3c..0000000 --- a/compat/thrust/system/cuda/detail/copy_cross_system.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template - OutputIterator copy_cross_system(cross_system systems, - InputIterator begin, - InputIterator end, - OutputIterator result); - - -template - OutputIterator copy_cross_system_n(cross_system systems, - InputIterator begin, - Size n, - OutputIterator result); - - -} // end detail -} // end cuda -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/copy_cross_system.inl b/compat/thrust/system/cuda/detail/copy_cross_system.inl deleted file mode 100644 index 861cb2c..0000000 --- a/compat/thrust/system/cuda/detail/copy_cross_system.inl +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -// XXX WAR circular #inclusion problem -template class temporary_array; - -} // end detail - -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -// general input to random access case -template - RandomAccessIterator copy_cross_system(cross_system systems, - InputIterator begin, - InputIterator end, - RandomAccessIterator result, - thrust::incrementable_traversal_tag, - thrust::random_access_traversal_tag) -{ - //std::cerr << std::endl; - //std::cerr << "general copy_host_to_device(): InputIterator: " << typeid(InputIterator).name() << std::endl; - //std::cerr << "general copy_host_to_device(): OutputIterator: " << typeid(OutputIterator).name() << std::endl; - - typedef typename thrust::iterator_value::type InputType; - - // allocate temporary storage in System1 - thrust::detail::temporary_array temp(systems.system1,begin,end); - return thrust::copy(systems, temp.begin(), temp.end(), result); -} - -template - RandomAccessIterator copy_cross_system_n(cross_system systems, - InputIterator first, - Size n, - RandomAccessIterator result, - thrust::incrementable_traversal_tag, - thrust::random_access_traversal_tag) -{ - typedef typename thrust::iterator_value::type InputType; - - // allocate and copy to temporary storage System1 - thrust::detail::temporary_array temp(systems.system1, first, n); - - // recurse - return copy_cross_system(systems, temp.begin(), temp.end(), result); -} - - -// random access to general output case -template - OutputIterator copy_cross_system(cross_system systems, - RandomAccessIterator begin, - RandomAccessIterator end, - OutputIterator result, - thrust::random_access_traversal_tag, - thrust::incrementable_traversal_tag) -{ - typedef typename thrust::iterator_value::type InputType; - - // copy to temporary storage in System2 - thrust::detail::temporary_array temp(systems.system2, systems.system1, begin, end); - - return thrust::copy(systems.system2, temp.begin(), temp.end(), result); -} - -template - OutputIterator copy_cross_system_n(cross_system systems, - RandomAccessIterator first, - Size n, - OutputIterator result, - thrust::random_access_traversal_tag, - thrust::incrementable_traversal_tag) -{ - typedef typename thrust::iterator_value::type InputType; - - // copy to temporary storage in System2 - thrust::detail::temporary_array temp(systems.system2, systems.system1, first, n); - - // copy temp to result - return thrust::copy(systems.system2, temp.begin(), temp.end(), result); -} - - -// trivial copy -template - RandomAccessIterator2 copy_cross_system(cross_system systems, - RandomAccessIterator1 begin, - RandomAccessIterator1 end, - RandomAccessIterator2 result, - thrust::random_access_traversal_tag, - thrust::random_access_traversal_tag, - thrust::detail::true_type) // trivial copy -{ -// std::cerr << std::endl; -// std::cerr << "random access copy_device_to_host(): trivial" << std::endl; -// std::cerr << "general copy_device_to_host(): RandomAccessIterator1: " << typeid(RandomAccessIterator1).name() << std::endl; -// std::cerr << "general copy_device_to_host(): RandomAccessIterator2: " << typeid(RandomAccessIterator2).name() << std::endl; - - // how many elements to copy? - typename thrust::iterator_traits::difference_type n = end - begin; - - thrust::system::cuda::detail::trivial_copy_n(systems, begin, n, result); - - return result + n; -} - - -namespace detail -{ - -// random access non-trivial iterator to random access iterator -template - RandomAccessIterator2 non_trivial_random_access_copy_cross_system(cross_system systems, - RandomAccessIterator1 begin, - RandomAccessIterator1 end, - RandomAccessIterator2 result, - thrust::detail::false_type) // InputIterator is non-trivial -{ - // copy the input to a temporary input system buffer of OutputType - typedef typename thrust::iterator_value::type OutputType; - - // allocate temporary storage in System1 - thrust::detail::temporary_array temp(systems.system1, begin, end); - - // recurse - return copy_cross_system(systems, temp.begin(), temp.end(), result); -} - -template - RandomAccessIterator2 non_trivial_random_access_copy_cross_system(cross_system systems, - RandomAccessIterator1 begin, - RandomAccessIterator1 end, - RandomAccessIterator2 result, - thrust::detail::true_type) // InputIterator is trivial -{ - typename thrust::iterator_difference::type n = thrust::distance(begin, end); - - // allocate temporary storage in System2 - // retain the input's type for the intermediate storage - // do not initialize the storage (the 0 does this) - typedef typename thrust::iterator_value::type InputType; - thrust::detail::temporary_array temp(0, systems.system2, n); - - // force a trivial (memcpy) copy of the input to the temporary - // note that this will not correctly account for copy constructors - // but there's nothing we can do about that - // XXX one thing we might try is to use pinned memory for the temporary storage - // this might allow us to correctly account for copy constructors - thrust::system::cuda::detail::trivial_copy_n(systems, begin, n, temp.begin()); - - // finally, copy to the result - return thrust::copy(systems.system2, temp.begin(), temp.end(), result); -} - -} // end detail - - -// random access iterator to random access host iterator with non-trivial copy -template - RandomAccessIterator2 copy_cross_system(cross_system systems, - RandomAccessIterator1 begin, - RandomAccessIterator1 end, - RandomAccessIterator2 result, - thrust::random_access_traversal_tag, - thrust::random_access_traversal_tag, - thrust::detail::false_type) // is_trivial_copy -{ - // dispatch a non-trivial random access cross system copy based on whether or not the InputIterator is trivial - return detail::non_trivial_random_access_copy_cross_system(systems, begin, end, result, - typename thrust::detail::is_trivial_iterator::type()); -} - -// random access iterator to random access iterator -template - RandomAccessIterator2 copy_cross_system(cross_system systems, - RandomAccessIterator1 begin, - RandomAccessIterator1 end, - RandomAccessIterator2 result, - thrust::random_access_traversal_tag input_traversal, - thrust::random_access_traversal_tag output_traversal) -{ - // dispatch on whether this is a trivial copy - return copy_cross_system(systems, begin, end, result, input_traversal, output_traversal, - typename thrust::detail::dispatch::is_trivial_copy::type()); -} - -template - RandomAccessIterator2 copy_cross_system_n(cross_system systems, - RandomAccessIterator1 first, - Size n, - RandomAccessIterator2 result, - thrust::random_access_traversal_tag input_traversal, - thrust::random_access_traversal_tag output_traversal) -{ - // implement with copy_cross_system - return copy_cross_system(systems, first, first + n, result, input_traversal, output_traversal); -} - -///////////////// -// Entry Point // -///////////////// - -template - OutputIterator copy_cross_system(cross_system systems, - InputIterator begin, - InputIterator end, - OutputIterator result) -{ - return copy_cross_system(systems, begin, end, result, - typename thrust::iterator_traversal::type(), - typename thrust::iterator_traversal::type()); -} - -template - OutputIterator copy_cross_system_n(cross_system systems, - InputIterator begin, - Size n, - OutputIterator result) -{ - return copy_cross_system_n(systems, begin, n, result, - typename thrust::iterator_traversal::type(), - typename thrust::iterator_traversal::type()); -} - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/copy_device_to_device.h b/compat/thrust/system/cuda/detail/copy_device_to_device.h deleted file mode 100644 index a7d8df8..0000000 --- a/compat/thrust/system/cuda/detail/copy_device_to_device.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file copy_device_to_device.h - * \brief Device implementations for copying on the device. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template - OutputIterator copy_device_to_device(execution_policy &exec, - InputIterator begin, - InputIterator end, - OutputIterator result); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/copy_device_to_device.inl b/compat/thrust/system/cuda/detail/copy_device_to_device.inl deleted file mode 100644 index c8263c5..0000000 --- a/compat/thrust/system/cuda/detail/copy_device_to_device.inl +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template - OutputIterator copy_device_to_device(execution_policy &exec, - InputIterator begin, - InputIterator end, - OutputIterator result, - thrust::detail::false_type) -{ - // general case (mixed types) - typedef typename thrust::iterator_traits::value_type InputType; - -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - return thrust::transform(exec, begin, end, result, thrust::identity()); -#else - // we're not compiling with nvcc: copy [begin, end) to temp host memory - typename thrust::iterator_traits::difference_type n = thrust::distance(begin, end); - - thrust::host_system_tag temp_exec; - thrust::detail::temporary_array temp1(temp_exec, begin, end); - - // transform temp1 to OutputType in host memory - typedef typename thrust::iterator_traits::value_type OutputType; - - thrust::detail::temporary_array temp2(temp_exec, temp1.begin(), temp1.end()); - - // copy temp2 to device - result = thrust::system::cuda::detail::copy_cross_system(temp2.begin(), temp2.end(), result); - - return result; -#endif // THRUST_DEVICE_COMPILER_NVCC -} - - -template - OutputIterator copy_device_to_device(execution_policy &exec, - InputIterator begin, - InputIterator end, - OutputIterator result, - thrust::detail::true_type) -{ - // specialization for device to device when the value_types match, operator= is not overloaded, - // and the iterators are pointers - - // how many elements to copy? - typename thrust::iterator_traits::difference_type n = end - begin; - - thrust::system::cuda::detail::trivial_copy_n(exec, begin, n, result); - - return result + n; -} - -} // end namespace detail - -///////////////// -// Entry Point // -///////////////// - -template - OutputIterator copy_device_to_device(execution_policy &exec, - InputIterator begin, - InputIterator end, - OutputIterator result) -{ - typedef typename thrust::iterator_traits::value_type InputType; - typedef typename thrust::iterator_traits::value_type OutputType; - - const bool use_trivial_copy = - thrust::detail::is_same::value - && thrust::detail::is_trivial_iterator::value - && thrust::detail::is_trivial_iterator::value; - - // XXX WAR unused variable warning - (void) use_trivial_copy; - - return detail::copy_device_to_device(exec, begin, end, result, - thrust::detail::integral_constant()); - -} - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/copy_if.h b/compat/thrust/system/cuda/detail/copy_if.h deleted file mode 100644 index 5ed0f6c..0000000 --- a/compat/thrust/system/cuda/detail/copy_if.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - OutputIterator copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/copy_if.inl b/compat/thrust/system/cuda/detail/copy_if.inl deleted file mode 100644 index 15ea7fa..0000000 --- a/compat/thrust/system/cuda/detail/copy_if.inl +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template -struct copy_if_intervals_closure -{ - InputIterator1 input; - InputIterator2 stencil; - InputIterator3 offsets; - Decomposition decomp; - OutputIterator output; - - typedef Context context_type; - context_type context; - - copy_if_intervals_closure(InputIterator1 input, - InputIterator2 stencil, - InputIterator3 offsets, - Decomposition decomp, - OutputIterator output, - Context context = Context()) - : input(input), stencil(stencil), offsets(offsets), decomp(decomp), output(output), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename thrust::iterator_value::type OutputType; - - typedef unsigned int PredicateType; - - const unsigned int CTA_SIZE = context_type::ThreadsPerBlock::value; - - thrust::plus binary_op; - - __shared__ PredicateType sdata[CTA_SIZE]; context.barrier(); - - typedef typename Decomposition::index_type IndexType; - - // this block processes results in [range.begin(), range.end()) - thrust::system::detail::internal::index_range range = decomp[context.block_index()]; - - IndexType base = range.begin(); - - PredicateType predicate = 0; - - // advance input iterators to this thread's starting position - input += base + context.thread_index(); - stencil += base + context.thread_index(); - - // advance output to this interval's starting position - if (context.block_index() != 0) - { - InputIterator3 temp = offsets + (context.block_index() - 1); - output += *temp; - } - - // process full blocks - while(base + CTA_SIZE <= range.end()) - { - // read data - sdata[context.thread_index()] = predicate = *stencil; - - context.barrier(); - - // scan block - block::inclusive_scan(context, sdata, binary_op); - - // write data - if (predicate) - { - OutputIterator temp2 = output + (sdata[context.thread_index()] - 1); - *temp2 = *input; - } - - // advance inputs by CTA_SIZE - base += CTA_SIZE; - input += CTA_SIZE; - stencil += CTA_SIZE; - - // advance output by number of true predicates - output += sdata[CTA_SIZE - 1]; - - context.barrier(); - } - - // process partially full block at end of input (if necessary) - if (base < range.end()) - { - // read data - if (base + context.thread_index() < range.end()) - sdata[context.thread_index()] = predicate = *stencil; - else - sdata[context.thread_index()] = predicate = 0; - - context.barrier(); - - // scan block - block::inclusive_scan(context, sdata, binary_op); - - // write data - if (predicate) // expects predicate=false for >= interval_end - { - OutputIterator temp2 = output + (sdata[context.thread_index()] - 1); - *temp2 = *input; - } - } - } -}; // copy_if_intervals_closure - - -template - OutputIterator copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator output, - Predicate pred) -{ - typedef typename thrust::iterator_difference::type IndexType; - typedef typename thrust::iterator_value::type OutputType; - - if (first == last) - return output; - - typedef thrust::system::detail::internal::uniform_decomposition Decomposition; - typedef thrust::detail::temporary_array IndexArray; - - Decomposition decomp = default_decomposition(last - first); - - // storage for per-block predicate counts - IndexArray block_results(exec, decomp.size()); - - // convert stencil into an iterator that produces integral values in {0,1} - typedef typename thrust::detail::predicate_to_integral PredicateToIndexTransform; - typedef thrust::transform_iterator PredicateToIndexIterator; - - PredicateToIndexIterator predicate_stencil(stencil, PredicateToIndexTransform(pred)); - - // compute number of true values in each interval - thrust::system::cuda::detail::reduce_intervals(exec, predicate_stencil, block_results.begin(), thrust::plus(), decomp); - - // scan the partial sums - thrust::inclusive_scan(exec, block_results.begin(), block_results.end(), block_results.begin(), thrust::plus()); - - // copy values to output - const unsigned int ThreadsPerBlock = 256; - typedef typename IndexArray::iterator InputIterator3; - typedef detail::statically_blocked_thread_array Context; - typedef copy_if_intervals_closure Closure; - Closure closure(first, predicate_stencil, block_results.begin(), decomp, output); - detail::launch_closure(closure, decomp.size(), ThreadsPerBlock); - - return output + block_results[decomp.size() - 1]; -} // end copy_if() - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - diff --git a/compat/thrust/system/cuda/detail/count.h b/compat/thrust/system/cuda/detail/count.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/count.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/cuda_launch_config.h b/compat/thrust/system/cuda/detail/cuda_launch_config.h deleted file mode 100644 index b7f0ca2..0000000 --- a/compat/thrust/system/cuda/detail/cuda_launch_config.h +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -// XXX define our own device_properties_t to avoid errors when #including -// this file in the absence of a CUDA installation -struct device_properties_t -{ - // mirror the type and spelling of cudaDeviceProp's members - // keep these alphabetized - int major; - int maxGridSize[3]; - int maxThreadsPerBlock; - int maxThreadsPerMultiProcessor; - int minor; - int multiProcessorCount; - int regsPerBlock; - size_t sharedMemPerBlock; - int warpSize; -}; - - -// XXX define our own device_properties_t to avoid errors when #including -// this file in the absence of a CUDA installation -struct function_attributes_t -{ - // mirror the type and spelling of cudaFuncAttributes' members - // keep these alphabetized - size_t constSizeBytes; - size_t localSizeBytes; - int maxThreadsPerBlock; - int numRegs; - size_t sharedSizeBytes; -}; - - -/*! Computes a block size in number of threads for a CUDA kernel using a occupancy-promoting heuristic. - * \param attributes The cudaFuncAttributes corresponding to a __global__ function of interest on a GPU of interest. - * \param properties The cudaDeviceProp corresponding to a GPU on which to launch the __global__ function of interest. - * \return A CUDA block size, in number of threads, which the resources of the GPU's streaming multiprocessor can - * accomodate and which is intended to promote occupancy. The result is equivalent to the one performed by - * the "CUDA Occupancy Calculator". - * \note The __global__ function of interest is presumed to use 0 bytes of dynamically-allocated __shared__ memory. - */ -inline __host__ __device__ -std::size_t block_size_with_maximum_potential_occupancy(const function_attributes_t &attributes, - const device_properties_t &properties); - -/*! Computes a block size in number of threads for a CUDA kernel using a occupancy-promoting heuristic. - * Use this version of the function when a CUDA block's dynamically-allocated __shared__ memory requirements - * vary with the size of the block. - * \param attributes The cudaFuncAttributes corresponding to a __global__ function of interest on a GPU of interest. - * \param properties The cudaDeviceProp corresponding to a GPU on which to launch the __global__ function of interest. - * \param block_size_to_dynamic_smem_bytes A unary function which maps an integer CUDA block size to the number of bytes - * of dynamically-allocated __shared__ memory required by a CUDA block of that size. - * \return A CUDA block size, in number of threads, which the resources of the GPU's streaming multiprocessor can - * accomodate and which is intended to promote occupancy. The result is equivalent to the one performed by - * the "CUDA Occupancy Calculator". - */ -template -inline __host__ __device__ -std::size_t block_size_with_maximum_potential_occupancy(const function_attributes_t &attributes, - const device_properties_t &properties, - UnaryFunction block_size_to_dynamic_smem_size); - - -/*! Returns the maximum amount of dynamic shared memory each block - * can utilize without reducing thread occupancy. - * - * \param properties CUDA device properties - * \param attributes CUDA function attributes - * \param blocks_per_processor Number of blocks per streaming multiprocessor - */ -inline __host__ __device__ -size_t proportional_smem_allocation(const device_properties_t &properties, - const function_attributes_t &attributes, - size_t blocks_per_processor); - - -template -inline __host__ __device__ -size_t max_blocksize_subject_to_smem_usage(const device_properties_t &properties, - const function_attributes_t &attributes, - UnaryFunction blocksize_to_dynamic_smem_usage); - - - -namespace cuda_launch_config_detail -{ - -using std::size_t; - -namespace util -{ - - -template -inline __host__ __device__ -T min_(const T &lhs, const T &rhs) -{ - return rhs < lhs ? rhs : lhs; -} - - -template -struct zero_function -{ - inline __host__ __device__ - T operator()(T) - { - return 0; - } -}; - - -// x/y rounding towards +infinity for integers, used to determine # of blocks/warps etc. -template - inline __host__ __device__ L divide_ri(const L x, const R y) -{ - return (x + (y - 1)) / y; -} - -// x/y rounding towards zero for integers, used to determine # of blocks/warps etc. -template - inline __host__ __device__ L divide_rz(const L x, const R y) -{ - return x / y; -} - -// round x towards infinity to the next multiple of y -template - inline __host__ __device__ L round_i(const L x, const R y){ return y * divide_ri(x, y); } - -// round x towards zero to the next multiple of y -template - inline __host__ __device__ L round_z(const L x, const R y){ return y * divide_rz(x, y); } - -} // end namespace util - - - -// granularity of shared memory allocation -inline __host__ __device__ -size_t smem_allocation_unit(const device_properties_t &properties) -{ - switch(properties.major) - { - case 1: return 512; - case 2: return 128; - case 3: return 256; - default: return 256; // unknown GPU; have to guess - } -} - - -// granularity of register allocation -inline __host__ __device__ -size_t reg_allocation_unit(const device_properties_t &properties, const size_t regsPerThread) -{ - switch(properties.major) - { - case 1: return (properties.minor <= 1) ? 256 : 512; - case 2: switch(regsPerThread) - { - case 21: - case 22: - case 29: - case 30: - case 37: - case 38: - case 45: - case 46: - return 128; - default: - return 64; - } - case 3: return 256; - default: return 256; // unknown GPU; have to guess - } -} - - -// granularity of warp allocation -inline __host__ __device__ -size_t warp_allocation_multiple(const device_properties_t &properties) -{ - return (properties.major <= 1) ? 2 : 1; -} - -// number of "sides" into which the multiprocessor is partitioned -inline __host__ __device__ -size_t num_sides_per_multiprocessor(const device_properties_t &properties) -{ - switch(properties.major) - { - case 1: return 1; - case 2: return 2; - case 3: return 4; - default: return 4; // unknown GPU; have to guess - } -} - - -inline __host__ __device__ -size_t max_blocks_per_multiprocessor(const device_properties_t &properties) -{ - return (properties.major <= 2) ? 8 : 16; -} - - -inline __host__ __device__ -size_t max_active_blocks_per_multiprocessor(const device_properties_t &properties, - const function_attributes_t &attributes, - int CTA_SIZE, - size_t dynamic_smem_bytes) -{ - // Determine the maximum number of CTAs that can be run simultaneously per SM - // This is equivalent to the calculation done in the CUDA Occupancy Calculator spreadsheet - - ////////////////////////////////////////// - // Limits due to threads/SM or blocks/SM - ////////////////////////////////////////// - const size_t maxThreadsPerSM = properties.maxThreadsPerMultiProcessor; // 768, 1024, 1536, etc. - const size_t maxBlocksPerSM = max_blocks_per_multiprocessor(properties); - - // Calc limits - const size_t ctaLimitThreads = (CTA_SIZE <= properties.maxThreadsPerBlock) ? maxThreadsPerSM / CTA_SIZE : 0; - const size_t ctaLimitBlocks = maxBlocksPerSM; - - ////////////////////////////////////////// - // Limits due to shared memory/SM - ////////////////////////////////////////// - const size_t smemAllocationUnit = smem_allocation_unit(properties); - const size_t smemBytes = attributes.sharedSizeBytes + dynamic_smem_bytes; - const size_t smemPerCTA = util::round_i(smemBytes, smemAllocationUnit); - - // Calc limit - const size_t ctaLimitSMem = smemPerCTA > 0 ? properties.sharedMemPerBlock / smemPerCTA : maxBlocksPerSM; - - ////////////////////////////////////////// - // Limits due to registers/SM - ////////////////////////////////////////// - const size_t regAllocationUnit = reg_allocation_unit(properties, attributes.numRegs); - const size_t warpAllocationMultiple = warp_allocation_multiple(properties); - const size_t numWarps = util::round_i(util::divide_ri(CTA_SIZE, properties.warpSize), warpAllocationMultiple); - - // Calc limit - size_t ctaLimitRegs; - if(properties.major <= 1) - { - // GPUs of compute capability 1.x allocate registers to CTAs - // Number of regs per block is regs per thread times number of warps times warp size, rounded up to allocation unit - const size_t regsPerCTA = util::round_i(attributes.numRegs * properties.warpSize * numWarps, regAllocationUnit); - ctaLimitRegs = regsPerCTA > 0 ? properties.regsPerBlock / regsPerCTA : maxBlocksPerSM; - } - else - { - // GPUs of compute capability 2.x and higher allocate registers to warps - // Number of regs per warp is regs per thread times times warp size, rounded up to allocation unit - const size_t regsPerWarp = util::round_i(attributes.numRegs * properties.warpSize, regAllocationUnit); - const size_t numSides = num_sides_per_multiprocessor(properties); - const size_t numRegsPerSide = properties.regsPerBlock / numSides; - ctaLimitRegs = regsPerWarp > 0 ? ((numRegsPerSide / regsPerWarp) * numSides) / numWarps : maxBlocksPerSM; - } - - ////////////////////////////////////////// - // Overall limit is min() of limits due to above reasons - ////////////////////////////////////////// - return util::min_(ctaLimitRegs, util::min_(ctaLimitSMem, util::min_(ctaLimitThreads, ctaLimitBlocks))); -} - - -} // end namespace cuda_launch_config_detail - - -template -inline __host__ __device__ -std::size_t block_size_with_maximum_potential_occupancy(const function_attributes_t &attributes, - const device_properties_t &properties, - UnaryFunction block_size_to_dynamic_smem_size) -{ - size_t max_occupancy = properties.maxThreadsPerMultiProcessor; - size_t largest_blocksize = cuda_launch_config_detail::util::min_(properties.maxThreadsPerBlock, attributes.maxThreadsPerBlock); - size_t granularity = properties.warpSize; - size_t max_blocksize = 0; - size_t highest_occupancy = 0; - - for(size_t blocksize = largest_blocksize; blocksize != 0; blocksize -= granularity) - { - size_t occupancy = blocksize * cuda_launch_config_detail::max_active_blocks_per_multiprocessor(properties, attributes, blocksize, block_size_to_dynamic_smem_size(blocksize)); - - if(occupancy > highest_occupancy) - { - max_blocksize = blocksize; - highest_occupancy = occupancy; - } - - // early out, can't do better - if(highest_occupancy == max_occupancy) - break; - } - - return max_blocksize; -} - - -inline __host__ __device__ -std::size_t block_size_with_maximum_potential_occupancy(const function_attributes_t &attributes, - const device_properties_t &properties) -{ - return block_size_with_maximum_potential_occupancy(attributes, properties, cuda_launch_config_detail::util::zero_function()); -} - - -inline __host__ __device__ -size_t proportional_smem_allocation(const device_properties_t &properties, - const function_attributes_t &attributes, - size_t blocks_per_processor) -{ - size_t smem_per_processor = properties.sharedMemPerBlock; - size_t smem_allocation_unit = cuda_launch_config_detail::smem_allocation_unit(properties); - - size_t total_smem_per_block = cuda_launch_config_detail::util::round_z(smem_per_processor / blocks_per_processor, smem_allocation_unit); - size_t static_smem_per_block = attributes.sharedSizeBytes; - - return total_smem_per_block - static_smem_per_block; -} - - -template -inline __host__ __device__ -size_t max_blocksize_subject_to_smem_usage(const device_properties_t &properties, - const function_attributes_t &attributes, - UnaryFunction blocksize_to_dynamic_smem_usage) -{ - size_t largest_blocksize = (thrust::min)(properties.maxThreadsPerBlock, attributes.maxThreadsPerBlock); - size_t granularity = properties.warpSize; - - for(int blocksize = largest_blocksize; blocksize > 0; blocksize -= granularity) - { - size_t total_smem_usage = blocksize_to_dynamic_smem_usage(blocksize) + attributes.sharedSizeBytes; - - if(total_smem_usage <= properties.sharedMemPerBlock) - { - return blocksize; - } - } - - return 0; -} - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/default_decomposition.h b/compat/thrust/system/cuda/detail/default_decomposition.h deleted file mode 100644 index 1ed6bcf..0000000 --- a/compat/thrust/system/cuda/detail/default_decomposition.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file default_decomposition.h - * \brief Return a decomposition that is appropriate for the CUDA backend. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template -thrust::system::detail::internal::uniform_decomposition default_decomposition(IndexType n); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/default_decomposition.inl b/compat/thrust/system/cuda/detail/default_decomposition.inl deleted file mode 100644 index 3f0879a..0000000 --- a/compat/thrust/system/cuda/detail/default_decomposition.inl +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template -thrust::system::detail::internal::uniform_decomposition default_decomposition(IndexType n) -{ - // TODO eliminate magical constant - device_properties_t properties = device_properties(); - return thrust::system::detail::internal::uniform_decomposition(n, properties.maxThreadsPerBlock, 10 * properties.multiProcessorCount); -} - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/alignment.h b/compat/thrust/system/cuda/detail/detail/alignment.h deleted file mode 100644 index 31fdaaf..0000000 --- a/compat/thrust/system/cuda/detail/detail/alignment.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace alignment_of_detail -{ - - -template class alignment_of_impl; - -template - struct helper -{ - static const std::size_t value = size_diff; -}; - -template - class helper -{ - public: - static const std::size_t value = alignment_of_impl::value; -}; - -template - class alignment_of_impl -{ - private: - struct big { T x; char c; }; - - public: - static const std::size_t value = helper::value; -}; - - -} // end alignment_of_detail - - -template - struct alignment_of - : alignment_of_detail::alignment_of_impl -{}; - - -template struct aligned_type; - -// __align__ is CUDA-specific, so guard it -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - -// implementing aligned_type portably is tricky: - -# if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC -// implement aligned_type with specialization because MSVC -// requires literals as arguments to declspec(align(n)) -template<> struct aligned_type<1> -{ - struct __align__(1) type { }; -}; - -template<> struct aligned_type<2> -{ - struct __align__(2) type { }; -}; - -template<> struct aligned_type<4> -{ - struct __align__(4) type { }; -}; - -template<> struct aligned_type<8> -{ - struct __align__(8) type { }; -}; - -template<> struct aligned_type<16> -{ - struct __align__(16) type { }; -}; - -template<> struct aligned_type<32> -{ - struct __align__(32) type { }; -}; - -template<> struct aligned_type<64> -{ - struct __align__(64) type { }; -}; - -template<> struct aligned_type<128> -{ - struct __align__(128) type { }; -}; - -template<> struct aligned_type<256> -{ - struct __align__(256) type { }; -}; - -template<> struct aligned_type<512> -{ - struct __align__(512) type { }; -}; - -template<> struct aligned_type<1024> -{ - struct __align__(1024) type { }; -}; - -template<> struct aligned_type<2048> -{ - struct __align__(2048) type { }; -}; - -template<> struct aligned_type<4096> -{ - struct __align__(4096) type { }; -}; - -template<> struct aligned_type<8192> -{ - struct __align__(8192) type { }; -}; -# elif (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC) && (THRUST_GCC_VERSION < 40300) -// implement aligned_type with specialization because gcc 4.2 -// requires literals as arguments to __attribute__(aligned(n)) -template<> struct aligned_type<1> -{ - struct __align__(1) type { }; -}; - -template<> struct aligned_type<2> -{ - struct __align__(2) type { }; -}; - -template<> struct aligned_type<4> -{ - struct __align__(4) type { }; -}; - -template<> struct aligned_type<8> -{ - struct __align__(8) type { }; -}; - -template<> struct aligned_type<16> -{ - struct __align__(16) type { }; -}; - -template<> struct aligned_type<32> -{ - struct __align__(32) type { }; -}; - -template<> struct aligned_type<64> -{ - struct __align__(64) type { }; -}; - -template<> struct aligned_type<128> -{ - struct __align__(128) type { }; -}; - -# else -// assume the compiler allows template parameters as -// arguments to __align__ -template struct aligned_type -{ - struct __align__(Align) type { }; -}; -# endif // THRUST_HOST_COMPILER -#else -template struct aligned_type -{ - struct type { }; -}; -#endif // THRUST_DEVICE_COMPILER - - -template - struct aligned_storage -{ - union type - { - unsigned char data[Len]; - - typename aligned_type::type align; - }; -}; - - -} // end detail -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/kernel_utils.h b/compat/thrust/system/cuda/detail/detail/b40c/kernel_utils.h deleted file mode 100644 index e2c5a44..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/kernel_utils.h +++ /dev/null @@ -1,284 +0,0 @@ -/** - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - */ - - -//------------------------------------------------------------------------------ -// Common B40C Defines, Properties, and Routines -//------------------------------------------------------------------------------ - - -#pragma once - -#include -#include - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - -//------------------------------------------------------------------------------ -// Device properties -//------------------------------------------------------------------------------ - - -#ifndef __CUDA_ARCH__ - #define __CUDA_ARCH__ 0 -#endif - -#define B40C_FERMI(version) (version >= 200) -#define B40C_LOG_WARP_THREADS 5 // 32 threads in a warp -#define B40C_WARP_THREADS (1 << B40C_LOG_WARP_THREADS) -#define B40C_LOG_MEM_BANKS(version) ((version >= 200) ? 5 : 4) // 32 banks on fermi, 16 on tesla -#define B40C_MEM_BANKS(version) (1 << B40C_LOG_MEM_BANKS(version)) - -// TODO refactor these -#if __CUDA_ARCH__ >= 200 - #define FastMul(a, b) (a * b) -#else - #define FastMul(a, b) (__umul24(a, b)) -#endif - -#if __CUDA_ARCH__ >= 120 - #define WarpVoteAll(active_threads, predicate) (__all(predicate)) -#else - #define WarpVoteAll(active_threads, predicate) (EmulatedWarpVoteAll(predicate)) -#endif - -#if __CUDA_ARCH__ >= 200 - #define TallyWarpVote(active_threads, predicate, storage) (__popc(__ballot(predicate))) -#else - #define TallyWarpVote(active_threads, predicate, storage) (TallyWarpVoteSm10(predicate, storage)) -#endif - -#ifdef __LP64__ - #define _B40C_LP64_ true -#else - #define _B40C_LP64_ false -#endif - -#define _B40C_REG_MISER_QUALIFIER_ __shared__ - - -//------------------------------------------------------------------------------ -// Handy routines -//------------------------------------------------------------------------------ - - -/** - * Select maximum - */ -#define B40C_MAX(a, b) ((a > b) ? a : b) - - -/** - * MagnitudeShift(). Allows you to shift left for positive magnitude values, - * right for negative. - * - * N.B. This code is a little strange; we are using this meta-programming - * pattern of partial template specialization for structures in order to - * decide whether to shift left or right. Normally we would just use a - * conditional to decide if something was negative or not and then shift - * accordingly, knowing that the compiler will elide the untaken branch, - * i.e., the out-of-bounds shift during dead code elimination. However, - * the pass for bounds-checking shifts seems to happen before the DCE - * phase, which results in a an unsightly number of compiler warnings, so - * we force the issue earlier using structural template specialization. - */ - -template struct MagnitudeShiftOp; - -template -struct MagnitudeShiftOp { - __device__ __forceinline__ static K Shift(K key) { - return key << magnitude; - } -}; - -template -struct MagnitudeShiftOp { - __device__ __forceinline__ static K Shift(K key) { - return key >> magnitude; - } -}; - -template -__device__ __forceinline__ K MagnitudeShift(K key) { - return MagnitudeShiftOp 0) ? magnitude : magnitude * -1, (magnitude > 0)>::Shift(key); -} - - -/** - * Supress warnings for unused constants - */ -template -__device__ __forceinline__ void SuppressUnusedConstantWarning(const T) {} - - - - -//------------------------------------------------------------------------------ -// Common device routines -//------------------------------------------------------------------------------ - - -/** - * Perform a warp-synchrounous prefix scan. Allows for diverting a warp's - * threads into separate scan problems (multi-scan). - */ -template -__device__ __forceinline__ int WarpScan( - volatile int warpscan[][NUM_ELEMENTS], - int partial_reduction, - int copy_section) { - - int warpscan_idx; - if (MULTI_SCAN) { - warpscan_idx = threadIdx.x & (NUM_ELEMENTS - 1); - } else { - warpscan_idx = threadIdx.x; - } - - warpscan[1][warpscan_idx] = partial_reduction; - - if (NUM_ELEMENTS > 1) warpscan[1][warpscan_idx] = partial_reduction = - partial_reduction + warpscan[1][warpscan_idx - 1]; - if (NUM_ELEMENTS > 2) warpscan[1][warpscan_idx] = partial_reduction = - partial_reduction + warpscan[1][warpscan_idx - 2]; - if (NUM_ELEMENTS > 4) warpscan[1][warpscan_idx] = partial_reduction = - partial_reduction + warpscan[1][warpscan_idx - 4]; - if (NUM_ELEMENTS > 8) warpscan[1][warpscan_idx] = partial_reduction = - partial_reduction + warpscan[1][warpscan_idx - 8]; - if (NUM_ELEMENTS > 16) warpscan[1][warpscan_idx] = partial_reduction = - partial_reduction + warpscan[1][warpscan_idx - 16]; - - if (copy_section > 0) { - warpscan[1 + copy_section][warpscan_idx] = partial_reduction; - } - - return warpscan[1][warpscan_idx - 1]; -} - -/** - * Perform a warp-synchronous reduction - */ -template -__device__ __forceinline__ void WarpReduce( - int idx, - volatile int *storage, - int partial_reduction) -{ - storage[idx] = partial_reduction; - - if (NUM_ELEMENTS > 16) storage[idx] = partial_reduction = partial_reduction + storage[idx + 16]; - if (NUM_ELEMENTS > 8) storage[idx] = partial_reduction = partial_reduction + storage[idx + 8]; - if (NUM_ELEMENTS > 4) storage[idx] = partial_reduction = partial_reduction + storage[idx + 4]; - if (NUM_ELEMENTS > 2) storage[idx] = partial_reduction = partial_reduction + storage[idx + 2]; - if (NUM_ELEMENTS > 1) storage[idx] = partial_reduction = partial_reduction + storage[idx + 1]; -} - - -/** - * Tally a warp-vote regarding the given predicate using the supplied storage - */ -template -__device__ __forceinline__ int TallyWarpVoteSm10(int predicate, int storage[]) { - WarpReduce(threadIdx.x, storage, predicate); - return storage[0]; -} - - -/** - * Tally a warp-vote regarding the given predicate - */ -template -__device__ __forceinline__ int TallyWarpVoteSm10(int predicate) { - __shared__ int vote_reduction[B40C_WARP_THREADS]; - return TallyWarpVoteSm10(predicate, vote_reduction); -} - -/** - * Emulate the __all() warp vote instruction - */ -template -__device__ __forceinline__ int EmulatedWarpVoteAll(int predicate) { - return (TallyWarpVoteSm10(predicate) == ACTIVE_THREADS); -} - - -/** - * Have each thread concurrently perform a serial reduction over its specified segment - */ -template -__device__ __forceinline__ int -SerialReduce(int segment[]) { - - int reduce = segment[0]; - - #pragma unroll - for (int i = 1; i < (int) LENGTH; i++) { - reduce += segment[i]; - } - - return reduce; -} - - -/** - * Have each thread concurrently perform a serial scan over its specified segment - */ -template -__device__ __forceinline__ -void SerialScan(int segment[], int seed0) { - - int seed1; - - #pragma unroll - for (int i = 0; i < (int) LENGTH; i += 2) { - seed1 = segment[i] + seed0; - segment[i] = seed0; - seed0 = seed1 + segment[i + 1]; - segment[i + 1] = seed1; - } -} - - - - -//------------------------------------------------------------------------------ -// Empty Kernels -//------------------------------------------------------------------------------ - -template -__global__ void FlushKernel(void) -{ -} - - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_api.h b/compat/thrust/system/cuda/detail/detail/b40c/radixsort_api.h deleted file mode 100644 index 2b199bb..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_api.h +++ /dev/null @@ -1,807 +0,0 @@ -/****************************************************************************** - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * - * - * AUTHORS' REQUEST: - * - * If you use|reference|benchmark this code, please cite our Technical - * Report (http://www.cs.virginia.edu/~dgm4d/papers/RadixSortTR.pdf): - * - * @TechReport{ Merrill:Sorting:2010, - * author = "Duane Merrill and Andrew Grimshaw", - * title = "Revisiting Sorting for GPGPU Stream Architectures", - * year = "2010", - * institution = "University of Virginia, Department of Computer Science", - * address = "Charlottesville, VA, USA", - * number = "CS2010-03" - * } - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - ******************************************************************************/ - - - -/****************************************************************************** - * Radix Sorting API - * - * USAGE: - * - * Using the B40C radix sorting implementation is easy. Just #include this API - * file and its kernel include dependencies within your source. Below are two - * examples for using: - * - * (1) A keys-only example for sorting floats: - * - * // Create storage-management structure - * RadixSortStorage device_storage(d_float_keys); - * - * // Create and enact sorter - * RadixSortingEnactor sorter(d_float_keys_len); - * sorter.EnactSort(device_storage); - * - * // Re-acquire pointer to sorted keys, free unused/temp storage - * d_float_keys = device_storage.d_keys; - * device_storage.CleanupTempStorage(); - * - * (2) And a key-value example for sorting ints paired with doubles: - * - * // Create storage-management structure - * RadixSortStorage device_storage(d_int_keys, d_double_values); - * - * // Create and enact sorter - * RadixSortingEnactor sorter(d_int_keys_len); - * sorter.EnactSort(device_storage); - * - * // Re-acquire pointer to sorted keys and values, free unused/temp storage - * d_int_keys = device_storage.d_keys; - * d_double_values = device_storage.d_values; - * device_storage.CleanupTempStorage(); - * - * - ******************************************************************************/ - -#pragma once - -#include -#include -#include -#include -#include - -#include "radixsort_reduction_kernel.h" -#include "radixsort_spine_kernel.h" -#include "radixsort_scanscatter_kernel.h" - -#include - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - - -/****************************************************************************** - * Debugging options - ******************************************************************************/ - -static bool RADIXSORT_DEBUG = false; - - - -/****************************************************************************** - * Structures for mananging device-side sorting state - ******************************************************************************/ - -/** - * Sorting storage-management structure for device vectors - */ -template -struct RadixSortStorage { - - // Device vector of keys to sort - K* d_keys; - - // Device vector of values to sort - V* d_values; - - // Ancillary device vector for key storage - K* d_alt_keys; - - // Ancillary device vector for value storage - V* d_alt_values; - - // Temporary device storage needed for radix sorting histograms - int *d_spine; - - // Flip-flopping temporary device storage denoting which digit place - // pass should read from which input source (i.e., false if reading from - // keys, true if reading from alternate_keys - bool *d_from_alt_storage; - - // Host-side boolean whether or not an odd number of sorting passes left the - // results in alternate storage. If so, the d_keys (and d_values) pointers - // will have been swapped with the d_alt_keys (and d_alt_values) pointers in order to - // point to the final results. - bool using_alternate_storage; - - // Constructor - RadixSortStorage(K* keys = NULL, V* values = NULL) - { - d_keys = keys; - d_values = values; - d_alt_keys = NULL; - d_alt_values = NULL; - d_spine = NULL; - d_from_alt_storage = NULL; - - using_alternate_storage = false; - } - - // Clean up non-results storage (may include freeing original storage if - // primary pointers were swizzled as per using_alternate_storage) - cudaError_t CleanupTempStorage() - { - if (d_alt_keys) cudaFree(d_alt_keys); - if (d_alt_values) cudaFree(d_alt_values); - if (d_spine) cudaFree(d_spine); - if (d_from_alt_storage) cudaFree(d_from_alt_storage); - - return cudaSuccess; - } -}; - - - -/****************************************************************************** - * Base class for sorting enactors - ******************************************************************************/ - - -/** - * Base class for SRTS radix sorting enactors. - */ -template -class BaseRadixSortingEnactor -{ -public: - - // Unsigned integer type suitable for radix sorting of keys - typedef typename KeyConversion::UnsignedBits ConvertedKeyType; - -protected: - - // - // Information about our problem configuration - // - - bool _keys_only; - unsigned int _num_elements; - int _cycle_elements; - int _spine_elements; - int _grid_size; - CtaDecomposition _work_decomposition; - int _passes; - bool _swizzle_pointers_for_odd_passes; - - // Information about our target device - cudaDeviceProp _device_props; - int _device_sm_version; - - // Information about our kernel assembly - int _kernel_ptx_version; - cudaFuncAttributes _spine_scan_kernel_attrs; - -protected: - - /** - * Constructor. - */ - BaseRadixSortingEnactor(int passes, int radix_bits, unsigned int num_elements, int max_grid_size, bool swizzle_pointers_for_odd_passes = true); - - /** - * Heuristic for determining the number of CTAs to launch. - * - * @param[in] max_grid_size - * Maximum allowable number of CTAs to launch. A value of 0 indicates - * that the default value should be used. - * - * @return The actual number of CTAs that should be launched - */ - int GridSize(int max_grid_size); - - /** - * Performs a distribution sorting pass over a single digit place - */ - template - cudaError_t DigitPlacePass(const RadixSortStorage &converted_storage); - - /** - * Enacts a sorting operation by performing the the appropriate - * digit-place passes. To be overloaded by specialized subclasses. - */ - virtual cudaError_t EnactDigitPlacePasses(const RadixSortStorage &converted_storage) = 0; - -public: - - /** - * Returns the length (in unsigned ints) of the device vector needed for - * temporary storage of the reduction spine. Useful if pre-allocating - * your own device storage (as opposed to letting EnactSort() allocate it - * for you). - */ - int SpineElements() { return _spine_elements; } - - /** - * Returns whether or not the problem will fit on the device. - */ - bool CanFit(); - - /** - * Enacts a radix sorting operation on the specified device data. - * - * IMPORTANT NOTES: The device storage backing the specified input vectors of - * keys (and data) will be modified. (I.e., treat this as an in-place sort.) - * - * Additionally, the pointers in the problem_storage structure may be updated - * (a) depending upon the number of digit-place sorting passes needed, and (b) - * whether or not the caller has already allocated temporary storage. - * - * The sorted results will always be referenced by problem_storage.d_keys (and - * problem_storage.d_values). However, for an odd number of sorting passes (uncommon) - * these results will actually be backed by the storage initially allocated for - * by problem_storage.d_alt_keys (and problem_storage.d_alt_values). If so, - * problem_storage.d_alt_keys and problem_storage.d_alt_keys will be updated to - * reference the original problem_storage.d_keys and problem_storage.d_values in order - * to facilitate cleanup. - * - * This means it is important to avoid keeping stale copies of device pointers - * to keys/data; you will want to re-reference the pointers in problem_storage. - * - * @param[in/out] problem_storage - * Device vectors of keys and values to sort, and ancillary storage - * needed by the sorting kernels. See the IMPORTANT NOTES above. - * - * The problem_storage.[alternate_keys|alternate_values|d_spine] fields are - * temporary storage needed by the sorting kernels. To facilitate - * speed, callers are welcome to re-use this storage for same-sized - * (or smaller) sortign problems. If NULL, these storage vectors will be - * allocated by this routine (and must be subsequently cuda-freed by - * the caller). - * - * @return cudaSuccess on success, error enumeration otherwise - */ - cudaError_t EnactSort(RadixSortStorage &problem_storage); - - /* - * Destructor - */ - virtual ~BaseRadixSortingEnactor() {} -}; - - - -template -BaseRadixSortingEnactor::BaseRadixSortingEnactor( - int passes, - int max_radix_bits, - unsigned int num_elements, - int max_grid_size, - bool swizzle_pointers_for_odd_passes) -{ - // - // Get current device properties - // - - int current_device; - cudaGetDevice(¤t_device); - cudaGetDeviceProperties(&_device_props, current_device); - _device_sm_version = _device_props.major * 100 + _device_props.minor * 10; - - - // - // Get SM version of compiled kernel assembly - // - cudaFuncGetAttributes(&_spine_scan_kernel_attrs, SrtsScanSpine); - _kernel_ptx_version = _spine_scan_kernel_attrs.ptxVersion * 10; - - - // - // Determine number of CTAs to launch, shared memory, cycle elements, etc. - // - - _passes = passes; - _num_elements = num_elements; - _keys_only = IsKeysOnly(); - _cycle_elements = B40C_RADIXSORT_CYCLE_ELEMENTS(_kernel_ptx_version , ConvertedKeyType, V); - _grid_size = GridSize(max_grid_size); - _swizzle_pointers_for_odd_passes = swizzle_pointers_for_odd_passes; - - int total_cycles = _num_elements / _cycle_elements; - unsigned int cycles_per_block = total_cycles / _grid_size; - unsigned int extra_cycles = total_cycles - (cycles_per_block * _grid_size); - - CtaDecomposition work_decomposition = { - extra_cycles, // num_big_blocks - (cycles_per_block + 1) * _cycle_elements, // big_block_elements - cycles_per_block * _cycle_elements, // normal_block_elements - _num_elements - (total_cycles * _cycle_elements), // extra_elements_last_block - _num_elements}; // num_elements - - _work_decomposition = work_decomposition; - - int spine_cycles = ((_grid_size * (1 << max_radix_bits)) + B40C_RADIXSORT_SPINE_CYCLE_ELEMENTS - 1) / B40C_RADIXSORT_SPINE_CYCLE_ELEMENTS; - _spine_elements = spine_cycles * B40C_RADIXSORT_SPINE_CYCLE_ELEMENTS; -} - - - -template -int BaseRadixSortingEnactor::GridSize(int max_grid_size) -{ - const int SINGLE_CTA_CUTOFF = 0; // right now zero; we have no single-cta sorting - - // find maximum number of threadblocks if "use-default" - if (max_grid_size == 0) { - - if (_num_elements <= static_cast(SINGLE_CTA_CUTOFF)) { - - // The problem size is too small to warrant a two-level reduction: - // use only one stream-processor - max_grid_size = 1; - - } else { - - if (_device_sm_version <= 120) { - - // G80/G90 - max_grid_size = _device_props.multiProcessorCount * 4; - - } else if (_device_sm_version < 200) { - - // GT200 (has some kind of TLB or icache drama) - int orig_max_grid_size = _device_props.multiProcessorCount * B40C_RADIXSORT_SCAN_SCATTER_CTA_OCCUPANCY(_kernel_ptx_version); - if (_keys_only) { - orig_max_grid_size *= (_num_elements + (1024 * 1024 * 96) - 1) / (1024 * 1024 * 96); - } else { - orig_max_grid_size *= (_num_elements + (1024 * 1024 * 64) - 1) / (1024 * 1024 * 64); - } - max_grid_size = orig_max_grid_size; - - if (_num_elements / _cycle_elements > static_cast(max_grid_size)) { - - double multiplier1 = 4.0; - double multiplier2 = 16.0; - - double delta1 = 0.068; - double delta2 = 0.127; - - int dividend = (_num_elements + _cycle_elements - 1) / _cycle_elements; - - while(true) { - - double quotient = ((double) dividend) / (multiplier1 * max_grid_size); - quotient -= (int) quotient; - - if ((quotient > delta1) && (quotient < 1 - delta1)) { - - quotient = ((double) dividend) / (multiplier2 * max_grid_size / 3.0); - quotient -= (int) quotient; - - if ((quotient > delta2) && (quotient < 1 - delta2)) { - break; - } - } - - if (max_grid_size == orig_max_grid_size - 2) { - max_grid_size = orig_max_grid_size - 30; - } else { - max_grid_size -= 1; - } - } - } - } else { - - // GF100 - max_grid_size = 418; - } - } - } - - // Calculate the actual number of threadblocks to launch. Initially - // assume that each threadblock will do only one cycle_elements worth - // of work, but then clamp it by the "max" restriction derived above - // in order to accomodate the "single-sp" and "saturated" cases. - - int grid_size = _num_elements / _cycle_elements; - if (grid_size == 0) { - grid_size = 1; - } - if (grid_size > max_grid_size) { - grid_size = max_grid_size; - } - - return grid_size; -} - - - -template -bool BaseRadixSortingEnactor:: -CanFit() -{ - long long bytes = (_num_elements * sizeof(K) * 2) + (_spine_elements * sizeof(int)); - if (!_keys_only) bytes += _num_elements * sizeof(V) * 2; - - if (_device_props.totalGlobalMem < 1024 * 1024 * 513) { - return (bytes < ((double) _device_props.totalGlobalMem) * 0.81); // allow up to 81% capacity for 512MB - } - - return (bytes < ((double) _device_props.totalGlobalMem) * 0.89); // allow up to 90% capacity -} - - - -template -template -cudaError_t BaseRadixSortingEnactor:: -DigitPlacePass(const RadixSortStorage &converted_storage) -{ - int threads = B40C_RADIXSORT_THREADS; - int dynamic_smem; - - cudaFuncAttributes reduce_kernel_attrs, scan_scatter_attrs; - cudaFuncGetAttributes(&reduce_kernel_attrs, RakingReduction); - cudaFuncGetAttributes(&scan_scatter_attrs, ScanScatterDigits); - - // - // Counting Reduction - // - - // Run tesla flush kernel if we have two or more threadblocks for each of the SMs - if ((_device_sm_version == 130) && (_work_decomposition.num_elements > static_cast(_device_props.multiProcessorCount * _cycle_elements * 2))) { - FlushKernel<<<_grid_size, B40C_RADIXSORT_THREADS, scan_scatter_attrs.sharedSizeBytes>>>(); - synchronize_if_enabled("FlushKernel"); - } - - // GF100 and GT200 get the same smem allocation for every kernel launch (pad the reduction/top-level-scan kernels) - dynamic_smem = (_kernel_ptx_version >= 130) ? scan_scatter_attrs.sharedSizeBytes - reduce_kernel_attrs.sharedSizeBytes : 0; - - RakingReduction <<<_grid_size, threads, dynamic_smem>>>( - converted_storage.d_from_alt_storage, - converted_storage.d_spine, - converted_storage.d_keys, - converted_storage.d_alt_keys, - _work_decomposition); - synchronize_if_enabled("RakingReduction"); - - - // - // Spine - // - - // GF100 and GT200 get the same smem allocation for every kernel launch (pad the reduction/top-level-scan kernels) - dynamic_smem = (_kernel_ptx_version >= 130) ? scan_scatter_attrs.sharedSizeBytes - _spine_scan_kernel_attrs.sharedSizeBytes : 0; - - SrtsScanSpine<<<_grid_size, B40C_RADIXSORT_SPINE_THREADS, dynamic_smem>>>( - converted_storage.d_spine, - converted_storage.d_spine, - _spine_elements); - synchronize_if_enabled("SrtsScanSpine"); - - - // - // Scanning Scatter - // - - // Run tesla flush kernel if we have two or more threadblocks for each of the SMs - if ((_device_sm_version == 130) && (_work_decomposition.num_elements > static_cast(_device_props.multiProcessorCount * _cycle_elements * 2))) { - FlushKernel<<<_grid_size, B40C_RADIXSORT_THREADS, scan_scatter_attrs.sharedSizeBytes>>>(); - synchronize_if_enabled("FlushKernel"); - } - - ScanScatterDigits <<<_grid_size, threads, 0>>>( - converted_storage.d_from_alt_storage, - converted_storage.d_spine, - converted_storage.d_keys, - converted_storage.d_alt_keys, - converted_storage.d_values, - converted_storage.d_alt_values, - _work_decomposition); - synchronize_if_enabled("ScanScatterDigits"); - - return cudaSuccess; -} - - - -template -cudaError_t BaseRadixSortingEnactor:: -EnactSort(RadixSortStorage &problem_storage) -{ - // - // Allocate device memory for temporary storage (if necessary) - // - - if (problem_storage.d_alt_keys == NULL) { - cudaMalloc((void**) &problem_storage.d_alt_keys, _num_elements * sizeof(K)); - } - if (!_keys_only && (problem_storage.d_alt_values == NULL)) { - cudaMalloc((void**) &problem_storage.d_alt_values, _num_elements * sizeof(V)); - } - if (problem_storage.d_spine == NULL) { - cudaMalloc((void**) &problem_storage.d_spine, _spine_elements * sizeof(int)); - } - if (problem_storage.d_from_alt_storage == NULL) { - cudaMalloc((void**) &problem_storage.d_from_alt_storage, 2 * sizeof(bool)); - } - - // Determine suitable type of unsigned byte storage to use for keys - typedef typename KeyConversion::UnsignedBits ConvertedKeyType; - - // Copy storage pointers to an appropriately typed stucture - RadixSortStorage converted_storage; - memcpy(&converted_storage, &problem_storage, sizeof(RadixSortStorage)); - - // - // Enact the sorting operation - // - - if (RADIXSORT_DEBUG) { - - printf("_device_sm_version: %d, _kernel_ptx_version: %d\n", _device_sm_version, _kernel_ptx_version); - printf("Bottom-level reduction & scan kernels:\n\tgrid_size: %d, \n\tthreads: %d, \n\tcycle_elements: %d, \n\tnum_big_blocks: %d, \n\tbig_block_elements: %d, \n\tnormal_block_elements: %d\n\textra_elements_last_block: %d\n\n", - _grid_size, B40C_RADIXSORT_THREADS, _cycle_elements, _work_decomposition.num_big_blocks, _work_decomposition.big_block_elements, _work_decomposition.normal_block_elements, _work_decomposition.extra_elements_last_block); - printf("Top-level spine scan:\n\tgrid_size: %d, \n\tthreads: %d, \n\tspine_block_elements: %d\n\n", - _grid_size, B40C_RADIXSORT_SPINE_THREADS, _spine_elements); - } - - cudaError_t retval = EnactDigitPlacePasses(converted_storage); - - - // - // Swizzle pointers if we left our sorted output in temp storage - // - - if (_swizzle_pointers_for_odd_passes) { - - cudaMemcpy( - &problem_storage.using_alternate_storage, - &problem_storage.d_from_alt_storage[_passes & 0x1], - sizeof(bool), - cudaMemcpyDeviceToHost); - - if (problem_storage.using_alternate_storage) { - thrust::swap(problem_storage.d_keys, problem_storage.d_alt_keys); - if (!_keys_only) { - thrust::swap(problem_storage.d_values, problem_storage.d_alt_values); - } - } - } - - return retval; -} - - - - - -/****************************************************************************** - * Sorting enactor classes - ******************************************************************************/ - -/** - * Generic sorting enactor class. Simply create an instance of this class - * with your key-type K (and optionally value-type V if sorting with satellite - * values). - * - * Template specialization provides the appropriate enactor instance to handle - * the specified data types. - * - * @template-param K - * Type of keys to be sorted - * - * @template-param V - * Type of values to be sorted. - * - * @template-param ConvertedKeyType - * Leave as default to effect necessary enactor specialization. - */ -template ::UnsignedBits> -class RadixSortingEnactor; - - - -/** - * Sorting enactor that is specialized for for 8-bit key types - */ -template -class RadixSortingEnactor : public BaseRadixSortingEnactor -{ -protected: - - typedef BaseRadixSortingEnactor Base; - typedef typename Base::ConvertedKeyType ConvertedKeyType; - - cudaError_t EnactDigitPlacePasses(const RadixSortStorage &converted_storage) - { - Base::template DigitPlacePass<0, 4, 0, PreprocessKeyFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<1, 4, 4, NopFunctor, PostprocessKeyFunctor > (converted_storage); - - return cudaSuccess; - } - -public: - - /** - * Constructor. - * - * @param[in] num_elements - * Length (in elements) of the input to a sorting operation - * - * @param[in] max_grid_size - * Maximum allowable number of CTAs to launch. The default value of 0 indicates - * that the dispatch logic should select an appropriate value for the target device. - */ - RadixSortingEnactor(unsigned int num_elements, int max_grid_size = 0) : Base::BaseRadixSortingEnactor(2, 4, num_elements, max_grid_size) {} - -}; - - - -/** - * Sorting enactor that is specialized for for 16-bit key types - */ -template -class RadixSortingEnactor : public BaseRadixSortingEnactor -{ -protected: - - typedef BaseRadixSortingEnactor Base; - typedef typename Base::ConvertedKeyType ConvertedKeyType; - - cudaError_t EnactDigitPlacePasses(const RadixSortStorage &converted_storage) - { - Base::template DigitPlacePass<0, 4, 0, PreprocessKeyFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<1, 4, 4, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<2, 4, 8, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<3, 4, 12, NopFunctor, PostprocessKeyFunctor > (converted_storage); - - return cudaSuccess; - } - -public: - - /** - * Constructor. - * - * @param[in] num_elements - * Length (in elements) of the input to a sorting operation - * - * @param[in] max_grid_size - * Maximum allowable number of CTAs to launch. The default value of 0 indicates - * that the dispatch logic should select an appropriate value for the target device. - */ - RadixSortingEnactor(unsigned int num_elements, int max_grid_size = 0) : Base::BaseRadixSortingEnactor(4, 4, num_elements, max_grid_size) {} - -}; - - -/** - * Sorting enactor that is specialized for for 32-bit key types - */ -template -class RadixSortingEnactor : public BaseRadixSortingEnactor -{ -protected: - - typedef BaseRadixSortingEnactor Base; - typedef typename Base::ConvertedKeyType ConvertedKeyType; - - cudaError_t EnactDigitPlacePasses(const RadixSortStorage &converted_storage) - { - Base::template DigitPlacePass<0, 4, 0, PreprocessKeyFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<1, 4, 4, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<2, 4, 8, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<3, 4, 12, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<4, 4, 16, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<5, 4, 20, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<6, 4, 24, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<7, 4, 28, NopFunctor, PostprocessKeyFunctor > (converted_storage); - - return cudaSuccess; - } - -public: - - /** - * Constructor. - * - * @param[in] num_elements - * Length (in elements) of the input to a sorting operation - * - * @param[in] max_grid_size - * Maximum allowable number of CTAs to launch. The default value of 0 indicates - * that the dispatch logic should select an appropriate value for the target device. - */ - RadixSortingEnactor(unsigned int num_elements, int max_grid_size = 0) : Base::BaseRadixSortingEnactor(8, 4, num_elements, max_grid_size) {} - -}; - - - -/** - * Sorting enactor that is specialized for for 64-bit key types - */ -template -class RadixSortingEnactor : public BaseRadixSortingEnactor -{ -protected: - - typedef BaseRadixSortingEnactor Base; - typedef typename Base::ConvertedKeyType ConvertedKeyType; - - cudaError_t EnactDigitPlacePasses(const RadixSortStorage &converted_storage) - { - Base::template DigitPlacePass<0, 4, 0, PreprocessKeyFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<1, 4, 4, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<2, 4, 8, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<3, 4, 12, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<4, 4, 16, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<5, 4, 20, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<6, 4, 24, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<7, 4, 28, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<8, 4, 32, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<9, 4, 36, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<10, 4, 40, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<11, 4, 44, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<12, 4, 48, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<13, 4, 52, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<14, 4, 56, NopFunctor, NopFunctor >(converted_storage); - Base::template DigitPlacePass<15, 4, 60, NopFunctor, PostprocessKeyFunctor > (converted_storage); - - return cudaSuccess; - } - -public: - - /** - * Constructor. - * - * @param[in] num_elements - * Length (in elements) of the input to a sorting operation - * - * @param[in] max_grid_size - * Maximum allowable number of CTAs to launch. The default value of 0 indicates - * that the dispatch logic should select an appropriate value for the target device. - */ - RadixSortingEnactor(unsigned int num_elements, int max_grid_size = 0) : Base::BaseRadixSortingEnactor(16, 4, num_elements, max_grid_size) {} - -}; - - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_kernel_common.h b/compat/thrust/system/cuda/detail/detail/b40c/radixsort_kernel_common.h deleted file mode 100644 index 7899dc3..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_kernel_common.h +++ /dev/null @@ -1,173 +0,0 @@ -/****************************************************************************** - * - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * - * - * AUTHORS' REQUEST: - * - * If you use|reference|benchmark this code, please cite our Technical - * Report (http://www.cs.virginia.edu/~dgm4d/papers/RadixSortTR.pdf): - * - * @TechReport{ Merrill:Sorting:2010, - * author = "Duane Merrill and Andrew Grimshaw", - * title = "Revisiting Sorting for GPGPU Stream Architectures", - * year = "2010", - * institution = "University of Virginia, Department of Computer Science", - * address = "Charlottesville, VA, USA", - * number = "CS2010-03" - * } - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - * - ******************************************************************************/ - - -/****************************************************************************** - * Configuration management for B40C radix sorting kernels - ******************************************************************************/ - -#pragma once - -#include "kernel_utils.h" -#include "vector_types.h" -#include "radixsort_key_conversion.h" - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - - -/****************************************************************************** - * Radix sorting configuration - ******************************************************************************/ - -// 128 threads -#define B40C_RADIXSORT_LOG_THREADS 7 -#define B40C_RADIXSORT_THREADS (1 << B40C_RADIXSORT_LOG_THREADS) - -// Target threadblock occupancy for counting/reduction kernel -#define B40C_SM20_REDUCE_CTA_OCCUPANCY() (8) // 8 threadblocks on GF100 -#define B40C_SM12_REDUCE_CTA_OCCUPANCY() (5) // 5 threadblocks on GT200 -#define B40C_SM10_REDUCE_CTA_OCCUPANCY() (3) // 4 threadblocks on G80 -#define B40C_RADIXSORT_REDUCE_CTA_OCCUPANCY(version) ((version >= 200) ? B40C_SM20_REDUCE_CTA_OCCUPANCY() : \ - (version >= 120) ? B40C_SM12_REDUCE_CTA_OCCUPANCY() : \ - B40C_SM10_REDUCE_CTA_OCCUPANCY()) - -// Target threadblock occupancy for bulk scan/scatter kernel -#define B40C_SM20_SCAN_SCATTER_CTA_OCCUPANCY() (7) // 7 threadblocks on GF100 -#define B40C_SM12_SCAN_SCATTER_CTA_OCCUPANCY() (5) // 5 threadblocks on GT200 -#define B40C_SM10_SCAN_SCATTER_CTA_OCCUPANCY() (2) // 2 threadblocks on G80 -#define B40C_RADIXSORT_SCAN_SCATTER_CTA_OCCUPANCY(version) ((version >= 200) ? B40C_SM20_SCAN_SCATTER_CTA_OCCUPANCY() : \ - (version >= 120) ? B40C_SM12_SCAN_SCATTER_CTA_OCCUPANCY() : \ - B40C_SM10_SCAN_SCATTER_CTA_OCCUPANCY()) - -// Number of 256-element sets to rake per raking pass -#define B40C_SM20_LOG_SETS_PER_PASS() (1) // 2 sets on GF100 -#define B40C_SM12_LOG_SETS_PER_PASS() (0) // 1 set on GT200 -#define B40C_SM10_LOG_SETS_PER_PASS() (1) // 2 sets on G80 -#define B40C_RADIXSORT_LOG_SETS_PER_PASS(version) ((version >= 200) ? B40C_SM20_LOG_SETS_PER_PASS() : \ - (version >= 120) ? B40C_SM12_LOG_SETS_PER_PASS() : \ - B40C_SM10_LOG_SETS_PER_PASS()) - -// Number of raking passes per cycle -#define B40C_SM20_LOG_PASSES_PER_CYCLE(K, V) (((B40C_MAX(sizeof(K), sizeof(V)) > 4) || _B40C_LP64_) ? 0 : 1) // 2 passes on GF100 (only one for large keys/values, or for 64-bit device pointers) -#define B40C_SM12_LOG_PASSES_PER_CYCLE(K, V) (B40C_MAX(sizeof(K), sizeof(V)) > 4 ? 0 : 1) // 2 passes on GT200 (only for large keys/values) -#define B40C_SM10_LOG_PASSES_PER_CYCLE(K, V) (0) // 1 pass on G80 -#define B40C_RADIXSORT_LOG_PASSES_PER_CYCLE(version, K, V) ((version >= 200) ? B40C_SM20_LOG_PASSES_PER_CYCLE(K, V) : \ - (version >= 120) ? B40C_SM12_LOG_PASSES_PER_CYCLE(K, V) : \ - B40C_SM10_LOG_PASSES_PER_CYCLE(K, V)) - - -// Number of raking threads per raking pass -#define B40C_SM20_LOG_RAKING_THREADS_PER_PASS() (B40C_LOG_WARP_THREADS + 1) // 2 raking warps on GF100 -#define B40C_SM12_LOG_RAKING_THREADS_PER_PASS() (B40C_LOG_WARP_THREADS) // 1 raking warp on GT200 -#define B40C_SM10_LOG_RAKING_THREADS_PER_PASS() (B40C_LOG_WARP_THREADS + 2) // 4 raking warps on G80 -#define B40C_RADIXSORT_LOG_RAKING_THREADS_PER_PASS(version) ((version >= 200) ? B40C_SM20_LOG_RAKING_THREADS_PER_PASS() : \ - (version >= 120) ? B40C_SM12_LOG_RAKING_THREADS_PER_PASS() : \ - B40C_SM10_LOG_RAKING_THREADS_PER_PASS()) - - -// Number of elements per cycle -#define B40C_RADIXSORT_LOG_CYCLE_ELEMENTS(version, K, V) (B40C_RADIXSORT_LOG_SETS_PER_PASS(version) + B40C_RADIXSORT_LOG_PASSES_PER_CYCLE(version, K, V) + B40C_RADIXSORT_LOG_THREADS + 1) -#define B40C_RADIXSORT_CYCLE_ELEMENTS(version, K, V) (1 << B40C_RADIXSORT_LOG_CYCLE_ELEMENTS(version, K, V)) - -// Number of warps per CTA -#define B40C_RADIXSORT_LOG_WARPS (B40C_RADIXSORT_LOG_THREADS - B40C_LOG_WARP_THREADS) -#define B40C_RADIXSORT_WARPS (1 << B40C_RADIXSORT_LOG_WARPS) - -// Number of threads for spine-scanning kernel -#define B40C_RADIXSORT_LOG_SPINE_THREADS 7 // 128 threads -#define B40C_RADIXSORT_SPINE_THREADS (1 << B40C_RADIXSORT_LOG_SPINE_THREADS) - -// Number of elements per spine-scanning cycle -#define B40C_RADIXSORT_LOG_SPINE_CYCLE_ELEMENTS 9 // 512 elements -#define B40C_RADIXSORT_SPINE_CYCLE_ELEMENTS (1 << B40C_RADIXSORT_LOG_SPINE_CYCLE_ELEMENTS) - - - -/****************************************************************************** - * SRTS Control Structures - ******************************************************************************/ - - -/** - * Value-type structure denoting keys-only sorting - */ -struct KeysOnlyType {}; - -/** - * Returns whether or not the templated type indicates keys-only sorting - */ -template -inline __host__ __device__ bool IsKeysOnly() {return false;} - - -/** - * Returns whether or not the templated type indicates keys-only sorting - */ -template <> -inline __host__ __device__ bool IsKeysOnly() {return true;} - - -/** - * A given threadblock may receive one of three different amounts of - * work: "big", "normal", and "last". The big workloads are one - * cycle_elements greater than the normal, and the last workload - * does the extra (problem-size % cycle_elements) work. - */ -struct CtaDecomposition { - unsigned int num_big_blocks; - unsigned int big_block_elements; - unsigned int normal_block_elements; - unsigned int extra_elements_last_block; - unsigned int num_elements; -}; - - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_key_conversion.h b/compat/thrust/system/cuda/detail/detail/b40c/radixsort_key_conversion.h deleted file mode 100644 index a170f95..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_key_conversion.h +++ /dev/null @@ -1,352 +0,0 @@ -/****************************************************************************** - * - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * - * - * AUTHORS' REQUEST: - * - * If you use|reference|benchmark this code, please cite our Technical - * Report (http://www.cs.virginia.edu/~dgm4d/papers/RadixSortTR.pdf): - * - * @TechReport{ Merrill:Sorting:2010, - * author = "Duane Merrill and Andrew Grimshaw", - * title = "Revisiting Sorting for GPGPU Stream Architectures", - * year = "2010", - * institution = "University of Virginia, Department of Computer Science", - * address = "Charlottesville, VA, USA", - * number = "CS2010-03" - * } - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - * - ******************************************************************************/ - - -/****************************************************************************** - * Functors for converting signed and floating point types to unsigned types - * suitable for radix sorting - ******************************************************************************/ - -#pragma once - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - - -// -// Do-nothing functors -// - -template -struct NopFunctor{ - template - __device__ __host__ __forceinline__ void operator()(ConvertedKeyType &converted_key) {} - __device__ __host__ __forceinline__ static bool MustApply(){ return false;} -}; - -// -// Do-nothing functors that indicate a mandatory pass -// - -template -struct MandatoryPassNopFunctor{ - template - __device__ __host__ __forceinline__ void operator()(ConvertedKeyType &converted_key) {} - __device__ __host__ __forceinline__ static bool MustApply(){ return false;} -}; - - -// -// Conversion for generic unsigned types -// - -template struct KeyConversion { - typedef T UnsignedBits; -}; - -template -struct PreprocessKeyFunctor{ - template - __device__ __host__ __forceinline__ void operator()(ConvertedKeyType &converted_key) {} - __device__ __host__ __forceinline__ static bool MustApply(){ return false;} -}; - -template -struct PostprocessKeyFunctor { - template - __device__ __host__ __forceinline__ void operator()(ConvertedKeyType &converted_key) {} - __device__ __host__ __forceinline__ static bool MustApply(){ return false;} -}; - - - -// -// Conversion for floats -// - -template <> struct KeyConversion { - typedef unsigned int UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned int &converted_key) { - - unsigned int mask = (converted_key & 0x80000000) ? 0xffffffff : 0x80000000; - converted_key ^= mask; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned int &converted_key) { - - unsigned int mask = (converted_key & 0x80000000) ? 0x80000000 : 0xffffffff; - converted_key ^= mask; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - - -// -// Conversion for doubles -// - -template <> struct KeyConversion { - typedef unsigned long long UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned long long &converted_key) { - - unsigned long long mask = (converted_key & 0x8000000000000000) ? 0xffffffffffffffff : 0x8000000000000000; - converted_key ^= mask; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned long long &converted_key) { - unsigned long long mask = (converted_key & 0x8000000000000000) ? 0x8000000000000000 : 0xffffffffffffffff; - converted_key ^= mask; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - -// -// Conversion for signed chars -// - -template <> struct KeyConversion { - typedef unsigned char UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) { - // char is unsigned on some platforms, so we have to check - if(std::numeric_limits::is_signed) - { - const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1); - converted_key ^= SIGN_MASK; - } - } - __device__ __host__ __forceinline__ static bool MustApply(){ return std::numeric_limits::is_signed;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) { - // char is unsigned on some platforms, so we have to check - if(std::numeric_limits::is_signed) - { - const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1); - converted_key ^= SIGN_MASK; - } - } - __device__ __host__ __forceinline__ static bool MustApply(){ return std::numeric_limits::is_signed;} -}; - - -// TODO handle this more gracefully -template <> struct KeyConversion { - typedef unsigned char UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) { - const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) { - const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - -// -// Conversion for signed shorts -// - -template <> struct KeyConversion { - typedef unsigned short UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned short &converted_key) { - const unsigned int SIGN_MASK = 1u << ((sizeof(short) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned short &converted_key) { - const unsigned int SIGN_MASK = 1u << ((sizeof(short) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - - -// -// Conversion for signed ints -// - -template <> struct KeyConversion { - typedef unsigned int UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned int &converted_key) { - const unsigned int SIGN_MASK = 1u << ((sizeof(int) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned int &converted_key) { - const unsigned int SIGN_MASK = 1u << ((sizeof(int) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - - -// -// Conversion for signed longs -// - -// TODO rework this with metaprogramming -template <> struct KeyConversion { -#if ULONG_MAX == UINT_MAX - typedef unsigned int UnsignedBits; -#else - typedef unsigned long long UnsignedBits; -#endif -}; - -// TODO rework this with metaprogramming -template <> struct KeyConversion { -#if ULONG_MAX == UINT_MAX - typedef unsigned int UnsignedBits; -#else - typedef unsigned long long UnsignedBits; -#endif -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(typename KeyConversion::UnsignedBits& converted_key) { - const typename KeyConversion::UnsignedBits SIGN_MASK = 1ul << ((sizeof(long) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(typename KeyConversion::UnsignedBits& converted_key) { - const typename KeyConversion::UnsignedBits SIGN_MASK = 1ul << ((sizeof(long) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - - -// -// Conversion for signed long longs -// - -template <> struct KeyConversion { - typedef unsigned long long UnsignedBits; -}; - -template <> -struct PreprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned long long &converted_key) { - const unsigned long long SIGN_MASK = 1ull << ((sizeof(long long) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - -template <> -struct PostprocessKeyFunctor { - __device__ __host__ __forceinline__ void operator()(unsigned long long &converted_key) { - const unsigned long long SIGN_MASK = 1ull << ((sizeof(long long) * 8) - 1); - converted_key ^= SIGN_MASK; - } - __device__ __host__ __forceinline__ static bool MustApply(){ return true;} -}; - - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_reduction_kernel.h b/compat/thrust/system/cuda/detail/detail/b40c/radixsort_reduction_kernel.h deleted file mode 100644 index a8f91d3..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_reduction_kernel.h +++ /dev/null @@ -1,439 +0,0 @@ -/****************************************************************************** - * - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * - * - * AUTHORS' REQUEST: - * - * If you use|reference|benchmark this code, please cite our Technical - * Report (http://www.cs.virginia.edu/~dgm4d/papers/RadixSortTR.pdf): - * - * @TechReport{ Merrill:Sorting:2010, - * author = "Duane Merrill and Andrew Grimshaw", - * title = "Revisiting Sorting for GPGPU Stream Architectures", - * year = "2010", - * institution = "University of Virginia, Department of Computer Science", - * address = "Charlottesville, VA, USA", - * number = "CS2010-03" - * } - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - * - ******************************************************************************/ - - -/****************************************************************************** - * Bottom-level digit-reduction/counting kernel - ******************************************************************************/ - -#pragma once - -#include "radixsort_kernel_common.h" - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - -/****************************************************************************** - * Defines - ******************************************************************************/ - -const int BYTE_ENCODE_SHIFT = 0x3; - - -/****************************************************************************** - * Cycle-processing Routines - ******************************************************************************/ - -__device__ __forceinline__ int DecodeInt(int encoded, int quad_byte){ - return (encoded >> quad_byte) & 0xff; // shift right 8 bits per digit and return rightmost 8 bits -} - - -__device__ __forceinline__ int EncodeInt(int count, int quad_byte) { - return count << quad_byte; // shift left 8 bits per digit -} - - -template -__device__ __forceinline__ void DecodeDigit( - K key, - int &lane, - int &quad_shift) -{ - const K DIGIT_MASK = RADIX_DIGITS - 1; - lane = (key & (DIGIT_MASK << BIT)) >> (BIT + 2); - - const K QUAD_MASK = (RADIX_DIGITS < 4) ? 0x1 : 0x3; - if (BIT == 32) { - // N.B.: This takes one more instruction than the code below it, but - // otherwise the compiler goes nuts and shoves hundreds of bytes - // to lmem when bit = 32 on 64-bit keys. - quad_shift = ((key >> BIT) & QUAD_MASK) << BYTE_ENCODE_SHIFT; - } else { - quad_shift = MagnitudeShift(key & (QUAD_MASK << BIT)); - } -} - - -template -__device__ __forceinline__ void ReduceEncodedCounts( - int local_counts[LANES_PER_WARP][4], - int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) -{ - const int LOG_PARTIALS_PER_THREAD = B40C_RADIXSORT_LOG_THREADS - B40C_LOG_WARP_THREADS; - const int PARTIALS_PER_THREAD = 1 << LOG_PARTIALS_PER_THREAD; - - int encoded; - int idx = threadIdx.x & (B40C_WARP_THREADS - 1); - - - __syncthreads(); - - #pragma unroll - for (int j = 0; j < (int) LANES_PER_WARP; j++) { - - int warp_id = (threadIdx.x >> B40C_LOG_WARP_THREADS) + (j * B40C_RADIXSORT_WARPS); - if (warp_id < SCAN_LANES) { - - // rest of my elements - #pragma unroll - for (int i = 0; i < (int) PARTIALS_PER_THREAD; i++) { - encoded = encoded_carry[warp_id][idx + (i * B40C_WARP_THREADS)]; - local_counts[j][0] += DecodeInt(encoded, 0u << BYTE_ENCODE_SHIFT); - local_counts[j][1] += DecodeInt(encoded, 1u << BYTE_ENCODE_SHIFT); - local_counts[j][2] += DecodeInt(encoded, 2u << BYTE_ENCODE_SHIFT); - local_counts[j][3] += DecodeInt(encoded, 3u << BYTE_ENCODE_SHIFT); - } - - if (FINAL_REDUCE) { - // reduce all four packed fields, leaving them in the first four elements of our row - WarpReduce(idx, &encoded_carry[warp_id][0], local_counts[j][0]); - WarpReduce(idx, &encoded_carry[warp_id][1], local_counts[j][1]); - WarpReduce(idx, &encoded_carry[warp_id][2], local_counts[j][2]); - WarpReduce(idx, &encoded_carry[warp_id][3], local_counts[j][3]); - } - } - } - - __syncthreads(); - -} - - -template -__device__ __forceinline__ void Bucket( - K input, - int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS], - PreprocessFunctor preprocess = PreprocessFunctor()) -{ - int lane, quad_shift; - preprocess(input); - DecodeDigit(input, lane, quad_shift); - encoded_carry[lane][threadIdx.x] += EncodeInt(1, quad_shift); -} - - -template -struct LoadOp; - -template -struct LoadOp -{ - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - K key = d_in_keys[offset + threadIdx.x]; - Bucket(key, encoded_carry); - } -}; - -template -struct LoadOp -{ - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 1), encoded_carry); - } -}; - -template -struct LoadOp -{ - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 2), encoded_carry); - } -}; - -template -struct LoadOp -{ - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - K keys[8]; - - keys[0] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 0) + threadIdx.x]; - keys[1] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 1) + threadIdx.x]; - keys[2] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 2) + threadIdx.x]; - keys[3] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 3) + threadIdx.x]; - - if (B40C_FERMI(__CUDA_ARCH__)) __syncthreads(); - - keys[4] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 4) + threadIdx.x]; - keys[5] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 5) + threadIdx.x]; - keys[6] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 6) + threadIdx.x]; - keys[7] = d_in_keys[offset + (B40C_RADIXSORT_THREADS * 7) + threadIdx.x]; - - Bucket(keys[0], encoded_carry); - Bucket(keys[1], encoded_carry); - Bucket(keys[2], encoded_carry); - Bucket(keys[3], encoded_carry); - Bucket(keys[4], encoded_carry); - Bucket(keys[5], encoded_carry); - Bucket(keys[6], encoded_carry); - Bucket(keys[7], encoded_carry); - } -}; - -template -struct LoadOp { - - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 8), encoded_carry); - } -}; - -template -struct LoadOp { - - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 16), encoded_carry); - } -}; - -template -struct LoadOp { - - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 32), encoded_carry); - } -}; - -template -struct LoadOp { - - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 64), encoded_carry); - } -}; - -template -struct LoadOp { - - static __device__ __forceinline__ void BlockOfLoads(K *d_in_keys, int offset, int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) - { - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 0), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 128), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 192), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 224), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 240), encoded_carry); - LoadOp::BlockOfLoads(d_in_keys, offset + (B40C_RADIXSORT_THREADS * 248), encoded_carry); - } -}; - - -template -__device__ __forceinline__ void ResetEncodedCarry( - int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]) -{ - #pragma unroll - for (int SCAN_LANE = 0; SCAN_LANE < (int) SCAN_LANES; SCAN_LANE++) { - encoded_carry[SCAN_LANE][threadIdx.x] = 0; - } -} - - -template -__device__ __forceinline__ int ProcessLoads( - K *d_in_keys, - int loads, - int &offset, - int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS], - int local_counts[LANES_PER_WARP][4]) -{ - // Unroll batches of loads with occasional reduction to avoid overflow - while (loads >= 32) { - - LoadOp::BlockOfLoads(d_in_keys, offset, encoded_carry); - offset += B40C_RADIXSORT_THREADS * 32; - loads -= 32; - - // Reduce int local count registers to prevent overflow - ReduceEncodedCounts( - local_counts, - encoded_carry); - - // Reset encoded counters - ResetEncodedCarry(encoded_carry); - } - - int retval = loads; - - // Wind down loads in decreasing batch sizes - - while (loads >= 4) { - LoadOp::BlockOfLoads(d_in_keys, offset, encoded_carry); - offset += B40C_RADIXSORT_THREADS * 4; - loads -= 4; - } - - while (loads) { - LoadOp::BlockOfLoads(d_in_keys, offset, encoded_carry); - offset += B40C_RADIXSORT_THREADS * 1; - loads--; - } - - return retval; -} - - -/****************************************************************************** - * Reduction/counting Kernel Entry Point - ******************************************************************************/ - -template -__launch_bounds__ (B40C_RADIXSORT_THREADS, B40C_RADIXSORT_REDUCE_CTA_OCCUPANCY(__CUDA_ARCH__)) -__global__ -void RakingReduction( - bool *d_from_alt_storage, - int *d_spine, - K *d_in_keys, - K *d_out_keys, - CtaDecomposition work_decomposition) -{ - const int RADIX_DIGITS = 1 << RADIX_BITS; - - const int LOG_SCAN_LANES = (RADIX_BITS >= 2) ? RADIX_BITS - 2 : 0; // Always at least one fours group - const int SCAN_LANES = 1 << LOG_SCAN_LANES; - - const int LOG_LANES_PER_WARP = (SCAN_LANES > B40C_RADIXSORT_WARPS) ? LOG_SCAN_LANES - B40C_RADIXSORT_LOG_WARPS : 0; // Always at least one fours group per warp - const int LANES_PER_WARP = 1 << LOG_LANES_PER_WARP; - - - // Each thread gets its own column of fours-groups (for conflict-free updates) - __shared__ int encoded_carry[SCAN_LANES][B40C_RADIXSORT_THREADS]; - - // Each thread is also responsible for aggregating an unencoded segment of a fours-group - int local_counts[LANES_PER_WARP][4]; - - // Determine where to read our input - bool from_alt_storage = (PASS == 0) ? false : d_from_alt_storage[PASS & 0x1]; - if (from_alt_storage) d_in_keys = d_out_keys; - - // Calculate our threadblock's range - int offset, block_elements; - if (blockIdx.x < work_decomposition.num_big_blocks) { - offset = work_decomposition.big_block_elements * blockIdx.x; - block_elements = work_decomposition.big_block_elements; - } else { - offset = (work_decomposition.normal_block_elements * blockIdx.x) + (work_decomposition.num_big_blocks * B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V)); - block_elements = work_decomposition.normal_block_elements; - } - - // Initialize local counts - #pragma unroll - for (int LANE = 0; LANE < (int) LANES_PER_WARP; LANE++) { - local_counts[LANE][0] = 0; - local_counts[LANE][1] = 0; - local_counts[LANE][2] = 0; - local_counts[LANE][3] = 0; - } - - // Reset encoded counters - ResetEncodedCarry(encoded_carry); - - // Process loads - int loads = block_elements >> B40C_RADIXSORT_LOG_THREADS; - int unreduced_loads = ProcessLoads( - d_in_keys, - loads, - offset, - encoded_carry, - local_counts); - - // Cleanup if we're the last block - if ((blockIdx.x == gridDim.x - 1) && (work_decomposition.extra_elements_last_block)) { - - const int LOADS_PER_CYCLE = B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V) / B40C_RADIXSORT_THREADS; - - // If extra guarded loads may cause overflow, reduce now and reset counters - if (unreduced_loads + LOADS_PER_CYCLE > 255) { - - ReduceEncodedCounts( - local_counts, - encoded_carry); - - ResetEncodedCarry(encoded_carry); - } - - // perform up to LOADS_PER_CYCLE extra guarded loads - #pragma unroll - for (int EXTRA_LOAD = 0; EXTRA_LOAD < (int) LOADS_PER_CYCLE; EXTRA_LOAD++) { - if (threadIdx.x + (B40C_RADIXSORT_THREADS * EXTRA_LOAD) < work_decomposition.extra_elements_last_block) { - K key = d_in_keys[offset + (B40C_RADIXSORT_THREADS * EXTRA_LOAD) + threadIdx.x]; - Bucket(key, encoded_carry); - } - } - } - - // Aggregate - ReduceEncodedCounts( - local_counts, - encoded_carry); - - // Write carry in parallel (carries per row are in the first four bytes of each row) - if (threadIdx.x < RADIX_DIGITS) { - - int row = threadIdx.x >> 2; - int col = threadIdx.x & 3; - d_spine[(gridDim.x * threadIdx.x) + blockIdx.x] = encoded_carry[row][col]; - } -} - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_scanscatter_kernel.h b/compat/thrust/system/cuda/detail/detail/b40c/radixsort_scanscatter_kernel.h deleted file mode 100644 index 1377999..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_scanscatter_kernel.h +++ /dev/null @@ -1,1207 +0,0 @@ -/****************************************************************************** - * - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * - * - * AUTHORS' REQUEST: - * - * If you use|reference|benchmark this code, please cite our Technical - * Report (http://www.cs.virginia.edu/~dgm4d/papers/RadixSortTR.pdf): - * - * @TechReport{ Merrill:Sorting:2010, - * author = "Duane Merrill and Andrew Grimshaw", - * title = "Revisiting Sorting for GPGPU Stream Architectures", - * year = "2010", - * institution = "University of Virginia, Department of Computer Science", - * address = "Charlottesville, VA, USA", - * number = "CS2010-03" - * } - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - * - ******************************************************************************/ - - -/****************************************************************************** -// Bottom-level digit scanning/scattering kernel - ******************************************************************************/ - -#pragma once - -#include "radixsort_kernel_common.h" - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - -/****************************************************************************** - * Appropriate substitutes to use for out-of-bounds key (and value) offsets - ******************************************************************************/ - -template -__device__ __forceinline__ T DefaultextraValue() { - return T(); -} - -template <> -__device__ __forceinline__ unsigned char DefaultextraValue() { - return (unsigned char) -1; -} - -template <> -__device__ __forceinline__ unsigned short DefaultextraValue() { - return (unsigned short) -1; -} - -template <> -__device__ __forceinline__ unsigned int DefaultextraValue() { - return (unsigned int) -1u; -} - -template <> -__device__ __forceinline__ unsigned long DefaultextraValue() { - return (unsigned long) -1ul; -} - -template <> -__device__ __forceinline__ unsigned long long DefaultextraValue() { - return (unsigned long long) -1ull; -} - - -/****************************************************************************** - * Cycle-processing Routines - ******************************************************************************/ - -template -__device__ __forceinline__ int DecodeDigit(K key) -{ - const K DIGIT_MASK = RADIX_DIGITS - 1; - return (key >> BIT) & DIGIT_MASK; -} - - -template -__device__ __forceinline__ void DecodeDigit( - K key, - int &digit, - int &flag_offset, // in bytes - const int SET_OFFSET) -{ - const int PADDED_BYTES_PER_LANE = PADDED_PARTIALS_PER_LANE * 4; - const int SET_OFFSET_BYTES = SET_OFFSET * 4; - const K QUAD_MASK = (RADIX_DIGITS < 4) ? 0x1 : 0x3; - - digit = DecodeDigit(key); - int lane = digit >> 2; - int quad_byte = digit & QUAD_MASK; - - flag_offset = SET_OFFSET_BYTES + FastMul(lane, PADDED_BYTES_PER_LANE) + quad_byte; -} - - -template -__device__ __forceinline__ void DecodeDigits( - typename VecType::Type keypairs[SETS_PER_PASS], - int2 digits[SETS_PER_PASS], - int2 flag_offsets[SETS_PER_PASS]) // in bytes -{ - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - - const int SET_OFFSET = SET * SCAN_LANES_PER_SET * PADDED_PARTIALS_PER_LANE; - - DecodeDigit( - keypairs[SET].x, digits[SET].x, flag_offsets[SET].x, SET_OFFSET); - - DecodeDigit( - keypairs[SET].y, digits[SET].y, flag_offsets[SET].y, SET_OFFSET); - } -} - - -template -__device__ __forceinline__ void GuardedReadSet( - T *in, - typename VecType::Type &pair, - int offset, - int extra[1], - PreprocessFunctor preprocess = PreprocessFunctor()) -{ - if (offset - extra[0] < 0) { - pair.x = in[offset]; - preprocess(pair.x); - } else { - pair.x = DefaultextraValue(); - } - - if (offset + 1 - extra[0] < 0) { - pair.y = in[offset + 1]; - preprocess(pair.y); - } else { - pair.y = DefaultextraValue(); - } -} - - -template -__device__ __forceinline__ void ReadSets( - typename VecType::Type *d_in, - typename VecType::Type pairs[SETS_PER_PASS], - const int BASE2, - int extra[1], - PreprocessFunctor preprocess = PreprocessFunctor()) -{ - if (UNGUARDED_IO) { - - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler makes it 1% slower - if (SETS_PER_PASS > 0) pairs[0] = d_in[threadIdx.x + BASE2 + (B40C_RADIXSORT_THREADS * 0)]; - if (SETS_PER_PASS > 1) pairs[1] = d_in[threadIdx.x + BASE2 + (B40C_RADIXSORT_THREADS * 1)]; - if (SETS_PER_PASS > 2) pairs[2] = d_in[threadIdx.x + BASE2 + (B40C_RADIXSORT_THREADS * 2)]; - if (SETS_PER_PASS > 3) pairs[3] = d_in[threadIdx.x + BASE2 + (B40C_RADIXSORT_THREADS * 3)]; - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - preprocess(pairs[SET].x); - preprocess(pairs[SET].y); - } - - } else { - - T* in = (T*) d_in; - - // N.B. -- I wish we could do some pragma unrolling here, but the compiler won't let - // us with user-defined value types (e.g., Fribbitz): "Advisory: Loop was not unrolled, cannot deduce loop trip count" - - if (SETS_PER_PASS > 0) GuardedReadSet(in, pairs[0], (threadIdx.x << 1) + (BASE2 << 1) + (B40C_RADIXSORT_THREADS * 2 * 0), extra); - if (SETS_PER_PASS > 1) GuardedReadSet(in, pairs[1], (threadIdx.x << 1) + (BASE2 << 1) + (B40C_RADIXSORT_THREADS * 2 * 1), extra); - if (SETS_PER_PASS > 2) GuardedReadSet(in, pairs[2], (threadIdx.x << 1) + (BASE2 << 1) + (B40C_RADIXSORT_THREADS * 2 * 2), extra); - if (SETS_PER_PASS > 3) GuardedReadSet(in, pairs[3], (threadIdx.x << 1) + (BASE2 << 1) + (B40C_RADIXSORT_THREADS * 2 * 3), extra); - } -} - - -template -__device__ __forceinline__ void PlacePartials( - unsigned char * base_partial, - int2 digits[SETS_PER_PASS], - int2 flag_offsets[SETS_PER_PASS]) -{ - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - base_partial[flag_offsets[SET].x] = 1; - base_partial[flag_offsets[SET].y] = 1 + (digits[SET].x == digits[SET].y); - } -} - - -template -__device__ __forceinline__ void ExtractRanks( - unsigned char * base_partial, - int2 digits[SETS_PER_PASS], - int2 flag_offsets[SETS_PER_PASS], - int2 ranks[SETS_PER_PASS]) -{ - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - ranks[SET].x = base_partial[flag_offsets[SET].x]; - ranks[SET].y = base_partial[flag_offsets[SET].y] + (digits[SET].x == digits[SET].y); - } -} - - -template -__device__ __forceinline__ void UpdateRanks( - int2 digits[SETS_PER_PASS], - int2 ranks[SETS_PER_PASS], - int digit_counts[SETS_PER_PASS][RADIX_DIGITS]) -{ - // N.B.: I wish we could pragma unroll here, but doing so currently - // results in the 3.1 compilier on 64-bit platforms generating bad - // code for SM1.3, resulting in incorrect sorting (e.g., problem size 16) - - if (SETS_PER_PASS > 0) { - ranks[0].x += digit_counts[0][digits[0].x]; - ranks[0].y += digit_counts[0][digits[0].y]; - } - if (SETS_PER_PASS > 1) { - ranks[1].x += digit_counts[1][digits[1].x]; - ranks[1].y += digit_counts[1][digits[1].y]; - } - if (SETS_PER_PASS > 2) { - ranks[2].x += digit_counts[2][digits[2].x]; - ranks[2].y += digit_counts[2][digits[2].y]; - } - if (SETS_PER_PASS > 3) { - ranks[3].x += digit_counts[3][digits[3].x]; - ranks[3].y += digit_counts[3][digits[3].y]; - } -} - -template -__device__ __forceinline__ void UpdateRanks( - int2 digits[PASSES_PER_CYCLE][SETS_PER_PASS], - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS], - int digit_counts[PASSES_PER_CYCLE][SETS_PER_PASS][RADIX_DIGITS]) -{ - // N.B.: I wish we could pragma unroll here, but doing so currently - // results in the 3.1 compilier on 64-bit platforms generating bad - // code for SM1.3, resulting in incorrect sorting (e.g., problem size 16) - - if (PASSES_PER_CYCLE > 0) UpdateRanks(digits[0], ranks[0], digit_counts[0]); - if (PASSES_PER_CYCLE > 1) UpdateRanks(digits[1], ranks[1], digit_counts[1]); - if (PASSES_PER_CYCLE > 2) UpdateRanks(digits[2], ranks[2], digit_counts[2]); - if (PASSES_PER_CYCLE > 3) UpdateRanks(digits[3], ranks[3], digit_counts[3]); -} - - - -template -__device__ __forceinline__ void PrefixScanOverLanes( - int raking_segment[], - int warpscan[SCAN_LANES_PER_PASS][3][RAKING_THREADS_PER_LANE], - int copy_section) -{ - // Upsweep rake - int partial_reduction = SerialReduce(raking_segment); - - // Warpscan reduction in digit warpscan_lane - int warpscan_lane = threadIdx.x >> LOG_RAKING_THREADS_PER_LANE; - int group_prefix = WarpScan( - warpscan[warpscan_lane], - partial_reduction, - copy_section); - - // Downsweep rake - SerialScan(raking_segment, group_prefix); - -} - - -template -__device__ __forceinline__ void RecoverDigitCounts( - int warpscan[SCAN_LANES_PER_PASS][3][RAKING_THREADS_PER_LANE], - int counts[SETS_PER_PASS], - int copy_section) -{ - int my_lane = threadIdx.x >> 2; - int my_quad_byte = threadIdx.x & 3; - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - unsigned char *warpscan_count = (unsigned char *) &warpscan[my_lane + (SCAN_LANES_PER_SET * SET)][1 + copy_section][RAKING_THREADS_PER_LANE - 1]; - counts[SET] = warpscan_count[my_quad_byte]; - } -} - -template -__device__ __forceinline__ void CorrectUnguardedSetOverflow( - int2 set_digits, - int &set_count) -{ - if (WarpVoteAll(RADIX_DIGITS, set_count <= 1)) { - // All first-pass, first set keys have same digit. - set_count = (threadIdx.x == set_digits.x) ? 256 : 0; - } -} - -template -__device__ __forceinline__ void CorrectUnguardedPassOverflow( - int2 pass_digits[SETS_PER_PASS], - int pass_counts[SETS_PER_PASS]) -{ - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler won't comply, - // telling me "Advisory: Loop was not unrolled, unexpected call OPs" - - if (SETS_PER_PASS > 0) CorrectUnguardedSetOverflow(pass_digits[0], pass_counts[0]); - if (SETS_PER_PASS > 1) CorrectUnguardedSetOverflow(pass_digits[1], pass_counts[1]); - if (SETS_PER_PASS > 2) CorrectUnguardedSetOverflow(pass_digits[2], pass_counts[2]); - if (SETS_PER_PASS > 3) CorrectUnguardedSetOverflow(pass_digits[3], pass_counts[3]); -} - - -template -__device__ __forceinline__ void CorrectUnguardedCycleOverflow( - int2 cycle_digits[PASSES_PER_CYCLE][SETS_PER_PASS], - int cycle_counts[PASSES_PER_CYCLE][SETS_PER_PASS]) -{ - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler won't comply, - // telling me "Advisory: Loop was not unrolled, unexpected call OPs" - - if (PASSES_PER_CYCLE > 0) CorrectUnguardedPassOverflow(cycle_digits[0], cycle_counts[0]); - if (PASSES_PER_CYCLE > 1) CorrectUnguardedPassOverflow(cycle_digits[1], cycle_counts[1]); -} - - -template -__device__ __forceinline__ void CorrectLastLaneOverflow(int &count, int extra[1]) -{ - if (WarpVoteAll(RADIX_DIGITS, count == 0) && (threadIdx.x == RADIX_DIGITS - 1)) { - // We're 'f' and we overflowed b/c of invalid 'f' placemarkers; the number of valid items in this set is the count of valid f's - count = extra[0] & 255; - } -} - - -template -__device__ __forceinline__ void CorrectForOverflows( - int2 digits[PASSES_PER_CYCLE][SETS_PER_PASS], - int counts[PASSES_PER_CYCLE][SETS_PER_PASS], - int extra[1]) -{ - if (!UNGUARDED_IO) { - - // Correct any overflow in the partially-filled last lane - int *linear_counts = (int *) counts; - CorrectLastLaneOverflow(linear_counts[SETS_PER_CYCLE - 1], extra); - } - - CorrectUnguardedCycleOverflow(digits, counts); -} - - -template < - typename K, - int BIT, - int RADIX_DIGITS, - int SCAN_LANES_PER_SET, - int SETS_PER_PASS, - int RAKING_THREADS_PER_PASS, - int SCAN_LANES_PER_PASS, - int LOG_RAKING_THREADS_PER_LANE, - int RAKING_THREADS_PER_LANE, - int PARTIALS_PER_SEG, - int PADDED_PARTIALS_PER_LANE, - int PASSES_PER_CYCLE> -__device__ __forceinline__ void ScanPass( - int *base_partial, - int *raking_partial, - int warpscan[SCAN_LANES_PER_PASS][3][RAKING_THREADS_PER_LANE], - typename VecType::Type keypairs[SETS_PER_PASS], - int2 digits[SETS_PER_PASS], - int2 flag_offsets[SETS_PER_PASS], - int2 ranks[SETS_PER_PASS], - int copy_section) -{ - // Reset smem - #pragma unroll - for (int SCAN_LANE = 0; SCAN_LANE < (int) SCAN_LANES_PER_PASS; SCAN_LANE++) { - base_partial[SCAN_LANE * PADDED_PARTIALS_PER_LANE] = 0; - } - - // Decode digits for first pass - DecodeDigits( - keypairs, digits, flag_offsets); - - // Encode counts into smem for first pass - PlacePartials( - (unsigned char *) base_partial, - digits, - flag_offsets); - - __syncthreads(); - - // Intra-group prefix scans for first pass - if (threadIdx.x < RAKING_THREADS_PER_PASS) { - - PrefixScanOverLanes( // first pass is offset right by one - raking_partial, - warpscan, - copy_section); - } - - __syncthreads(); - - // Extract ranks - ExtractRanks( - (unsigned char *) base_partial, - digits, - flag_offsets, - ranks); -} - - -/****************************************************************************** - * SM1.3 Local Exchange Routines - * - * Routines for exchanging keys (and values) in shared memory (i.e., local - * scattering) in order to to facilitate coalesced global scattering - ******************************************************************************/ - -template -__device__ __forceinline__ void ScatterSets( - T *d_out, - typename VecType::Type pairs[SETS_PER_PASS], - int2 offsets[SETS_PER_PASS], - const int BASE4, - int extra[1], - PostprocessFunctor postprocess = PostprocessFunctor()) -{ - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - postprocess(pairs[SET].x); - postprocess(pairs[SET].y); - } - - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler makes it 1% slower - - if (SETS_PER_PASS > 0) { - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 0) < extra[0])) - d_out[offsets[0].x] = pairs[0].x; - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 1) < extra[0])) - d_out[offsets[0].y] = pairs[0].y; - } - - if (SETS_PER_PASS > 1) { - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 2) < extra[0])) - d_out[offsets[1].x] = pairs[1].x; - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 3) < extra[0])) - d_out[offsets[1].y] = pairs[1].y; - } - - if (SETS_PER_PASS > 2) { - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 4) < extra[0])) - d_out[offsets[2].x] = pairs[2].x; - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 5) < extra[0])) - d_out[offsets[2].y] = pairs[2].y; - } - - if (SETS_PER_PASS > 3) { - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 6) < extra[0])) - d_out[offsets[3].x] = pairs[3].x; - if (UNGUARDED_IO || (threadIdx.x + BASE4 + (B40C_RADIXSORT_THREADS * 7) < extra[0])) - d_out[offsets[3].y] = pairs[3].y; - } -} - -template -__device__ __forceinline__ void PushPairs( - T *swap, - typename VecType::Type pairs[PASSES_PER_CYCLE][SETS_PER_PASS], - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS]) -{ - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - swap[ranks[PASS][SET].x] = pairs[PASS][SET].x; - swap[ranks[PASS][SET].y] = pairs[PASS][SET].y; - } - } -} - -template -__device__ __forceinline__ void ExchangePairs( - T *swap, - typename VecType::Type pairs[PASSES_PER_CYCLE][SETS_PER_PASS], - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS]) -{ - // Push in Pairs - PushPairs(swap, pairs, ranks); - - __syncthreads(); - - // Extract pairs - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - const int BLOCK = ((PASS * SETS_PER_PASS) + SET) * 2; - pairs[PASS][SET].x = swap[threadIdx.x + (B40C_RADIXSORT_THREADS * (BLOCK + 0))]; - pairs[PASS][SET].y = swap[threadIdx.x + (B40C_RADIXSORT_THREADS * (BLOCK + 1))]; - } - } -} - - -template < - typename K, - typename V, - int RADIX_DIGITS, - int BIT, - int PASSES_PER_CYCLE, - int SETS_PER_PASS, - bool UNGUARDED_IO, - typename PostprocessFunctor> -__device__ __forceinline__ void SwapAndScatterSm13( - typename VecType::Type keypairs[PASSES_PER_CYCLE][SETS_PER_PASS], - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS], - int4 *exchange, - typename VecType::Type *d_in_values, - K *d_out_keys, - V *d_out_values, - int carry[RADIX_DIGITS], - int extra[1]) -{ - int2 offsets[PASSES_PER_CYCLE][SETS_PER_PASS]; - - // Swap keys according to ranks - ExchangePairs((K*) exchange, keypairs, ranks); - - // Calculate scatter offsets (re-decode digits from keys: it's less work than making a second exchange of digits) - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - const int BLOCK = ((PASS * SETS_PER_PASS) + SET) * 2; - offsets[PASS][SET].x = threadIdx.x + (B40C_RADIXSORT_THREADS * (BLOCK + 0)) + carry[DecodeDigit(keypairs[PASS][SET].x)]; - offsets[PASS][SET].y = threadIdx.x + (B40C_RADIXSORT_THREADS * (BLOCK + 1)) + carry[DecodeDigit(keypairs[PASS][SET].y)]; - } - } - - // Scatter keys - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - const int BLOCK = PASS * SETS_PER_PASS * 2; - ScatterSets(d_out_keys, keypairs[PASS], offsets[PASS], B40C_RADIXSORT_THREADS * BLOCK, extra); - } - - if (!IsKeysOnly()) { - - __syncthreads(); - - // Read input data - typename VecType::Type datapairs[PASSES_PER_CYCLE][SETS_PER_PASS]; - - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler won't comply, - // telling me "Advisory: Loop was not unrolled, unexpected control flow" - - if (PASSES_PER_CYCLE > 0) ReadSets >(d_in_values, datapairs[0], B40C_RADIXSORT_THREADS * SETS_PER_PASS * 0, extra); - if (PASSES_PER_CYCLE > 1) ReadSets >(d_in_values, datapairs[1], B40C_RADIXSORT_THREADS * SETS_PER_PASS * 1, extra); - - // Swap data according to ranks - ExchangePairs((V*) exchange, datapairs, ranks); - - // Scatter data - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - const int BLOCK = PASS * SETS_PER_PASS * 2; - ScatterSets >(d_out_values, datapairs[PASS], offsets[PASS], B40C_RADIXSORT_THREADS * BLOCK, extra); - } - } -} - - -/****************************************************************************** - * SM1.0 Local Exchange Routines - * - * Routines for exchanging keys (and values) in shared memory (i.e., local - * scattering) in order to to facilitate coalesced global scattering - ******************************************************************************/ - -template < - typename T, - int RADIX_DIGITS, - bool UNGUARDED_IO, - typename PostprocessFunctor> -__device__ __forceinline__ void ScatterPass( - T *swapmem, - T *d_out, - int digit_scan[2][RADIX_DIGITS], - int carry[RADIX_DIGITS], - int extra[1], - int base_digit, - PostprocessFunctor postprocess = PostprocessFunctor()) -{ - const int LOG_STORE_TXN_THREADS = B40C_LOG_MEM_BANKS(__CUDA_ARCH__); - const int STORE_TXN_THREADS = 1 << LOG_STORE_TXN_THREADS; - - int store_txn_idx = threadIdx.x & (STORE_TXN_THREADS - 1); - int store_txn_digit = threadIdx.x >> LOG_STORE_TXN_THREADS; - - int my_digit = base_digit + store_txn_digit; - if (my_digit < RADIX_DIGITS) { - - int my_exclusive_scan = digit_scan[1][my_digit - 1]; - int my_inclusive_scan = digit_scan[1][my_digit]; - int my_digit_count = my_inclusive_scan - my_exclusive_scan; - - int my_carry = carry[my_digit] + my_exclusive_scan; - int my_aligned_offset = store_txn_idx - (my_carry & (STORE_TXN_THREADS - 1)); - - while (my_aligned_offset < my_digit_count) { - - if ((my_aligned_offset >= 0) && (UNGUARDED_IO || (my_exclusive_scan + my_aligned_offset < extra[0]))) { - - T datum = swapmem[my_exclusive_scan + my_aligned_offset]; - postprocess(datum); - d_out[my_carry + my_aligned_offset] = datum; - } - my_aligned_offset += STORE_TXN_THREADS; - } - } -} - -template < - typename T, - int RADIX_DIGITS, - int PASSES_PER_CYCLE, - int SETS_PER_PASS, - bool UNGUARDED_IO, - typename PostprocessFunctor> -__device__ __forceinline__ void SwapAndScatterPairs( - typename VecType::Type pairs[PASSES_PER_CYCLE][SETS_PER_PASS], - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS], - T *exchange, - T *d_out, - int carry[RADIX_DIGITS], - int digit_scan[2][RADIX_DIGITS], - int extra[1]) -{ - const int SCATTER_PASS_DIGITS = B40C_RADIXSORT_WARPS * (B40C_WARP_THREADS / B40C_MEM_BANKS(__CUDA_ARCH__)); - const int SCATTER_PASSES = RADIX_DIGITS / SCATTER_PASS_DIGITS; - - // Push in pairs - PushPairs(exchange, pairs, ranks); - - __syncthreads(); - - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler won't comply, - // telling me "Advisory: Loop was not unrolled, not an innermost loop" - - if (SCATTER_PASSES > 0) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 0); - if (SCATTER_PASSES > 1) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 1); - if (SCATTER_PASSES > 2) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 2); - if (SCATTER_PASSES > 3) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 3); - if (SCATTER_PASSES > 4) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 4); - if (SCATTER_PASSES > 5) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 5); - if (SCATTER_PASSES > 6) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 6); - if (SCATTER_PASSES > 7) ScatterPass(exchange, d_out, digit_scan, carry, extra, SCATTER_PASS_DIGITS * 7); -} - - -template < - typename K, - typename V, - int RADIX_DIGITS, - int PASSES_PER_CYCLE, - int SETS_PER_PASS, - bool UNGUARDED_IO, - typename PostprocessFunctor> -__device__ __forceinline__ void SwapAndScatterSm10( - typename VecType::Type keypairs[PASSES_PER_CYCLE][SETS_PER_PASS], - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS], - int4 *exchange, - typename VecType::Type *d_in_values, - K *d_out_keys, - V *d_out_values, - int carry[RADIX_DIGITS], - int digit_scan[2][RADIX_DIGITS], - int extra[1]) -{ - // Swap and scatter keys - SwapAndScatterPairs( - keypairs, ranks, (K*) exchange, d_out_keys, carry, digit_scan, extra); - - if (!IsKeysOnly()) { - - __syncthreads(); - - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler won't comply, - // telling me "Advisory: Loop was not unrolled, unexpected control flow" - - // Read input data - typename VecType::Type datapairs[PASSES_PER_CYCLE][SETS_PER_PASS]; - if (PASSES_PER_CYCLE > 0) ReadSets >(d_in_values, datapairs[0], B40C_RADIXSORT_THREADS * SETS_PER_PASS * 0, extra); - if (PASSES_PER_CYCLE > 1) ReadSets >(d_in_values, datapairs[1], B40C_RADIXSORT_THREADS * SETS_PER_PASS * 1, extra); - - // Swap and scatter data - SwapAndScatterPairs >( - datapairs, ranks, (V*) exchange, d_out_values, carry, digit_scan, extra); - } -} - - -/****************************************************************************** - * Cycle of RADIXSORT_CYCLE_ELEMENTS keys (and values) - ******************************************************************************/ - -template < - typename K, - typename V, - int BIT, - bool UNGUARDED_IO, - int RADIX_DIGITS, - int LOG_SCAN_LANES_PER_SET, - int SCAN_LANES_PER_SET, - int SETS_PER_PASS, - int PASSES_PER_CYCLE, - int LOG_SCAN_LANES_PER_PASS, - int SCAN_LANES_PER_PASS, - int LOG_PARTIALS_PER_LANE, - int LOG_PARTIALS_PER_PASS, - int LOG_RAKING_THREADS_PER_PASS, - int RAKING_THREADS_PER_PASS, - int LOG_RAKING_THREADS_PER_LANE, - int RAKING_THREADS_PER_LANE, - int LOG_PARTIALS_PER_SEG, - int PARTIALS_PER_SEG, - int LOG_PARTIALS_PER_ROW, - int PARTIALS_PER_ROW, - int LOG_SEGS_PER_ROW, - int SEGS_PER_ROW, - int LOG_ROWS_PER_SET, - int LOG_ROWS_PER_LANE, - int ROWS_PER_LANE, - int LOG_ROWS_PER_PASS, - int ROWS_PER_PASS, - int MAX_EXCHANGE_BYTES, - typename PreprocessFunctor, - typename PostprocessFunctor> - -__device__ __forceinline__ void SrtsScanDigitCycle( - typename VecType::Type *d_in_keys, - typename VecType::Type *d_in_values, - K *d_out_keys, - V *d_out_values, - int4 *exchange, - int warpscan[SCAN_LANES_PER_PASS][3][RAKING_THREADS_PER_LANE], - int carry[RADIX_DIGITS], - int digit_scan[2][RADIX_DIGITS], - int digit_counts[PASSES_PER_CYCLE][SETS_PER_PASS][RADIX_DIGITS], - int extra[1], - int *base_partial, - int *raking_partial) -{ - - const int PADDED_PARTIALS_PER_LANE = ROWS_PER_LANE * (PARTIALS_PER_ROW + 1); - const int SETS_PER_CYCLE = PASSES_PER_CYCLE * SETS_PER_PASS; - - // N.B.: We use the following voodoo incantations to elide the compiler's miserable - // "declared but never referenced" warnings for these (which are actually used for - // template instantiation) - SuppressUnusedConstantWarning(PADDED_PARTIALS_PER_LANE); - SuppressUnusedConstantWarning(SETS_PER_CYCLE); - - typename VecType::Type keypairs[PASSES_PER_CYCLE][SETS_PER_PASS]; - int2 digits[PASSES_PER_CYCLE][SETS_PER_PASS]; - int2 flag_offsets[PASSES_PER_CYCLE][SETS_PER_PASS]; // a byte offset - int2 ranks[PASSES_PER_CYCLE][SETS_PER_PASS]; - - - //------------------------------------------------------------------------- - // Read keys - //------------------------------------------------------------------------- - - // N.B. -- I wish we could do some pragma unrolling here too, but the compiler won't comply, - // telling me "Advisory: Loop was not unrolled, unexpected control flow construct" - - // Read Keys - if (PASSES_PER_CYCLE > 0) ReadSets(d_in_keys, keypairs[0], B40C_RADIXSORT_THREADS * SETS_PER_PASS * 0, extra); - if (PASSES_PER_CYCLE > 1) ReadSets(d_in_keys, keypairs[1], B40C_RADIXSORT_THREADS * SETS_PER_PASS * 1, extra); - - //------------------------------------------------------------------------- - // Lane-scanning Passes - //------------------------------------------------------------------------- - - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - - // First Pass - ScanPass( - base_partial, - raking_partial, - warpscan, - keypairs[PASS], - digits[PASS], - flag_offsets[PASS], - ranks[PASS], - PASSES_PER_CYCLE - PASS - 1); // lower passes get copied right - } - - //------------------------------------------------------------------------- - // Digit-scanning - //------------------------------------------------------------------------- - - // Recover second-half digit-counts, scan across all digit-counts - if (threadIdx.x < RADIX_DIGITS) { - - int counts[PASSES_PER_CYCLE][SETS_PER_PASS]; - - // Recover digit-counts - - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - RecoverDigitCounts( // first pass, offset by 1 - warpscan, - counts[PASS], - PASSES_PER_CYCLE - PASS - 1); // lower passes get copied right - } - - // Check for overflows - CorrectForOverflows( - digits, counts, extra); - - // Scan across my digit counts for each set - int exclusive_total = 0; - int inclusive_total = 0; - - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - inclusive_total += counts[PASS][SET]; - counts[PASS][SET] = exclusive_total; - exclusive_total = inclusive_total; - } - } - - // second half of carry update - int my_carry = carry[threadIdx.x] + digit_scan[1][threadIdx.x]; - - // Perform overflow-free SIMD Kogge-Stone across digits - int digit_prefix = WarpScan( - digit_scan, - inclusive_total, - 0); - - // first-half of carry update - carry[threadIdx.x] = my_carry - digit_prefix; - - #pragma unroll - for (int PASS = 0; PASS < (int) PASSES_PER_CYCLE; PASS++) { - - #pragma unroll - for (int SET = 0; SET < (int) SETS_PER_PASS; SET++) { - digit_counts[PASS][SET][threadIdx.x] = counts[PASS][SET] + digit_prefix; - } - } - } - - __syncthreads(); - - //------------------------------------------------------------------------- - // Update Ranks - //------------------------------------------------------------------------- - - UpdateRanks(digits, ranks, digit_counts); - - - //------------------------------------------------------------------------- - // Scatter - //------------------------------------------------------------------------- - -#if ((__CUDA_ARCH__ < 130) || FERMI_ECC) - - SwapAndScatterSm10( - keypairs, - ranks, - exchange, - d_in_values, - d_out_keys, - d_out_values, - carry, - digit_scan, - extra); - -#else - - SwapAndScatterSm13( - keypairs, - ranks, - exchange, - d_in_values, - d_out_keys, - d_out_values, - carry, - extra); - -#endif - - __syncthreads(); - -} - - - -/****************************************************************************** - * Scan/Scatter Kernel Entry Point - ******************************************************************************/ - -template < - typename K, - typename V, - int PASS, - int RADIX_BITS, - int BIT, - typename PreprocessFunctor, - typename PostprocessFunctor> -__launch_bounds__ (B40C_RADIXSORT_THREADS, B40C_RADIXSORT_SCAN_SCATTER_CTA_OCCUPANCY(__CUDA_ARCH__)) -__global__ -void ScanScatterDigits( - bool *d_from_alt_storage, - int* d_spine, - K* d_in_keys, - K* d_out_keys, - V* d_in_values, - V* d_out_values, - CtaDecomposition work_decomposition) -{ - - const int RADIX_DIGITS = 1 << RADIX_BITS; - - const int LOG_SCAN_LANES_PER_SET = (RADIX_BITS > 2) ? RADIX_BITS - 2 : 0; // Always at one lane per set - const int SCAN_LANES_PER_SET = 1 << LOG_SCAN_LANES_PER_SET; // N.B.: we have "declared but never referenced" warnings for these, but they're actually used for template instantiation - - const int LOG_SETS_PER_PASS = B40C_RADIXSORT_LOG_SETS_PER_PASS(__CUDA_ARCH__); - const int SETS_PER_PASS = 1 << LOG_SETS_PER_PASS; - - const int LOG_PASSES_PER_CYCLE = B40C_RADIXSORT_LOG_PASSES_PER_CYCLE(__CUDA_ARCH__, K, V); - const int PASSES_PER_CYCLE = 1 << LOG_PASSES_PER_CYCLE; - - const int LOG_SCAN_LANES_PER_PASS = LOG_SETS_PER_PASS + LOG_SCAN_LANES_PER_SET; - const int SCAN_LANES_PER_PASS = 1 << LOG_SCAN_LANES_PER_PASS; - - const int LOG_PARTIALS_PER_LANE = B40C_RADIXSORT_LOG_THREADS; - - const int LOG_PARTIALS_PER_PASS = LOG_SCAN_LANES_PER_PASS + LOG_PARTIALS_PER_LANE; - - const int LOG_RAKING_THREADS_PER_PASS = B40C_RADIXSORT_LOG_RAKING_THREADS_PER_PASS(__CUDA_ARCH__); - const int RAKING_THREADS_PER_PASS = 1 << LOG_RAKING_THREADS_PER_PASS; - - const int LOG_RAKING_THREADS_PER_LANE = LOG_RAKING_THREADS_PER_PASS - LOG_SCAN_LANES_PER_PASS; - const int RAKING_THREADS_PER_LANE = 1 << LOG_RAKING_THREADS_PER_LANE; - - const int LOG_PARTIALS_PER_SEG = LOG_PARTIALS_PER_LANE - LOG_RAKING_THREADS_PER_LANE; - const int PARTIALS_PER_SEG = 1 << LOG_PARTIALS_PER_SEG; - - const int LOG_PARTIALS_PER_ROW = (LOG_PARTIALS_PER_SEG < B40C_LOG_MEM_BANKS(__CUDA_ARCH__)) ? B40C_LOG_MEM_BANKS(__CUDA_ARCH__) : LOG_PARTIALS_PER_SEG; // floor of MEM_BANKS partials per row - const int PARTIALS_PER_ROW = 1 << LOG_PARTIALS_PER_ROW; - const int PADDED_PARTIALS_PER_ROW = PARTIALS_PER_ROW + 1; - - const int LOG_SEGS_PER_ROW = LOG_PARTIALS_PER_ROW - LOG_PARTIALS_PER_SEG; - const int SEGS_PER_ROW = 1 << LOG_SEGS_PER_ROW; - - const int LOG_ROWS_PER_SET = LOG_PARTIALS_PER_PASS - LOG_PARTIALS_PER_ROW; - - const int LOG_ROWS_PER_LANE = LOG_PARTIALS_PER_LANE - LOG_PARTIALS_PER_ROW; - const int ROWS_PER_LANE = 1 << LOG_ROWS_PER_LANE; - - const int LOG_ROWS_PER_PASS = LOG_SCAN_LANES_PER_PASS + LOG_ROWS_PER_LANE; - const int ROWS_PER_PASS = 1 << LOG_ROWS_PER_PASS; - - const int SCAN_LANE_BYTES = ROWS_PER_PASS * PADDED_PARTIALS_PER_ROW * sizeof(int); - const int MAX_EXCHANGE_BYTES = (sizeof(K) > sizeof(V)) ? - B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V) * sizeof(K) : - B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V) * sizeof(V); - const int SCAN_LANE_INT4S = (B40C_MAX(MAX_EXCHANGE_BYTES, SCAN_LANE_BYTES) + sizeof(int4) - 1) / sizeof(int4); - - - // N.B.: We use the following voodoo incantations to elide the compiler's miserable - // "declared but never referenced" warnings for these (which are actually used for - // template instantiation) - SuppressUnusedConstantWarning(SCAN_LANES_PER_SET); - SuppressUnusedConstantWarning(PARTIALS_PER_SEG); - SuppressUnusedConstantWarning(LOG_ROWS_PER_SET); - SuppressUnusedConstantWarning(ROWS_PER_LANE); - - // scan_lanes is a int4[] to avoid alignment issues when casting to (K *) and/or (V *) - __shared__ int4 scan_lanes[SCAN_LANE_INT4S]; - __shared__ int warpscan[SCAN_LANES_PER_PASS][3][RAKING_THREADS_PER_LANE]; // One warpscan per fours-group - __shared__ int carry[RADIX_DIGITS]; - __shared__ int digit_scan[2][RADIX_DIGITS]; - __shared__ int digit_counts[PASSES_PER_CYCLE][SETS_PER_PASS][RADIX_DIGITS]; - __shared__ bool non_trivial_digit_pass; - __shared__ bool from_alt_storage; - - _B40C_REG_MISER_QUALIFIER_ int extra[1]; - _B40C_REG_MISER_QUALIFIER_ int oob[1]; - - extra[0] = (blockIdx.x == gridDim.x - 1) ? work_decomposition.extra_elements_last_block : 0; - - // calculate our threadblock's range - int block_elements, block_offset; - if (blockIdx.x < work_decomposition.num_big_blocks) { - block_offset = work_decomposition.big_block_elements * blockIdx.x; - block_elements = work_decomposition.big_block_elements; - } else { - block_offset = (work_decomposition.normal_block_elements * blockIdx.x) + (work_decomposition.num_big_blocks * B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V)); - block_elements = work_decomposition.normal_block_elements; - } - oob[0] = block_offset + block_elements; // out-of-bounds - - - // location for placing 2-element partial reductions in the first lane of a pass - int row = threadIdx.x >> LOG_PARTIALS_PER_ROW; - int col = threadIdx.x & (PARTIALS_PER_ROW - 1); - int *base_partial = reinterpret_cast(scan_lanes) + (row * PADDED_PARTIALS_PER_ROW) + col; - - // location for raking across all sets within a pass - int *raking_partial = 0; - - if (threadIdx.x < RAKING_THREADS_PER_PASS) { - - // initalize lane warpscans - if (threadIdx.x < RAKING_THREADS_PER_LANE) { - - #pragma unroll - for (int SCAN_LANE = 0; SCAN_LANE < (int) SCAN_LANES_PER_PASS; SCAN_LANE++) { - warpscan[SCAN_LANE][0][threadIdx.x] = 0; - } - } - - // initialize digit warpscans - if (threadIdx.x < RADIX_DIGITS) { - - // Initialize digit_scan - digit_scan[0][threadIdx.x] = 0; - digit_scan[1][threadIdx.x] = 0; - - // Determine where to read our input - from_alt_storage = (PASS == 0) ? false : d_from_alt_storage[PASS & 0x1]; - - // Read carry in parallel - int spine_digit_offset = FastMul(gridDim.x, threadIdx.x); - int my_digit_carry = d_spine[spine_digit_offset + blockIdx.x]; - carry[threadIdx.x] = my_digit_carry; - - // Determine whether or not we have work to do and setup the next round - // accordingly. Everybody but the first threadblock can determine this - // from the number of non-zero-and-non-oob digit carries. First block - // needs someone else's because he always writes the zero offset. - - int predicate; - if (PreprocessFunctor::MustApply() || PostprocessFunctor::MustApply()) { - - non_trivial_digit_pass = true; - - } else { - - if (blockIdx.x > 0) { - // Non-first CTA : use digit-carry from first block - my_digit_carry = d_spine[spine_digit_offset]; - } - - predicate = ((my_digit_carry > 0) && (my_digit_carry < work_decomposition.num_elements)); - non_trivial_digit_pass = (TallyWarpVote(RADIX_DIGITS, predicate, reinterpret_cast(scan_lanes)) > 0); - } - - // Let the next round know which set of buffers to use - if (blockIdx.x == 0) d_from_alt_storage[(PASS + 1) & 0x1] = from_alt_storage ^ non_trivial_digit_pass; - } - - // initialize raking segment - row = threadIdx.x >> LOG_SEGS_PER_ROW; - col = (threadIdx.x & (SEGS_PER_ROW - 1)) << LOG_PARTIALS_PER_SEG; - raking_partial = reinterpret_cast(scan_lanes) + (row * PADDED_PARTIALS_PER_ROW) + col; - } - - // Sync to acquire non_trivial_digit_pass and from_temp_storage - __syncthreads(); - - // Short-circuit this entire pass - if (!non_trivial_digit_pass) return; - - if (!from_alt_storage) { - - // Scan in tiles of cycle_elements - while (block_offset < oob[0]) { - - SrtsScanDigitCycle( - reinterpret_cast::Type *>((void *) &d_in_keys[block_offset]), - reinterpret_cast::Type *>((void *) &d_in_values[block_offset]), - d_out_keys, - d_out_values, - scan_lanes, - warpscan, - carry, - digit_scan, - digit_counts, - extra, - base_partial, - raking_partial); - - block_offset += B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V); - } - - if (extra[0]) { - - SrtsScanDigitCycle( - reinterpret_cast::Type *>((void *) &d_in_keys[block_offset]), - reinterpret_cast::Type *>((void *) &d_in_values[block_offset]), - d_out_keys, - d_out_values, - scan_lanes, - warpscan, - carry, - digit_scan, - digit_counts, - extra, - base_partial, - raking_partial); - } - - } else { - - // Scan in tiles of cycle_elements - while (block_offset < oob[0]) { - - SrtsScanDigitCycle( - reinterpret_cast::Type *>((void *) &d_out_keys[block_offset]), - reinterpret_cast::Type *>((void *) &d_out_values[block_offset]), - d_in_keys, - d_in_values, - scan_lanes, - warpscan, - carry, - digit_scan, - digit_counts, - extra, - base_partial, - raking_partial); - - block_offset += B40C_RADIXSORT_CYCLE_ELEMENTS(__CUDA_ARCH__, K, V); - } - - if (extra[0]) { - - SrtsScanDigitCycle( - reinterpret_cast::Type *>((void *) &d_out_keys[block_offset]), - reinterpret_cast::Type *>((void *) &d_out_values[block_offset]), - d_in_keys, - d_in_values, - scan_lanes, - warpscan, - carry, - digit_scan, - digit_counts, - extra, - base_partial, - raking_partial); - } - - } -} - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_spine_kernel.h b/compat/thrust/system/cuda/detail/detail/b40c/radixsort_spine_kernel.h deleted file mode 100644 index 3d20f4a..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/radixsort_spine_kernel.h +++ /dev/null @@ -1,187 +0,0 @@ -/****************************************************************************** - * - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * - * - * AUTHORS' REQUEST: - * - * If you use|reference|benchmark this code, please cite our Technical - * Report (http://www.cs.virginia.edu/~dgm4d/papers/RadixSortTR.pdf): - * - * @TechReport{ Merrill:Sorting:2010, - * author = "Duane Merrill and Andrew Grimshaw", - * title = "Revisiting Sorting for GPGPU Stream Architectures", - * year = "2010", - * institution = "University of Virginia, Department of Computer Science", - * address = "Charlottesville, VA, USA", - * number = "CS2010-03" - * } - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - * - ******************************************************************************/ - - -/****************************************************************************** - * Top-level histogram/spine scanning kernel - ******************************************************************************/ - -#pragma once - -#include "radixsort_kernel_common.h" - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - -/****************************************************************************** - * Scans a cycle of RADIXSORT_CYCLE_ELEMENTS elements - ******************************************************************************/ - -template -__device__ __forceinline__ void SrtsScanCycle( - int *smem_offset, - int *smem_segment, - int warpscan[2][B40C_WARP_THREADS], - int4 *in, - int4 *out, - int &carry) -{ - int4 datum; - - // read input data - datum = in[threadIdx.x]; - - smem_offset[0] = datum.x + datum.y + datum.z + datum.w; - - __syncthreads(); - - if (threadIdx.x < B40C_WARP_THREADS) { - - int partial_reduction = SerialReduce(smem_segment); - - int seed = WarpScan(warpscan, partial_reduction, 0); - seed += carry; - - SerialScan(smem_segment, seed); - - carry += warpscan[1][B40C_WARP_THREADS - 1]; - } - - __syncthreads(); - - int part0 = smem_offset[0]; - int part1; - - part1 = datum.x + part0; - datum.x = part0; - part0 = part1 + datum.y; - datum.y = part1; - - part1 = datum.z + part0; - datum.z = part0; - part0 = part1 + datum.w; - datum.w = part1; - - out[threadIdx.x] = datum; -} - - -/****************************************************************************** - * Spine/histogram Scan Kernel Entry Point - ******************************************************************************/ - -template -__global__ void SrtsScanSpine( - int *d_ispine, - int *d_ospine, - int normal_block_elements) -{ - const int LOG_PARTIALS = B40C_RADIXSORT_LOG_THREADS; - const int PARTIALS = 1 << LOG_PARTIALS; - - const int LOG_PARTIALS_PER_SEG = LOG_PARTIALS - B40C_LOG_WARP_THREADS; - const int PARTIALS_PER_SEG = 1 << LOG_PARTIALS_PER_SEG; - - const int LOG_PARTIALS_PER_ROW = (LOG_PARTIALS_PER_SEG < B40C_LOG_MEM_BANKS(__CUDA_ARCH__)) ? B40C_LOG_MEM_BANKS(__CUDA_ARCH__) : LOG_PARTIALS_PER_SEG; // floor of 32 elts per row - const int PARTIALS_PER_ROW = 1 << LOG_PARTIALS_PER_ROW; - - const int LOG_SEGS_PER_ROW = LOG_PARTIALS_PER_ROW - LOG_PARTIALS_PER_SEG; - const int SEGS_PER_ROW = 1 << LOG_SEGS_PER_ROW; - - const int SMEM_ROWS = PARTIALS / PARTIALS_PER_ROW; - - __shared__ int smem[SMEM_ROWS][PARTIALS_PER_ROW + 1]; - __shared__ int warpscan[2][B40C_WARP_THREADS]; - - // WAR spurious unused constant warning - SuppressUnusedConstantWarning(PARTIALS_PER_SEG); - - int *smem_segment = 0; - int carry = 0; - - int row = threadIdx.x >> LOG_PARTIALS_PER_ROW; - int col = threadIdx.x & (PARTIALS_PER_ROW - 1); - int *smem_offset = &smem[row][col]; - - if (blockIdx.x > 0) { - return; - } - - if (threadIdx.x < B40C_WARP_THREADS) { - - // two segs per row, odd segs are offset by 8 - row = threadIdx.x >> LOG_SEGS_PER_ROW; - col = (threadIdx.x & (SEGS_PER_ROW - 1)) << LOG_PARTIALS_PER_SEG; - smem_segment = &smem[row][col]; - - if (threadIdx.x < B40C_WARP_THREADS) { - carry = 0; - warpscan[0][threadIdx.x] = 0; - } - } - - // scan the spine in blocks of cycle_elements - int block_offset = 0; - while (block_offset < normal_block_elements) { - - SrtsScanCycle( - smem_offset, - smem_segment, - warpscan, - reinterpret_cast((void *) &d_ispine[block_offset]), - reinterpret_cast((void *) &d_ospine[block_offset]), - carry); - - block_offset += B40C_RADIXSORT_SPINE_CYCLE_ELEMENTS; - } -} - - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/b40c/vector_types.h b/compat/thrust/system/cuda/detail/detail/b40c/vector_types.h deleted file mode 100644 index 6db7931..0000000 --- a/compat/thrust/system/cuda/detail/detail/b40c/vector_types.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright 2010 Duane Merrill - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * For more information, see our Google Code project site: - * http://code.google.com/p/back40computing/ - * - * Thanks! - */ - -#pragma once - -#include - -namespace thrust { -namespace system { -namespace cuda { -namespace detail { -namespace detail { -namespace b40c_thrust { - -//------------------------------------------------------------------------------ -// Vector types -//------------------------------------------------------------------------------ - -template struct VecType; - - -// -// Define general vector types -// - -template -struct VecType { - K x; - typedef K Type; -}; - -template -struct VecType { - K x; - K y; - typedef VecType Type; -}; - -template -struct VecType { - K x; - K y; - K z; - K w; - typedef VecType Type; -}; - -// -// Specialize certain built-in vector types -// - -#define B40C_DEFINE_VECTOR_TYPE(base_type,short_type) \ - template<> struct VecType { typedef short_type##1 Type; }; \ - template<> struct VecType { typedef short_type##2 Type; }; \ - template<> struct VecType { typedef short_type##4 Type; }; - -B40C_DEFINE_VECTOR_TYPE(char, char) -B40C_DEFINE_VECTOR_TYPE(short, short) -B40C_DEFINE_VECTOR_TYPE(int, int) -B40C_DEFINE_VECTOR_TYPE(long, long) -B40C_DEFINE_VECTOR_TYPE(long long, longlong) -B40C_DEFINE_VECTOR_TYPE(unsigned char, uchar) -B40C_DEFINE_VECTOR_TYPE(unsigned short, ushort) -B40C_DEFINE_VECTOR_TYPE(unsigned int, uint) -B40C_DEFINE_VECTOR_TYPE(unsigned long, ulong) -B40C_DEFINE_VECTOR_TYPE(unsigned long long, ulonglong) -B40C_DEFINE_VECTOR_TYPE(float, float) -B40C_DEFINE_VECTOR_TYPE(double, double) - -#undef B40C_DEFINE_VECTOR_TYPE - -} // end namespace b40c_thrust -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/balanced_path.h b/compat/thrust/system/cuda/detail/detail/balanced_path.h deleted file mode 100644 index 51e4f5b..0000000 --- a/compat/thrust/system/cuda/detail/detail/balanced_path.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace balanced_path_detail -{ - -template -__host__ __device__ void BinarySearchIteration(It data, int& begin, int& end, - T key, int shift, Comp comp) { - - IntT scale = (1<< shift) - 1; - int mid = (int)((begin + scale * end)>> shift); - - T key2 = data[mid]; - bool pred = UpperBound ? !comp(key, key2) : comp(key2, key); - if(pred) begin = (int)mid + 1; - else end = mid; -} - -template -__host__ __device__ int BinarySearch(It data, int count, T key, Comp comp) { - int begin = 0; - int end = count; - while(begin < end) - BinarySearchIteration(data, begin, end, key, 1, comp); - return begin; -} - -template -__host__ __device__ int BiasedBinarySearch(It data, int count, T key, - IntT levels, Comp comp) { - int begin = 0; - int end = count; - - if(levels >= 4 && begin < end) - BinarySearchIteration(data, begin, end, key, 9, comp); - if(levels >= 3 && begin < end) - BinarySearchIteration(data, begin, end, key, 7, comp); - if(levels >= 2 && begin < end) - BinarySearchIteration(data, begin, end, key, 5, comp); - if(levels >= 1 && begin < end) - BinarySearchIteration(data, begin, end, key, 4, comp); - - while(begin < end) - BinarySearchIteration(data, begin, end, key, 1, comp); - return begin; -} - -template -__host__ __device__ int MergePath(It1 a, int aCount, It2 b, int bCount, int diag, Comp comp) -{ - typedef typename thrust::iterator_traits::value_type T; - - int begin = thrust::max(0, diag - bCount); - int end = thrust::min(diag, aCount); - - while(begin < end) - { - int mid = (begin + end)>> 1; - T aKey = a[mid]; - T bKey = b[diag - 1 - mid]; - bool pred = UpperBound ? comp(aKey, bKey) : !comp(bKey, aKey); - if(pred) begin = mid + 1; - else end = mid; - } - return begin; -} - - -} // end namespace balanced_path_detail - - -template -__host__ __device__ -thrust::pair - balanced_path(RandomAccessIterator1 first1, Size1 n1, - RandomAccessIterator2 first2, Size1 n2, - Size1 diag, - Size2 levels, - Compare comp) -{ - typedef typename thrust::iterator_traits::value_type T; - - Size1 aIndex = balanced_path_detail::MergePath(first1, n1, first2, n2, diag, comp); - Size1 bIndex = diag - aIndex; - - bool star = false; - if(bIndex < n2) - { - T x = first2[bIndex]; - - // Search for the beginning of the duplicate run in both A and B. - Size1 aStart = balanced_path_detail::BiasedBinarySearch(first1, aIndex, x, levels, comp); - Size1 bStart = balanced_path_detail::BiasedBinarySearch(first2, bIndex, x, levels, comp); - - // The distance between x's merge path and its lower_bound is its rank. - // We add up the a and b ranks and evenly distribute them to - // get a stairstep path. - Size1 aRun = aIndex - aStart; - Size1 bRun = bIndex - bStart; - Size1 xCount = aRun + bRun; - - // Attempt to advance b and regress a. - Size1 bAdvance = thrust::max(xCount >> 1, xCount - aRun); - Size1 bEnd = thrust::min(n2, bStart + bAdvance + 1); - Size1 bRunEnd = balanced_path_detail::BinarySearch(first2 + bIndex, bEnd - bIndex, x, comp) + bIndex; - bRun = bRunEnd - bStart; - - bAdvance = thrust::min(bAdvance, bRun); - Size1 aAdvance = xCount - bAdvance; - - bool roundUp = (aAdvance == bAdvance + 1) && (bAdvance < bRun); - aIndex = aStart + aAdvance; - - if(roundUp) star = true; - } - - return thrust::make_pair(aIndex, (diag - aIndex) + star); -} - - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/cached_temporary_allocator.h b/compat/thrust/system/cuda/detail/detail/cached_temporary_allocator.h deleted file mode 100644 index 2bbd658..0000000 --- a/compat/thrust/system/cuda/detail/detail/cached_temporary_allocator.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - - -template class BasePolicy> - class cached_temporary_allocator - : public BasePolicy > -{ - private: - typedef thrust::detail::temporary_allocator base_allocator_type; - typedef thrust::detail::allocator_traits traits; - typedef typename traits::pointer allocator_pointer; - typedef std::multimap free_blocks_type; - typedef std::map allocated_blocks_type; - - base_allocator_type m_base_allocator; - free_blocks_type free_blocks; - allocated_blocks_type allocated_blocks; - - void free_all() - { - // deallocate all outstanding blocks in both lists - for(free_blocks_type::iterator i = free_blocks.begin(); - i != free_blocks.end(); - ++i) - { - // transform the pointer to allocator_pointer before calling deallocate - traits::deallocate(m_base_allocator, allocator_pointer(reinterpret_cast(i->second)), i->first); - } - - for(allocated_blocks_type::iterator i = allocated_blocks.begin(); - i != allocated_blocks.end(); - ++i) - { - // transform the pointer to allocator_pointer before calling deallocate - traits::deallocate(m_base_allocator, allocator_pointer(reinterpret_cast(i->first)), i->second); - } - } - - public: - cached_temporary_allocator(thrust::execution_policy &system) - : m_base_allocator(system) - {} - - ~cached_temporary_allocator() - { - // free all allocations when cached_allocator goes out of scope - free_all(); - } - - void *allocate(std::ptrdiff_t num_bytes) - { - void *result = 0; - - // search the cache for a free block - free_blocks_type::iterator free_block = free_blocks.find(num_bytes); - - if(free_block != free_blocks.end()) - { - // get the pointer - result = free_block->second; - - // erase from the free_blocks map - free_blocks.erase(free_block); - } - else - { - // no allocation of the right size exists - // create a new one with m_base_allocator - // allocate memory and convert to raw pointer - result = thrust::raw_pointer_cast(traits::allocate(m_base_allocator, num_bytes)); - } - - // insert the allocated pointer into the allocated_blocks map - allocated_blocks.insert(std::make_pair(result, num_bytes)); - - return result; - } - - void deallocate(void *ptr) - { - // erase the allocated block from the allocated blocks map - allocated_blocks_type::iterator iter = allocated_blocks.find(ptr); - std::ptrdiff_t num_bytes = iter->second; - allocated_blocks.erase(iter); - - // insert the block into the free blocks map - free_blocks.insert(std::make_pair(num_bytes, ptr)); - } -}; - - -// overload get_temporary_buffer on cached_temporary_allocator -// note that we take a reference to cached_temporary_allocator -template class BasePolicy> - thrust::pair - get_temporary_buffer(cached_temporary_allocator &alloc, std::ptrdiff_t n) -{ - // ask the allocator for sizeof(T) * n bytes - T* result = reinterpret_cast(alloc.allocate(sizeof(T) * n)); - - // return the pointer and the number of elements allocated - return thrust::make_pair(result,n); -} - - -// overload return_temporary_buffer on cached_temporary_allocator -// an overloaded return_temporary_buffer should always accompany -// an overloaded get_temporary_buffer -template class BasePolicy> - void return_temporary_buffer(cached_temporary_allocator &alloc, Pointer p) -{ - // return the pointer to the allocator - alloc.deallocate(thrust::raw_pointer_cast(p)); -} - - -} // end detail -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/detail/fast_scan.h b/compat/thrust/system/cuda/detail/detail/fast_scan.h deleted file mode 100644 index d095a4a..0000000 --- a/compat/thrust/system/cuda/detail/detail/fast_scan.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file fast_scan.h - * \brief A fast scan for primitive types. - */ - -#pragma once - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace fast_scan -{ - -template -OutputIterator inclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryFunction binary_op); - -template -OutputIterator exclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - const T init, - BinaryFunction binary_op); - -} // end namespace fast_scan -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include "fast_scan.inl" - diff --git a/compat/thrust/system/cuda/detail/detail/fast_scan.inl b/compat/thrust/system/cuda/detail/detail/fast_scan.inl deleted file mode 100644 index b02763d..0000000 --- a/compat/thrust/system/cuda/detail/detail/fast_scan.inl +++ /dev/null @@ -1,753 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - - -namespace thrust -{ -namespace detail -{ - -// forward declaration of temporary_array -template class temporary_array; - -} // end detail - -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace fast_scan -{ -namespace fast_scan_detail -{ - - -// TODO tune this -template -struct inclusive_scan_block_size -{ - private: - static const unsigned int max_memory = 16384 - 256 - 2 * sizeof(ValueType); - static const unsigned int max_block_size = max_memory / sizeof(ValueType); - static const unsigned int default_block_size = 7 * 32; - static const unsigned int block_size = (max_block_size < default_block_size) ? max_block_size : default_block_size; - - public: - static const unsigned int pass1 = block_size; - static const unsigned int pass2 = block_size; - static const unsigned int pass3 = block_size; -}; - -// TODO tune this -template -struct exclusive_scan_block_size -{ - private: - static const unsigned int max_memory = 16384 - 256 - 2 * sizeof(ValueType); - static const unsigned int max_block_size = max_memory / sizeof(ValueType); - static const unsigned int default_block_size = 5 * 32; - static const unsigned int block_size = (max_block_size < default_block_size) ? max_block_size : default_block_size; - - public: - static const unsigned int pass1 = block_size; - static const unsigned int pass2 = block_size; - static const unsigned int pass3 = block_size; -}; - - -template -__device__ __thrust_forceinline__ -void scan_block(Context context, SharedArray array, BinaryFunction binary_op) -{ - typedef typename thrust::iterator_value::type T; - - T val = array[context.thread_index()]; - - if (CTA_SIZE > 1) { if(context.thread_index() >= 1) { T tmp = array[context.thread_index() - 1]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 2) { if(context.thread_index() >= 2) { T tmp = array[context.thread_index() - 2]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 4) { if(context.thread_index() >= 4) { T tmp = array[context.thread_index() - 4]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 8) { if(context.thread_index() >= 8) { T tmp = array[context.thread_index() - 8]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 16) { if(context.thread_index() >= 16) { T tmp = array[context.thread_index() - 16]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 32) { if(context.thread_index() >= 32) { T tmp = array[context.thread_index() - 32]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 64) { if(context.thread_index() >= 64) { T tmp = array[context.thread_index() - 64]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 128) { if(context.thread_index() >= 128) { T tmp = array[context.thread_index() - 128]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 256) { if(context.thread_index() >= 256) { T tmp = array[context.thread_index() - 256]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 512) { if(context.thread_index() >= 512) { T tmp = array[context.thread_index() - 512]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 1024) { if(context.thread_index() >= 1024) { T tmp = array[context.thread_index() - 1024]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } -} - -template -__device__ __thrust_forceinline__ -void scan_block_n(Context context, SharedArray array, const unsigned int n, BinaryFunction binary_op) -{ - typedef typename thrust::iterator_value::type T; - - T val = array[context.thread_index()]; - - if (CTA_SIZE > 1) { if(context.thread_index() < n && context.thread_index() >= 1) { T tmp = array[context.thread_index() - 1]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 2) { if(context.thread_index() < n && context.thread_index() >= 2) { T tmp = array[context.thread_index() - 2]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 4) { if(context.thread_index() < n && context.thread_index() >= 4) { T tmp = array[context.thread_index() - 4]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 8) { if(context.thread_index() < n && context.thread_index() >= 8) { T tmp = array[context.thread_index() - 8]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 16) { if(context.thread_index() < n && context.thread_index() >= 16) { T tmp = array[context.thread_index() - 16]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 32) { if(context.thread_index() < n && context.thread_index() >= 32) { T tmp = array[context.thread_index() - 32]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 64) { if(context.thread_index() < n && context.thread_index() >= 64) { T tmp = array[context.thread_index() - 64]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 128) { if(context.thread_index() < n && context.thread_index() >= 128) { T tmp = array[context.thread_index() - 128]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 256) { if(context.thread_index() < n && context.thread_index() >= 256) { T tmp = array[context.thread_index() - 256]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 512) { if(context.thread_index() < n && context.thread_index() >= 512) { T tmp = array[context.thread_index() - 512]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } - if (CTA_SIZE > 1024) { if(context.thread_index() < n && context.thread_index() >= 1024) { T tmp = array[context.thread_index() - 1024]; val = binary_op(tmp, val); } context.barrier(); array[context.thread_index()] = val; context.barrier(); } -} - -template -__device__ __thrust_forceinline__ -void load_block(Context context, - const unsigned int n, - InputIterator input, - ValueType (&sdata)[K][CTA_SIZE + 1]) -{ - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = k*CTA_SIZE + context.thread_index(); - - if (FullBlock || offset < n) - { - InputIterator temp = input + offset; - sdata[offset % K][offset / K] = *temp; - } - } - - context.barrier(); -} - -template -__device__ __thrust_forceinline__ -void store_block(Context context, - const unsigned int n, - OutputIterator output, - ValueType (&sdata)[K][CTA_SIZE + 1], - ValueType& carry) -{ - if (Inclusive) - { - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = k*CTA_SIZE + context.thread_index(); - - if (FullBlock || offset < n) - { - OutputIterator temp = output + offset; - *temp = sdata[offset % K][offset / K]; - } - } - } - else - { - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = k*CTA_SIZE + context.thread_index(); - - if (FullBlock || offset < n) - { - OutputIterator temp = output + offset; - *temp = (offset == 0) ? carry : sdata[(offset - 1) % K][(offset - 1) / K]; - } - } - } -} - -template -__device__ __thrust_forceinline__ -void upsweep_body(Context context, - const unsigned int n, - const bool carry_in, - InputIterator input, - BinaryFunction binary_op, - ValueType (&sdata)[K][CTA_SIZE + 1], - ValueType& carry) -{ - // read data - load_block(context, n, input, sdata); - - // copy into local array - ValueType ldata[K]; - for (unsigned int k = 0; k < K; k++) - ldata[k] = sdata[k][context.thread_index()]; - - // carry in - if (context.thread_index() == 0 && carry_in) - { - // XXX WAR sm_10 issue - ValueType tmp = carry; - ldata[0] = binary_op(tmp, ldata[0]); - } - - // scan local values - for(unsigned int k = 1; k < K; k++) - { - const unsigned int offset = K * context.thread_index() + k; - - if (FullBlock || offset < n) - ldata[k] = binary_op(ldata[k-1],ldata[k]); - } - - sdata[K - 1][context.thread_index()] = ldata[K - 1]; - - context.barrier(); - - // second level scan - if (FullBlock && sizeof(ValueType) > 1) // TODO investigate why this WAR is necessary - scan_block(context, sdata[K - 1], binary_op); - else - scan_block_n(context, sdata[K - 1], n / K, binary_op); - - // store carry out - if (FullBlock) - { - if (context.thread_index() == CTA_SIZE - 1) - carry = sdata[K - 1][context.thread_index()]; - } - else - { - if (context.thread_index() == (n - 1) / K) - { - ValueType sum; - - for (unsigned int k = 0; k < K; k++) - if ((n - 1) % K == k) - sum = ldata[k]; - - if (context.thread_index() > 0) - { - // WAR sm_10 issue - ValueType tmp = sdata[K - 1][context.thread_index() - 1]; - sum = binary_op(tmp, sum); - } - - carry = sum; - } - } - - context.barrier(); -} - -template -__device__ __thrust_forceinline__ -void scan_body(Context context, - const unsigned int n, - const bool carry_in, - InputIterator input, - OutputIterator output, - BinaryFunction binary_op, - ValueType (&sdata)[K][CTA_SIZE + 1], - ValueType& carry) -{ - // read data - load_block(context, n, input, sdata); - - // copy into local array - ValueType ldata[K]; - for (unsigned int k = 0; k < K; k++) - ldata[k] = sdata[k][context.thread_index()]; - - // carry in - if (context.thread_index() == 0 && carry_in) - { - // XXX WAR sm_10 issue - ValueType tmp = carry; - ldata[0] = binary_op(tmp, ldata[0]); - } - - // scan local values - for(unsigned int k = 1; k < K; k++) - { - const unsigned int offset = K * context.thread_index() + k; - - if (FullBlock || offset < n) - ldata[k] = binary_op(ldata[k-1],ldata[k]); - } - - sdata[K - 1][context.thread_index()] = ldata[K - 1]; - - context.barrier(); - - // second level scan - if (FullBlock) - scan_block(context, sdata[K - 1], binary_op); - else - scan_block_n(context, sdata[K - 1], n / K, binary_op); - - // update local values - if (context.thread_index() > 0) - { - ValueType left = sdata[K - 1][context.thread_index() - 1]; - - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = K * context.thread_index() + k; - - if (FullBlock || offset < n) - ldata[k] = binary_op(left, ldata[k]); - } - } - - for (unsigned int k = 0; k < K; k++) - sdata[k][context.thread_index()] = ldata[k]; - - context.barrier(); - - // write data - store_block(context, n, output, sdata, carry); - - // store carry out - if (context.thread_index() == 0) - { - if (FullBlock) - carry = sdata[K - 1][CTA_SIZE - 1]; - else - carry = sdata[(n - 1) % K][(n - 1) / K]; // note: this must come after the local update - } - - context.barrier(); -} - -template -struct upsweep_intervals_closure -{ - InputIterator input; - ValueType * block_results; // TODO change this to ValueIterator - BinaryFunction binary_op; - Decomposition decomp; - Context context; - - typedef Context context_type; - - upsweep_intervals_closure(InputIterator input, - ValueType * block_results, - BinaryFunction binary_op, - Decomposition decomp, - Context context = Context()) - : input(input), block_results(block_results), binary_op(binary_op), decomp(decomp), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename Decomposition::index_type IndexType; - - const unsigned int CTA_SIZE = context_type::ThreadsPerBlock::value; - -#if __CUDA_ARCH__ >= 200 - const unsigned int SMEM = (48 * 1024); -#else - const unsigned int SMEM = (16 * 1024) - 256; -#endif - const unsigned int MAX_K = ((SMEM - 1 * sizeof(ValueType)) / (sizeof(ValueType) * (CTA_SIZE + 1))); - const unsigned int K = (MAX_K < 6) ? MAX_K : 6; - - __shared__ uninitialized sdata; // padded to avoid bank conflicts - - __shared__ uninitialized carry; // storage for carry out - if(context.thread_index() == 0) carry.construct(); - - context.barrier(); - - thrust::system::detail::internal::index_range interval = decomp[context.block_index()]; - - IndexType base = interval.begin(); - - input += base; - - const unsigned int unit_size = K * CTA_SIZE; - - bool carry_in = false; - - // process full units - while (base + unit_size <= interval.end()) - { - const unsigned int n = unit_size; - upsweep_body(context, n, carry_in, input, binary_op, sdata.get(), carry.get()); - base += unit_size; - input += unit_size; - carry_in = true; - } - - // process partially full unit at end of input (if necessary) - if (base < interval.end()) - { - const unsigned int n = interval.end() - base; - upsweep_body(context, n, carry_in, input, binary_op, sdata.get(), carry.get()); - } - - // write interval sum - if (context.thread_index() == 0) - block_results[context.block_index()] = carry; - } -}; - - -template -struct downsweep_intervals_closure -{ - InputIterator input; - OutputIterator output; - ValueType * block_results; - BinaryFunction binary_op; - Decomposition decomp; - Context context; - - typedef Context context_type; - - downsweep_intervals_closure(InputIterator input, - OutputIterator output, - ValueType * block_results, - BinaryFunction binary_op, - Decomposition decomp, - Context context = Context()) - : input(input), output(output), block_results(block_results), binary_op(binary_op), decomp(decomp), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename Decomposition::index_type IndexType; - - const unsigned int CTA_SIZE = context_type::ThreadsPerBlock::value; - -#if __CUDA_ARCH__ >= 200 - const unsigned int SMEM = (48 * 1024); -#else - const unsigned int SMEM = (16 * 1024) - 256; -#endif - const unsigned int MAX_K = ((SMEM - 1 * sizeof(ValueType))/ (sizeof(ValueType) * (CTA_SIZE + 1))); - const unsigned int K = (MAX_K < 6) ? MAX_K : 6; - - __shared__ uninitialized sdata; // padded to avoid bank conflicts - - __shared__ uninitialized carry; // storage for carry in and carry out - if(context.thread_index() == 0) carry.construct(); - - context.barrier(); - - thrust::system::detail::internal::index_range interval = decomp[context.block_index()]; - - IndexType base = interval.begin(); - - input += base; - output += base; - - const unsigned int unit_size = K * CTA_SIZE; - - bool carry_in = (Inclusive && context.block_index() == 0) ? false : true; - - if (carry_in) - { - if (context.thread_index() == 0) - carry = block_results[context.block_index()]; - context.barrier(); - } - - // process full units - while (base + unit_size <= interval.end()) - { - const unsigned int n = unit_size; - scan_body(context, n, carry_in, input, output, binary_op, sdata.get(), carry.get()); - base += K * CTA_SIZE; - input += K * CTA_SIZE; - output += K * CTA_SIZE; - carry_in = true; - } - - // process partially full unit at end of input (if necessary) - if (base < interval.end()) - { - const unsigned int n = interval.end() - base; - scan_body(context, n, carry_in, input, output, binary_op, sdata.get(), carry.get()); - } - } -}; - - -} // end namespace fast_scan_detail - - -template -OutputIterator inclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryFunction binary_op) -{ - using namespace fast_scan_detail; - - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - typedef typename thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - typedef unsigned int IndexType; - typedef thrust::system::detail::internal::uniform_decomposition Decomposition; - typedef thrust::detail::temporary_array ValueArray; - - if (first == last) - return output; - - Decomposition decomp = thrust::system::cuda::detail::default_decomposition(last - first); - - ValueArray block_results(exec, decomp.size()); - - // compute sum over each interval - if (thrust::detail::is_commutative::value) - { - // use reduce_intervals for commutative operators - thrust::system::cuda::detail::reduce_intervals(exec, first, block_results.begin(), binary_op, decomp); - } - else - { - const static unsigned int ThreadsPerBlock = inclusive_scan_block_size::pass1; - typedef detail::statically_blocked_thread_array Context; - - typedef upsweep_intervals_closure Closure; - Closure closure(first, - thrust::raw_pointer_cast(&block_results[0]), - binary_op, - decomp); - detail::launch_closure(closure, decomp.size(), ThreadsPerBlock); - } - - // second level inclusive scan of per-block results - { - const static unsigned int ThreadsPerBlock = inclusive_scan_block_size::pass2; - typedef detail::statically_blocked_thread_array Context; - - typedef downsweep_intervals_closure Closure; - Closure closure(thrust::raw_pointer_cast(&block_results[0]), - thrust::raw_pointer_cast(&block_results[0]), - thrust::raw_pointer_cast(&block_results[0]), // not used - binary_op, - Decomposition(decomp.size(), 1, 1)); - detail::launch_closure(closure, 1, ThreadsPerBlock); - } - - // update intervals with result of second level scan - { - const static unsigned int ThreadsPerBlock = inclusive_scan_block_size::pass3; - typedef detail::statically_blocked_thread_array Context; - - typedef downsweep_intervals_closure Closure; - Closure closure(first, - output, - thrust::raw_pointer_cast(&block_results[0]) - 1, // shift block results - binary_op, - decomp); - detail::launch_closure(closure, decomp.size(), ThreadsPerBlock); - } - - return output + (last - first); -} - - -template -OutputIterator exclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - const T init, - BinaryFunction binary_op) -{ - using namespace fast_scan_detail; - - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - typedef typename thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - typedef unsigned int IndexType; - typedef thrust::system::detail::internal::uniform_decomposition Decomposition; - typedef thrust::detail::temporary_array ValueArray; - - if (first == last) - return output; - - Decomposition decomp = thrust::system::cuda::detail::default_decomposition(last - first); - - ValueArray block_results(exec, decomp.size() + 1); - - // compute sum over each interval - if (thrust::detail::is_commutative::value) - { - // use reduce_intervals for commutative operators - thrust::system::cuda::detail::reduce_intervals(exec, first, block_results.begin() + 1, binary_op, decomp); - } - else - { - const static unsigned int ThreadsPerBlock = exclusive_scan_block_size::pass1; - typedef detail::statically_blocked_thread_array Context; - - typedef upsweep_intervals_closure Closure; - Closure closure(first, - thrust::raw_pointer_cast(&block_results[0]) + 1, - binary_op, - decomp); - detail::launch_closure(closure, decomp.size(), ThreadsPerBlock); - } - - // place init before per-block results - block_results[0] = init; - - // second level inclusive scan of per-block results - { - const static unsigned int ThreadsPerBlock = exclusive_scan_block_size::pass2; - typedef detail::statically_blocked_thread_array Context; - - typedef downsweep_intervals_closure Closure; - Closure closure(thrust::raw_pointer_cast(&block_results[0]), - thrust::raw_pointer_cast(&block_results[0]), - thrust::raw_pointer_cast(&block_results[0]), // not used - binary_op, - Decomposition(decomp.size() + 1, 1, 1)); - detail::launch_closure(closure, 1, ThreadsPerBlock); - } - - // update intervals with result of second level scan - { - const static unsigned int ThreadsPerBlock = exclusive_scan_block_size::pass3; - typedef detail::statically_blocked_thread_array Context; - - typedef downsweep_intervals_closure Closure; - Closure closure(first, - output, - thrust::raw_pointer_cast(&block_results[0]), // shift block results - binary_op, - decomp); - detail::launch_closure(closure, decomp.size(), ThreadsPerBlock); - } - - return output + (last - first); -} - - -} // end namespace fast_scan -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - diff --git a/compat/thrust/system/cuda/detail/detail/launch_calculator.h b/compat/thrust/system/cuda/detail/detail/launch_calculator.h deleted file mode 100644 index 5126aa6..0000000 --- a/compat/thrust/system/cuda/detail/detail/launch_calculator.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -class launch_calculator -{ - device_properties_t properties; - function_attributes_t attributes; - - public: - - launch_calculator(void); - - launch_calculator(const device_properties_t& properties, const function_attributes_t& attributes); - - thrust::tuple with_variable_block_size(void) const; - - template - thrust::tuple with_variable_block_size(UnaryFunction block_size_to_smem_size) const; - - thrust::tuple with_variable_block_size_available_smem(void) const; - - private: - - /*! Returns a pair (num_threads_per_block, num_blocks_per_multiprocessor) - * where num_threads_per_block is a valid block size for an instance of Closure - * chosen by a heuristic and num_blocks_per_multiprocessor is the maximum - * number of such blocks that can execute on a streaming multiprocessor at once. - */ - thrust::pair default_block_configuration() const; - - /*! Returns a pair (num_threads_per_block, num_blocks_per_multiprocessor) - * where num_threads_per_block is a valid block size for an instance of Closure - * chosen by a heuristic and num_blocks_per_multiprocessor is the maximum - * number of such blocks that can execute on a streaming multiprocessor at once. - * - * \param block_size_to_smem_size Mapping from num_threads_per_block to number of - * dynamically-allocated bytes of shared memory - */ - template - thrust::pair default_block_configuration(UnaryFunction block_size_to_smem_size) const; -}; - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/launch_calculator.inl b/compat/thrust/system/cuda/detail/detail/launch_calculator.inl deleted file mode 100644 index b851d5f..0000000 --- a/compat/thrust/system/cuda/detail/detail/launch_calculator.inl +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// do not attempt to compile this file with any other compiler -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -launch_calculator::launch_calculator(void) - : properties(device_properties()), - attributes(closure_attributes()) -{} - -template -launch_calculator::launch_calculator(const device_properties_t& properties, const function_attributes_t& attributes) - : properties(properties), - attributes(attributes) -{} - -template - template -thrust::pair launch_calculator::default_block_configuration(UnaryFunction block_size_to_smem_size) const -{ - // choose a block size - std::size_t num_threads_per_block = block_size_with_maximum_potential_occupancy(attributes, properties, block_size_to_smem_size); - - // choose a subscription rate - std::size_t num_blocks_per_multiprocessor = properties.maxThreadsPerMultiProcessor / num_threads_per_block; - - return thrust::make_pair(num_threads_per_block, num_blocks_per_multiprocessor); -} - - -template -thrust::pair launch_calculator::default_block_configuration(void) const -{ - // choose a block size - std::size_t num_threads_per_block = block_size_with_maximum_potential_occupancy(attributes, properties); - - // choose a subscription rate - std::size_t num_blocks_per_multiprocessor = properties.maxThreadsPerMultiProcessor / num_threads_per_block; - - return thrust::make_pair(num_threads_per_block, num_blocks_per_multiprocessor); -} - -template -thrust::tuple launch_calculator::with_variable_block_size(void) const -{ - thrust::pair config = default_block_configuration(); - return thrust::tuple(config.second * properties.multiProcessorCount, config.first, 0); -} - -template - template -thrust::tuple launch_calculator::with_variable_block_size(UnaryFunction block_size_to_smem_size) const -{ - thrust::pair config = default_block_configuration(block_size_to_smem_size); - return thrust::tuple(config.second * properties.multiProcessorCount, config.first, block_size_to_smem_size(config.first)); -} - -template -thrust::tuple launch_calculator::with_variable_block_size_available_smem(void) const -{ - thrust::pair config = default_block_configuration(); - size_t smem_per_block = proportional_smem_allocation(properties, attributes, config.second); - return thrust::tuple(config.second * properties.multiProcessorCount, config.first, smem_per_block); -} - -} // end detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - diff --git a/compat/thrust/system/cuda/detail/detail/launch_closure.h b/compat/thrust/system/cuda/detail/detail/launch_closure.h deleted file mode 100644 index c2e6c43..0000000 --- a/compat/thrust/system/cuda/detail/detail/launch_closure.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -struct launch_bounds -{ - typedef thrust::detail::integral_constant ThreadsPerBlock; - typedef thrust::detail::integral_constant BlocksPerMultiprocessor; -}; - -struct thread_array : public launch_bounds<> -{ -// CUDA built-in variables require nvcc -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - __device__ __thrust_forceinline__ unsigned int thread_index(void) const { return threadIdx.x; } - __device__ __thrust_forceinline__ unsigned int thread_count(void) const { return blockDim.x * gridDim.x; } -#else - __device__ __thrust_forceinline__ unsigned int thread_index(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int thread_count(void) const { return 0; } -#endif // THRUST_DEVICE_COMPILER_NVCC -}; - -struct blocked_thread_array : public launch_bounds<> -{ -// CUDA built-in variables require nvcc -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - __device__ __thrust_forceinline__ unsigned int thread_index(void) const { return threadIdx.x; } - __device__ __thrust_forceinline__ unsigned int block_dimension(void) const { return blockDim.x; } - __device__ __thrust_forceinline__ unsigned int block_index(void) const { return blockIdx.x; } - __device__ __thrust_forceinline__ unsigned int grid_dimension(void) const { return gridDim.x; } - __device__ __thrust_forceinline__ unsigned int linear_index(void) const { return block_dimension() * block_index() + thread_index(); } - __device__ __thrust_forceinline__ void barrier(void) { __syncthreads(); } -#else - __device__ __thrust_forceinline__ unsigned int thread_index(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int block_dimension(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int block_index(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int grid_dimension(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int linear_index(void) const { return 0; } - __device__ __thrust_forceinline__ void barrier(void) { } -#endif // THRUST_DEVICE_COMPILER_NVCC -}; - -template -struct statically_blocked_thread_array : public launch_bounds<_ThreadsPerBlock,1> -{ -// CUDA built-in variables require nvcc -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - __device__ __thrust_forceinline__ unsigned int thread_index(void) const { return threadIdx.x; } - __device__ __thrust_forceinline__ unsigned int block_dimension(void) const { return _ThreadsPerBlock; } // minor optimization - __device__ __thrust_forceinline__ unsigned int block_index(void) const { return blockIdx.x; } - __device__ __thrust_forceinline__ unsigned int grid_dimension(void) const { return gridDim.x; } - __device__ __thrust_forceinline__ unsigned int linear_index(void) const { return block_dimension() * block_index() + thread_index(); } - __device__ __thrust_forceinline__ void barrier(void) { __syncthreads(); } -#else - __device__ __thrust_forceinline__ unsigned int thread_index(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int block_dimension(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int block_index(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int grid_dimension(void) const { return 0; } - __device__ __thrust_forceinline__ unsigned int linear_index(void) const { return 0; } - __device__ __thrust_forceinline__ void barrier(void) { } -#endif // THRUST_DEVICE_COMPILER_NVCC -}; - -template - void launch_closure(Closure f, Size1 num_blocks, Size2 block_size); - -template - void launch_closure(Closure f, Size1 num_blocks, Size2 block_size, Size3 smem_size); - -/*! Returns a copy of the cudaFuncAttributes structure - * that is associated with a given Closure - */ -template -function_attributes_t closure_attributes(void); - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/launch_closure.inl b/compat/thrust/system/cuda/detail/detail/launch_closure.inl deleted file mode 100644 index ce39cfc..0000000 --- a/compat/thrust/system/cuda/detail/detail/launch_closure.inl +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace detail -{ - -// XXX WAR circular inclusion problems with this forward declaration -template class temporary_array; - -} // end detail - -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC -template -__global__ __launch_bounds__(Closure::context_type::ThreadsPerBlock::value, Closure::context_type::BlocksPerMultiprocessor::value) -void launch_closure_by_value(Closure f) -{ - f(); -} - -template -__global__ __launch_bounds__(Closure::context_type::ThreadsPerBlock::value, Closure::context_type::BlocksPerMultiprocessor::value) -void launch_closure_by_pointer(const Closure *f) -{ - // copy to registers - Closure f_reg = *f; - f_reg(); -} -#else -template -void launch_closure_by_value(Closure) {} - -template -void launch_closure_by_pointer(const Closure *) {} - -#endif // THRUST_DEVICE_COMPILER_NVCC - -template - struct closure_launcher_base -{ - typedef void (*launch_function_t)(Closure); - - static launch_function_t get_launch_function(void) - { - return launch_closure_by_value; - } - - template - static void launch(Closure f, Size1 num_blocks, Size2 block_size, Size3 smem_size) - { -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - if(num_blocks > 0) - { - launch_closure_by_value<<<(unsigned int) num_blocks, (unsigned int) block_size, (unsigned int) smem_size>>>(f); - synchronize_if_enabled("launch_closure_by_value"); - } -#endif // THRUST_DEVICE_COMPILER_NVCC - } -}; // end closure_launcher_base - - -template - struct closure_launcher_base -{ - typedef void (*launch_function_t)(const Closure *); - - static launch_function_t get_launch_function(void) - { - return launch_closure_by_pointer; - } - - template - static void launch(Closure f, Size1 num_blocks, Size2 block_size, Size3 smem_size) - { -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - if(num_blocks > 0) - { - // use temporary storage for the closure - // XXX use of cuda::tag is too specific here - thrust::cuda::tag cuda_tag; - thrust::host_system_tag host_tag; - thrust::detail::temporary_array closure_storage(cuda_tag, host_tag, &f, &f + 1); - - // launch - detail::launch_closure_by_pointer<<<(unsigned int) num_blocks, (unsigned int) block_size, (unsigned int) smem_size>>>((&closure_storage[0]).get()); - synchronize_if_enabled("launch_closure_by_pointer"); - } -#endif // THRUST_DEVICE_COMPILER_NVCC - } -}; - - -template - struct closure_launcher - : public closure_launcher_base -{ - typedef closure_launcher_base super_t; - - static inline const device_properties_t& device_properties(void) - { - return device_properties(); - } - - static inline function_attributes_t function_attributes(void) - { - return thrust::system::cuda::detail::function_attributes(super_t::get_launch_function()); - } - - template - static void launch(Closure f, Size1 num_blocks, Size2 block_size, Size3 smem_size) - { - super_t::launch(f,num_blocks,block_size,smem_size); - } -}; - -template - void launch_closure(Closure f, Size num_blocks) -{ - launch_calculator calculator; - launch_closure(f, num_blocks, thrust::get<1>(calculator.with_variable_block_size())); -} // end launch_closure() - -template - void launch_closure(Closure f, Size1 num_blocks, Size2 block_size) -{ - launch_closure(f, num_blocks, block_size, 0u); -} // end launch_closure() - -template - void launch_closure(Closure f, Size1 num_blocks, Size2 block_size, Size3 smem_size) -{ - closure_launcher::launch(f, num_blocks, block_size, smem_size); -} // end launch_closure() - - -template -function_attributes_t closure_attributes(void) -{ - typedef closure_launcher Launcher; - - // cache the result of function_attributes(), because it is slow - // only cache the first few devices - static const int max_num_devices = 16; - - static bool attributes_exist[max_num_devices] = {0}; - static function_attributes_t function_attributes[max_num_devices] = {}; - - // XXX device_id ought to be an argument to this function - int device_id = current_device(); - - if(device_id >= max_num_devices) - { - return thrust::system::cuda::detail::function_attributes(Launcher::get_launch_function()); - } - - if(!attributes_exist[device_id]) - { - function_attributes[device_id] = thrust::system::cuda::detail::function_attributes(Launcher::get_launch_function()); - - // disallow the compiler to move the write to attributes_exist[device_id] - // before the initialization of function_attributes[device_id] - __thrust_compiler_fence(); - - attributes_exist[device_id] = true; - } - - return function_attributes[device_id]; -} - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/set_operation.h b/compat/thrust/system/cuda/detail/detail/set_operation.h deleted file mode 100644 index 5475731..0000000 --- a/compat/thrust/system/cuda/detail/detail/set_operation.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template - RandomAccessIterator3 set_operation(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp, - SetOperation set_op); - - -} // end detail -} // end detail -} // end cuda -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/set_operation.inl b/compat/thrust/system/cuda/detail/detail/set_operation.inl deleted file mode 100644 index 3f14379..0000000 --- a/compat/thrust/system/cuda/detail/detail/set_operation.inl +++ /dev/null @@ -1,639 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace set_operation_detail -{ - - -using thrust::system::cuda::detail::detail::statically_blocked_thread_array; -using thrust::detail::uint16_t; -using thrust::detail::uint32_t; - - -// empirically determined on sm_20 -// value_types larger than this will fail to launch if placed in smem -template - struct stage_through_smem -{ - static const bool value = sizeof(T) <= 6 * sizeof(uint32_t); -}; - - -// max_input_size <= 32 -template -inline __device__ - OutputIterator serial_bounded_copy_if(Size max_input_size, - InputIterator first, - uint32_t mask, - OutputIterator result) -{ - for(Size i = 0; i < max_input_size; ++i, ++first) - { - if((1< - struct find_partition_offsets_functor -{ - Size partition_size; - InputIterator1 first1; - InputIterator2 first2; - Size n1, n2; - Compare comp; - - find_partition_offsets_functor(Size partition_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - Compare comp) - : partition_size(partition_size), - first1(first1), first2(first2), - n1(last1 - first1), n2(last2 - first2), - comp(comp) - {} - - inline __host__ __device__ - thrust::pair operator()(Size i) const - { - Size diag = thrust::min(n1 + n2, i * partition_size); - - // XXX the correctness of balanced_path depends critically on the ll suffix below - // why??? - return balanced_path(first1, n1, first2, n2, diag, 4ll, comp); - } -}; - - -template - OutputIterator find_partition_offsets(thrust::cuda::execution_policy &exec, - Size num_partitions, - Size partition_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp) -{ - find_partition_offsets_functor f(partition_size, first1, last1, first2, last2, comp); - - return thrust::transform(exec, - thrust::counting_iterator(0), - thrust::counting_iterator(num_partitions), - result, - f); -} - - -namespace block -{ - - -template -inline __device__ -T right_neighbor(statically_blocked_thread_array &ctx, const T &x, const T &boundary) -{ - // stage this shift to conserve smem - const unsigned int storage_size = block_size / 2; - __shared__ uninitialized_array shared; - - T result = x; - - unsigned int tid = ctx.thread_index(); - - if(0 < tid && tid <= storage_size) - { - shared[tid - 1] = x; - } - - ctx.barrier(); - - if(tid < storage_size) - { - result = shared[tid]; - } - - ctx.barrier(); - - tid -= storage_size; - if(0 < tid && tid <= storage_size) - { - shared[tid - 1] = x; - } - else if(tid == 0) - { - shared[storage_size-1] = boundary; - } - - ctx.barrier(); - - if(tid < storage_size) - { - result = shared[tid]; - } - - ctx.barrier(); - - return result; -} - - -template -inline __device__ - unsigned int bounded_count_set_operation_n(statically_blocked_thread_array &ctx, - InputIterator1 first1, uint16_t n1, - InputIterator2 first2, uint16_t n2, - Compare comp, - SetOperation set_op) -{ - unsigned int thread_idx = ctx.thread_index(); - - // find partition offsets - uint16_t diag = thrust::min(n1 + n2, thread_idx * work_per_thread); - thrust::pair thread_input_begin = balanced_path(first1, n1, first2, n2, diag, 2, comp); - thrust::pair thread_input_end = block::right_neighbor(ctx, thread_input_begin, thrust::make_pair(n1,n2)); - - __shared__ uint16_t s_thread_output_size[block_size]; - - // work_per_thread + 1 to accomodate a "starred" partition returned from balanced_path above - s_thread_output_size[thread_idx] = - set_op.count(work_per_thread + 1, - first1 + thread_input_begin.first, first1 + thread_input_end.first, - first2 + thread_input_begin.second, first2 + thread_input_end.second, - comp); - - ctx.barrier(); - - // reduce per-thread counts - thrust::system::cuda::detail::block::inplace_inclusive_scan(ctx, s_thread_output_size); - return s_thread_output_size[ctx.block_dimension() - 1]; -} - - -inline __device__ int pop_count(unsigned int x) -{ -// guard use of __popc from other compilers -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - return __popc(x); -#else - return x; -#endif -} - - - -template -inline __device__ - OutputIterator bounded_set_operation_n(statically_blocked_thread_array &ctx, - InputIterator1 first1, uint16_t n1, - InputIterator2 first2, uint16_t n2, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - unsigned int thread_idx = ctx.thread_index(); - - // find partition offsets - uint16_t diag = thrust::min(n1 + n2, thread_idx * work_per_thread); - thrust::pair thread_input_begin = balanced_path(first1, n1, first2, n2, diag, 2, comp); - thrust::pair thread_input_end = block::right_neighbor(ctx, thread_input_begin, thrust::make_pair(n1,n2)); - - typedef typename thrust::iterator_value::type value_type; - // +1 to accomodate a "starred" partition returned from balanced_path above - uninitialized_array sparse_result; - uint32_t active_mask = - set_op(work_per_thread + 1, - first1 + thread_input_begin.first, first1 + thread_input_end.first, - first2 + thread_input_begin.second, first2 + thread_input_end.second, - sparse_result.begin(), - comp); - - __shared__ uint16_t s_thread_output_size[block_size]; - s_thread_output_size[thread_idx] = pop_count(active_mask); - - ctx.barrier(); - - // scan to turn per-thread counts into output indices - uint16_t block_output_size = thrust::system::cuda::detail::block::inplace_exclusive_scan(ctx, s_thread_output_size, 0u); - - serial_bounded_copy_if(work_per_thread + 1, sparse_result.begin(), active_mask, result + s_thread_output_size[thread_idx]); - - ctx.barrier(); - - return result + block_output_size; -} - - -template -inline __device__ - typename thrust::iterator_difference::type - count_set_operation(statically_blocked_thread_array &ctx, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - Compare comp, - SetOperation set_op) -{ - typedef typename thrust::iterator_difference::type difference; - - difference result = 0; - - thrust::pair remaining_input_size = thrust::make_pair(last1 - first1, last2 - first2); - - // iterate until the input is consumed - while(remaining_input_size.first + remaining_input_size.second > 0) - { - // find the end of this subpartition's input - // -1 to accomodate "starred" partitions - uint16_t max_subpartition_size = block_size * work_per_thread - 1; - difference diag = thrust::min(remaining_input_size.first + remaining_input_size.second, max_subpartition_size); - thrust::pair subpartition_size = balanced_path(first1, remaining_input_size.first, first2, remaining_input_size.second, diag, 4ll, comp); - - typedef typename thrust::iterator_value::type value_type; - if(stage_through_smem::value) - { - // load the input into __shared__ storage - __shared__ uninitialized_array s_input; - - value_type *s_input_end1 = thrust::system::cuda::detail::block::copy_n(ctx, first1, subpartition_size.first, s_input.begin()); - value_type *s_input_end2 = thrust::system::cuda::detail::block::copy_n(ctx, first2, subpartition_size.second, s_input_end1); - - result += block::bounded_count_set_operation_n(ctx, - s_input.begin(), subpartition_size.first, - s_input_end1, subpartition_size.second, - comp, - set_op); - } - else - { - result += block::bounded_count_set_operation_n(ctx, - first1, subpartition_size.first, - first2, subpartition_size.second, - comp, - set_op); - } - - // advance input - first1 += subpartition_size.first; - first2 += subpartition_size.second; - - // decrement remaining size - remaining_input_size.first -= subpartition_size.first; - remaining_input_size.second -= subpartition_size.second; - } - - return result; -} - - -template -inline __device__ -OutputIterator set_operation(statically_blocked_thread_array &ctx, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - typedef typename thrust::iterator_difference::type difference; - - thrust::pair remaining_input_size = thrust::make_pair(last1 - first1, last2 - first2); - - // iterate until the input is consumed - while(remaining_input_size.first + remaining_input_size.second > 0) - { - // find the end of this subpartition's input - // -1 to accomodate "starred" partitions - uint16_t max_subpartition_size = block_size * work_per_thread - 1; - difference diag = thrust::min(remaining_input_size.first + remaining_input_size.second, max_subpartition_size); - thrust::pair subpartition_size = balanced_path(first1, remaining_input_size.first, first2, remaining_input_size.second, diag, 4ll, comp); - - typedef typename thrust::iterator_value::type value_type; - if(stage_through_smem::value) - { - // load the input into __shared__ storage - __shared__ uninitialized_array s_input; - - value_type *s_input_end1 = thrust::system::cuda::detail::block::copy_n(ctx, first1, subpartition_size.first, s_input.begin()); - value_type *s_input_end2 = thrust::system::cuda::detail::block::copy_n(ctx, first2, subpartition_size.second, s_input_end1); - - result = block::bounded_set_operation_n(ctx, - s_input.begin(), subpartition_size.first, - s_input_end1, subpartition_size.second, - result, - comp, - set_op); - } - else - { - result = block::bounded_set_operation_n(ctx, - first1, subpartition_size.first, - first2, subpartition_size.second, - result, - comp, - set_op); - } - - // advance input - first1 += subpartition_size.first; - first2 += subpartition_size.second; - - // decrement remaining size - remaining_input_size.first -= subpartition_size.first; - remaining_input_size.second -= subpartition_size.second; - } - - return result; -} - - -} // end namespace block - - -template - inline __device__ void count_set_operation(statically_blocked_thread_array &ctx, - InputIterator1 input_partition_offsets, - Size num_partitions, - InputIterator2 first1, - InputIterator3 first2, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - // consume partitions - for(Size partition_idx = ctx.block_index(); - partition_idx < num_partitions; - partition_idx += ctx.grid_dimension()) - { - typedef typename thrust::iterator_difference::type difference; - - // find the partition - thrust::pair block_input_begin = input_partition_offsets[partition_idx]; - thrust::pair block_input_end = input_partition_offsets[partition_idx + 1]; - - // count the size of the set operation - difference count = block::count_set_operation(ctx, - first1 + block_input_begin.first, first1 + block_input_end.first, - first2 + block_input_begin.second, first2 + block_input_end.second, - comp, - set_op); - - if(ctx.thread_index() == 0) - { - result[partition_idx] = count; - } - } -} - - -template - struct count_set_operation_closure -{ - typedef statically_blocked_thread_array context_type; - - InputIterator1 input_partition_offsets; - Size num_partitions; - InputIterator2 first1; - InputIterator3 first2; - OutputIterator result; - Compare comp; - SetOperation set_op; - - count_set_operation_closure(InputIterator1 input_partition_offsets, - Size num_partitions, - InputIterator2 first1, - InputIterator3 first2, - OutputIterator result, - Compare comp, - SetOperation set_op) - : input_partition_offsets(input_partition_offsets), - num_partitions(num_partitions), - first1(first1), - first2(first2), - result(result), - comp(comp), - set_op(set_op) - {} - - inline __device__ void operator()() const - { - context_type ctx; - count_set_operation(ctx, input_partition_offsets, num_partitions, first1, first2, result, comp, set_op); - } -}; - - -template - count_set_operation_closure - make_count_set_operation_closure(InputIterator1 input_partition_offsets, - Size num_partitions, - InputIterator2 first1, - InputIterator3 first2, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - typedef count_set_operation_closure result_type; - return result_type(input_partition_offsets,num_partitions,first1,first2,result,comp,set_op); -} - - -template -inline __device__ - void set_operation(statically_blocked_thread_array &ctx, - InputIterator1 input_partition_offsets, - Size num_partitions, - InputIterator2 first1, - InputIterator3 first2, - InputIterator4 output_partition_offsets, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - // consume partitions - for(Size partition_idx = ctx.block_index(); - partition_idx < num_partitions; - partition_idx += ctx.grid_dimension()) - { - typedef typename thrust::iterator_difference::type difference; - - // find the partition - thrust::pair block_input_begin = input_partition_offsets[partition_idx]; - thrust::pair block_input_end = input_partition_offsets[partition_idx + 1]; - - // do the set operation across the partition - block::set_operation(ctx, - first1 + block_input_begin.first, first1 + block_input_end.first, - first2 + block_input_begin.second, first2 + block_input_end.second, - result + output_partition_offsets[partition_idx], - comp, - set_op); - } -} - - -template - struct set_operation_closure -{ - typedef statically_blocked_thread_array context_type; - - InputIterator1 input_partition_offsets; - Size num_partitions; - InputIterator2 first1; - InputIterator3 first2; - InputIterator4 output_partition_offsets; - OutputIterator result; - Compare comp; - SetOperation set_op; - - set_operation_closure(InputIterator1 input_partition_offsets, - Size num_partitions, - InputIterator2 first1, - InputIterator3 first2, - InputIterator4 output_partition_offsets, - OutputIterator result, - Compare comp, - SetOperation set_op) - : input_partition_offsets(input_partition_offsets), - num_partitions(num_partitions), - first1(first1), - first2(first2), - output_partition_offsets(output_partition_offsets), - result(result), - comp(comp), - set_op(set_op) - {} - - inline __device__ void operator()() const - { - context_type ctx; - set_operation(ctx, input_partition_offsets, num_partitions, first1, first2, output_partition_offsets, result, comp, set_op); - } -}; - - -template - set_operation_closure - make_set_operation_closure(InputIterator1 input_partition_offsets, - Size num_partitions, - InputIterator2 first1, - InputIterator3 first2, - InputIterator4 output_partition_offsets, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - typedef set_operation_closure result_type; - return result_type(input_partition_offsets,num_partitions,first1,first2,output_partition_offsets,result,comp,set_op); -} - - -} // end namespace set_operation_detail - - -template - OutputIterator set_operation(thrust::cuda::execution_policy &exec, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp, - SetOperation set_op) -{ - using thrust::system::cuda::detail::device_properties; - using thrust::system::cuda::detail::detail::launch_closure; - namespace d = thrust::system::cuda::detail::detail::set_operation_detail; - - typedef typename thrust::iterator_difference::type difference; - - const difference n1 = last1 - first1; - const difference n2 = last2 - first2; - - // handle empty input - if(n1 == 0 && n2 == 0) - { - return result; - } - - const thrust::detail::uint16_t work_per_thread = 15; - const thrust::detail::uint16_t threads_per_block = 128; - const thrust::detail::uint16_t work_per_block = threads_per_block * work_per_thread; - - // -1 because balanced_path adds a single element to the end of a "starred" partition, increasing its size by one - const thrust::detail::uint16_t maximum_partition_size = work_per_block - 1; - const difference num_partitions = thrust::detail::util::divide_ri(n1 + n2, maximum_partition_size); - - // find input partition offsets - // +1 to handle the end of the input elegantly - thrust::detail::temporary_array, DerivedPolicy> input_partition_offsets(0, exec, num_partitions + 1); - d::find_partition_offsets(exec, input_partition_offsets.size(), maximum_partition_size, first1, last1, first2, last2, input_partition_offsets.begin(), comp); - - const difference num_blocks = thrust::min(device_properties().maxGridSize[0], num_partitions); - - // find output partition offsets - // +1 to store the total size of the total - thrust::detail::temporary_array output_partition_offsets(0, exec, num_partitions + 1); - launch_closure(d::make_count_set_operation_closure(input_partition_offsets.begin(), num_partitions, first1, first2, output_partition_offsets.begin(), comp, set_op), - num_blocks, - threads_per_block); - - // turn the output partition counts into offsets to output partitions - thrust::exclusive_scan(exec, output_partition_offsets.begin(), output_partition_offsets.end(), output_partition_offsets.begin()); - - // run the set op kernel - launch_closure(d::make_set_operation_closure(input_partition_offsets.begin(), num_partitions, first1, first2, output_partition_offsets.begin(), result, comp, set_op), - num_blocks, - threads_per_block); - - return result + output_partition_offsets[num_partitions]; -} - - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/stable_merge_sort.h b/compat/thrust/system/cuda/detail/detail/stable_merge_sort.h deleted file mode 100644 index 23f3254..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_merge_sort.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file stable_merge_sort_dev.h - * \brief Defines the interface for a stable merge implementation on CUDA - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -void stable_merge_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - -template -void stable_merge_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_begin, - RandomAccessIterator1 keys_end, - RandomAccessIterator2 values_begin, - StrictWeakOrdering comp); - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/stable_merge_sort.inl b/compat/thrust/system/cuda/detail/detail/stable_merge_sort.inl deleted file mode 100644 index 0c69803..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_merge_sort.inl +++ /dev/null @@ -1,1103 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file stable_merge_sort.inl - * \brief Inline file for stable_merge_sort.h. - * \note This algorithm is based on the one described - * in "Designing Efficient Sorting Algorithms for - * Manycore GPUs", by Satish, Harris, and Garland. - */ - -#include - -#include -#include - -#include - -#include // for log2 -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace stable_merge_sort_detail -{ - - -template - struct is_block_size_valid -{ - // assume sm_10 limits - static const unsigned int max_num_smem_bytes = 16384; - - // CUDA steals 256 for itself for kernel parms - static const unsigned int num_reserved_smem_bytes = 256; - - // the number of bytes available to our kernels - static const unsigned int num_available_smem_bytes = max_num_smem_bytes - num_reserved_smem_bytes; - - // merge_small_tiles_by_key_closure is the hungriest kernel - // the block_size it uses is 2x the size of all the other kernels - // this merge_small_tiles_by_key_closure's smem requirements: - // 2 * block_size_x2 * sizeof(Key) - // + 2 * block_size_x2 * sizeof(Key) - // + 2 * block_size_x2 * sizeof(Value) - // ================================ - // 4 * (block_size) * (2 * sizeof(Key) + sizeof(Value)) - static const unsigned int num_needed_smem_bytes = 4 * (1 << log_block_size) * (2 * sizeof(Key) + sizeof(Value)); - - static const bool value = num_needed_smem_bytes <= num_available_smem_bytes; -}; - - - -// choose a (log) block_size to use for our kernels -template - struct select_log_block_size - : thrust::detail::eval_if< - is_block_size_valid::value, - thrust::detail::integral_constant, - select_log_block_size - >::type -{}; - - -// don't recurse lower than block_size < 128 -template - struct select_log_block_size<6, Key, Value> -{ - // no block size exists which can satisfy the storage demands -}; - - -template - struct block_size -{ - // prefer block_size == 512, go lower if we need to - static const unsigned int value = 1 << select_log_block_size<8, Key, Value>::value; -}; - - -template -inline unsigned int max_grid_size(Size block_size) -{ - const device_properties_t& properties = device_properties(); - - const unsigned int max_threads = properties.maxThreadsPerMultiProcessor * properties.multiProcessorCount; - const unsigned int max_blocks = properties.maxGridSize[0]; - - return std::min(max_blocks, 3 * max_threads / block_size); -} // end max_grid_size() - - -// Base case for the merge algorithm: merges data where tile_size <= block_size. -// Works by loading two or more tiles into shared memory and doing a binary search. -template -struct merge_small_tiles_by_key_closure -{ - typedef Context context_type; - - RandomAccessIterator1 keys_first; - RandomAccessIterator2 values_first; - const unsigned int n; - const unsigned int log_tile_size; - RandomAccessIterator3 keys_result; - RandomAccessIterator4 values_result; - StrictWeakOrdering comp; - context_type context; - - // these members are derivable from block_size, n, and log_tile_size - unsigned int index_of_last_block; - unsigned int index_of_last_tile_in_last_block; - unsigned int size_of_last_tile; - - merge_small_tiles_by_key_closure - (RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - const unsigned int n, - const unsigned int log_tile_size, - RandomAccessIterator3 keys_result, - RandomAccessIterator4 values_result, - StrictWeakOrdering comp, - Context context = Context()) - : keys_first(keys_first), values_first(values_first), - n(n), - log_tile_size(log_tile_size), - keys_result(keys_result), values_result(values_result), - comp(comp), - context(context) - { - // compute the number of tiles, including a possible partial tile - unsigned int tile_size = 1 << log_tile_size; - unsigned int num_tiles = thrust::detail::util::divide_ri(n, tile_size); - unsigned int partial_tile_size = n % tile_size; - - // compute the number of logical thread blocks, including a possible partial block - unsigned int tiles_per_block = block_size / tile_size; - unsigned int num_blocks = thrust::detail::util::divide_ri(num_tiles, tiles_per_block); - unsigned int partial_block_size = num_tiles % tiles_per_block; - - // compute the number of tiles in the last block, which might be of partial size - unsigned int number_of_tiles_in_last_block = partial_block_size ? partial_block_size : tiles_per_block; - - size_of_last_tile = partial_tile_size ? partial_tile_size : tile_size; - index_of_last_tile_in_last_block = number_of_tiles_in_last_block - 1; - index_of_last_block = num_blocks - 1; - } - - unsigned int grid_size() const - { - const unsigned int max_num_blocks = max_grid_size(block_size); - const unsigned int num_logical_blocks = index_of_last_block + 1; - return thrust::min(num_logical_blocks, max_num_blocks); - } - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename iterator_value::type KeyType; - typedef typename iterator_value::type ValueType; - - // load (2*block_size) elements into shared memory. These (2*block_size) elements belong to (2*block_size)/tile_size different tiles. - __shared__ uninitialized_array key; - __shared__ uninitialized_array outkey; - __shared__ uninitialized_array outvalue; - - const unsigned int grid_size = context.grid_dimension() * context.block_dimension(); - - unsigned int block_idx = context.block_index(); - - // the global index of this task - unsigned int i = context.thread_index() + context.block_index() * context.block_dimension(); - - // advance iterators - keys_first += i; - values_first += i; - keys_result += i; - values_result += i; - - for(; - block_idx <= index_of_last_block; - block_idx += context.grid_dimension(), i += grid_size, keys_first += grid_size, values_first += grid_size, keys_result += grid_size, values_result += grid_size) - { - KeyType my_key; - - // copy over inputs to shared memory - if(i < n) - { - key[context.thread_index()] = my_key = *keys_first; - } // end if - - // the tile to which the element belongs - unsigned int tile_index = context.thread_index()>>log_tile_size; - - // figure out the index and size of the other tile - unsigned int other_tile_index = tile_index^1; - unsigned int other_tile_size = (1< - class static_strided_integer_range -{ - // XXX cudafe doesn't like this private for some reason - //private: - public: - typedef typename thrust::counting_iterator counting_iterator; - - struct stride_functor - : public thrust::unary_function - { - inline __host__ __device__ - unsigned int operator()(unsigned int i) const - { - return stride * i; - } - }; - - public: - typedef typename thrust::transform_iterator iterator; - - static_strided_integer_range(unsigned int num_strides) - : m_begin(iterator(counting_iterator(0), stride_functor())), - m_end(iterator(counting_iterator(num_strides), stride_functor())) - {} - - iterator begin() const - { - return m_begin; - } - - iterator end() const - { - return m_end; - } - - private: - iterator m_begin, m_end; -}; - - -///////////////////// Find the rank of each extracted element in both arrays //////////////////////////////////////// -///////////////////// This breaks up the array into independent segments to merge //////////////////////////////////////// -// Inputs: d_splitters, d_splittes_pos: the merged array of splitters with corresponding positions. -// d_srcData: input data, datasize: number of entries in d_srcData -// N_SPLITTERS the number of splitters, log_blocksize: log of the size of each block of sorted data -// log_num_merged_splitters_per_tile = log of the number of merged splitters. ( = log_blocksize - 7). -// Output: d_rank1, d_rank2: ranks of each splitter in d_splitters in the block to which it belongs -// (say i) and its corresponding block (block i+1). -template -struct rank_splitters_closure -{ - typedef Context context_type; - - static const unsigned int log_block_size = thrust::detail::mpl::math::log2::value; - - RandomAccessIterator1 splitters_first; - RandomAccessIterator2 splitters_pos_first; - RandomAccessIterator3 keys_first; - RandomAccessIterator4 ranks_result1; - RandomAccessIterator4 ranks_result2; - unsigned int num_splitters; - unsigned int num_keys; - unsigned int log_tile_size; - thrust::detail::device_function< - StrictWeakOrdering, - bool - > comp; - context_type context; - - // this member is derivable from those received in the constructor - unsigned int log_num_merged_splitters_per_tile; - - rank_splitters_closure(RandomAccessIterator1 splitters_first, - RandomAccessIterator2 splitters_pos_first, - RandomAccessIterator3 keys_first, - unsigned int num_splitters, - unsigned int num_keys, - unsigned int log_tile_size, - RandomAccessIterator4 ranks_result1, - RandomAccessIterator4 ranks_result2, - StrictWeakOrdering comp, - context_type context = context_type()) - : splitters_first(splitters_first), splitters_pos_first(splitters_pos_first), - keys_first(keys_first), - ranks_result1(ranks_result1), ranks_result2(ranks_result2), - num_splitters(num_splitters), num_keys(num_keys), - log_tile_size(log_tile_size), - comp(comp), context(context) - { - // the number of splitters in each tile before merging - const unsigned int log_num_splitters_per_tile = log_tile_size - log_block_size; - - // the number of splitters in each merged tile - log_num_merged_splitters_per_tile = log_num_splitters_per_tile + 1; - } - - inline unsigned int grid_size() const - { - unsigned int num_blocks = num_splitters / block_size; - if(num_splitters % block_size) ++num_blocks; - - // compute the maximum number of block_size we can launch on this arch - const unsigned int max_num_blocks = max_grid_size(block_size); - - return min(num_blocks, max_num_blocks); - } - - /*! this member function returns the index of the (odd,even) block pair - * that the splitter of interest belongs to - * \param splitter_idx The index of the splitter in the splitters list - * \return The global index of the (odd,even) block pair - */ - __device__ __thrust_forceinline__ - unsigned int block_pair_idx(unsigned int splitter_idx) const - { - return splitter_idx >> log_num_merged_splitters_per_tile; - } - - /*! This member function returns the end of the search range in the other tile in - * which the splitter of interest needs to be ranked. - * \param splitter_idx The index of the splitter in the splitters array - * \param splitter_global_idx The index of the splitter in the global array of elements - * \param tile_idx The index of the tile to which the splitter belongs. - * \return The half-open interval in the other tile in which the splitter needs to be ranked. - * [first_index_to_search, size_of_interval) - */ - __device__ __thrust_forceinline__ - thrust::pair search_interval(unsigned int splitter_idx, unsigned int splitter_global_idx, unsigned int tile_idx) const - { - // We want to compute the ranks of the splitter in d_srcData1 and d_srcData2 - // for instance, if the splitter belongs to d_srcData1, then - // (1) the rank in d_srcData1 is simply given by its splitter_global_idx - // (2) to find the rank in d_srcData2, we first find the block in d_srcData2 where inp appears. - // We do this by noting that we have already merged/sorted splitters, and thus the rank - // of inp in the elements of d_srcData2 that are present in splitters is given by - // position of inp in d_splitters - rank of inp in elements of d_srcData1 in splitters - // = i - splitter_global_idx - // This also gives us the block of d_srcData2 that the splitter belongs in, since we have one - // element in splitters per block of d_srcData2. - - // We now perform a binary search over this block of d_srcData2 to find the rank of inp in d_srcData2. - // start and end are the start and end indices of this block in d_srcData2, forming the bounds of the binary search. - // Note that this binary search is in global memory with uncoalesced loads. However, we only find the ranks - // of a small set of elements, one per splitter: thus it is not the performance bottleneck. - - // the local index of the splitter within the (odd, even) block pair. - const unsigned int splitter_block_pair_idx = splitter_idx - (block_pair_idx(splitter_idx)<> log_block_size; - - // find the end of the search range in the other tile - unsigned int end = (( splitter_block_pair_idx - block_tile_idx) << log_block_size); - - // begin by assuming the search range is the size of a full block - unsigned int other_block_size = block_size; - - // the index of the other tile can be found with - const unsigned int other_tile_idx = tile_idx ^ 1; - - // the size of the other tile can be less than tile_size if the it is the last tile. - unsigned int other_tile_size = min(1 << log_tile_size, num_keys - (other_tile_idx< other_tile_size) - { - // the other block has partial size - end = other_tile_size; - other_block_size = num_keys % block_size; - } - else if(end == 0) - { - // when the search range is empty - // the other_block_size is 0 - other_block_size = 0; - } - - // the search range begins other_block_size elements before the end - unsigned int start = end - other_block_size; - - return thrust::make_pair(start,other_block_size); - } - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename iterator_value::type KeyType; - typedef typename iterator_value::type IndexType; - - const unsigned int grid_size = context.grid_dimension() * context.block_dimension(); - - unsigned int splitter_idx = context.thread_index() + context.block_index() * context.block_dimension(); - - // advance iterators - splitters_first += splitter_idx; - splitters_pos_first += splitter_idx; - ranks_result1 += splitter_idx; - ranks_result2 += splitter_idx; - - for(; - splitter_idx < num_splitters; - splitter_idx += grid_size, splitters_first += grid_size, splitters_pos_first += grid_size, ranks_result1 += grid_size, ranks_result2 += grid_size) - { - // the index of the splitter within the global array of elements - IndexType splitter_global_idx = *splitters_pos_first; - - // the tile to which the splitter belongs. - unsigned int tile_idx = (splitter_global_idx >> log_tile_size); - - // the index of the "other" tile which which tile_idx must be merged. - unsigned int other_tile_idx = tile_idx^1; - - // compute the interval in the other tile to search - unsigned int start, n; - thrust::tie(start,n) = search_interval(splitter_idx, splitter_global_idx, tile_idx); - - // point to the beginning of the other tile - RandomAccessIterator3 other_tile_begin = keys_first + (other_tile_idx< - void rank_splitters(RandomAccessIterator1 splitters_first, - RandomAccessIterator1 splitters_last, - RandomAccessIterator2 splitter_positions_first, - RandomAccessIterator3 keys_first, - RandomAccessIterator3 keys_last, - size_t log_tile_size, - RandomAccessIterator4 ranks_result1, - RandomAccessIterator4 ranks_result2, - StrictWeakOrdering comp) -{ - typedef rank_splitters_closure< - block_size, - RandomAccessIterator1, - RandomAccessIterator2, - RandomAccessIterator3, - RandomAccessIterator4, - StrictWeakOrdering, - detail::statically_blocked_thread_array - > Closure; - - Closure closure(splitters_first, - splitter_positions_first, - keys_first, - splitters_last - splitters_first, - keys_last - keys_first, - log_tile_size, - ranks_result1, - ranks_result2, - comp); - - detail::launch_closure(closure, closure.grid_size(), block_size); -} - - -template -__device__ - void copy_n(Context context, - RandomAccessIterator1 first1, - RandomAccessIterator2 first2, - Size n, - RandomAccessIterator3 result1, - RandomAccessIterator4 result2) -{ - for(Size i = context.thread_index(); - i < n; - i += context.block_dimension()) - { - result1[i] = first1[i]; - result2[i] = first2[i]; - } -} - - -///////////////////// MERGE TWO INDEPENDENT SEGMENTS USING BINARY SEARCH IN SHARED MEMORY //////////////////////////////////////// -// NOTE: This is the most compute-intensive part of the algorithm. -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Thread block i merges entries between rank[i] and rank[i+1]. These can be independently -// merged and concatenated, as noted above. -// Each thread in the thread block i does a binary search of one element between rank[i] -> rank[i+1] in the -// other array. - -// Inputs: srcdatakey, value: inputs -// log_blocksize, log_num_merged_splitters_per_tile: as in previous functions -// Outputs: resultdatakey, resultdatavalue: output merged arrays are written here. -template -struct merge_subtiles_by_key_closure -{ - typedef Context context_type; - static const unsigned int log_block_size = thrust::detail::mpl::math::log2::value; - - RandomAccessIterator1 keys_first; - RandomAccessIterator2 values_first; - unsigned int n; - RandomAccessIterator3 ranks_first1; - RandomAccessIterator4 ranks_first2; - const unsigned int tile_size; - const unsigned int num_splitters; - RandomAccessIterator5 keys_result; - RandomAccessIterator6 values_result; - StrictWeakOrdering comp; - Context context; - - // this member is derivable from the constructor parameters - unsigned int log_num_merged_splitters_per_tile; - - merge_subtiles_by_key_closure - (RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - unsigned int n, - RandomAccessIterator3 ranks_first1, - RandomAccessIterator4 ranks_first2, - const unsigned int log_tile_size, - const unsigned int num_splitters, - RandomAccessIterator5 keys_result, - RandomAccessIterator6 values_result, - StrictWeakOrdering comp, - Context context = Context()) - : keys_first(keys_first), values_first(values_first), n(n), - ranks_first1(ranks_first1), ranks_first2(ranks_first2), - tile_size(1 << log_tile_size), - num_splitters(num_splitters), - keys_result(keys_result), values_result(values_result), - comp(comp), context(context) - { - const unsigned int log_num_splitters_per_tile = log_tile_size - log_block_size; - log_num_merged_splitters_per_tile = log_num_splitters_per_tile + 1; - } - - unsigned int grid_size() const - { - const unsigned int max_num_blocks = max_grid_size(block_size); - return thrust::min(num_splitters, max_num_blocks); - } - - __device__ __thrust_forceinline__ - unsigned int even_offset(unsigned int oddeven_blockid) const - { - return oddeven_blockid << (log_num_merged_splitters_per_tile + log_block_size); - } - - __device__ __thrust_forceinline__ - void get_partition(unsigned int partition_idx, unsigned int oddeven_blockid, - unsigned int &rank1, unsigned int &size1, - unsigned int &rank2, unsigned int &size2) const - { - // XXX this logic would be much improved if we were guaranteed that there was - // an element at ranks_first[1] - // XXX we could eliminate the need for local_blockIdx, log_num_merged_splitters_per_block, tile_size, and n - - // the index of the merged splitter within the splitters for the odd-even block pair. - unsigned int local_blockIdx = partition_idx - (oddeven_blockid< n) - { - size2 = n - tile_size - even_offset(oddeven_blockid); - } // end if - - // measure each array relative to its beginning - size1 -= rank1; - size2 -= rank2; - } - - template - __device__ __thrust_forceinline__ - void do_it(KeyType *s_keys, ValueType *s_values) - { - // advance iterators - unsigned int i = context.block_index(); - ranks_first1 += i; - ranks_first2 += i; - - // Thread Block i merges the sub-block associated with splitter i: rank[i] -> rank[i+1] in a particular odd-even block pair. - for(; - i < num_splitters; - i += context.grid_dimension(), ranks_first1 += context.grid_dimension(), ranks_first2 += context.grid_dimension()) - { - // the (odd, even) block pair that the splitter belongs to. - unsigned int oddeven_blockid = i >> log_num_merged_splitters_per_tile; - - // start1 & start2 store rank[i] and rank[i+1] indices in arrays 1 and 2. - // size1 & size2 store the number of of elements between rank[i] & rank[i+1] in arrays 1 & 2. - unsigned int rank1, rank2, size1, size2; - get_partition(i, oddeven_blockid, rank1, size1, rank2, size2); - - // find where the odd,even arrays begin - RandomAccessIterator1 even_keys_first = keys_first + even_offset(oddeven_blockid); - RandomAccessIterator1 odd_keys_first = even_keys_first + tile_size; - - RandomAccessIterator2 even_values_first = values_first + even_offset(oddeven_blockid); - RandomAccessIterator2 odd_values_first = even_values_first + tile_size; - - // load tiles into smem - copy_n(context, even_keys_first + rank1, even_values_first + rank1, size1, s_keys, s_values); - copy_n(context, odd_keys_first + rank2, odd_values_first + rank2, size2, s_keys + size1, s_values + size1); - - context.barrier(); - - // merge the arrays in-place - block::inplace_merge_by_key_n(context, s_keys, s_values, size1, size2, comp); - - context.barrier(); - - // write tiles to gmem - unsigned int dst_offset = even_offset(oddeven_blockid) + rank1 + rank2; - copy_n(context, s_keys, s_values, size1 + size2, keys_result + dst_offset, values_result + dst_offset); - - context.barrier(); - } // end for i - } - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename iterator_value::type KeyType; - typedef typename iterator_value::type ValueType; - - __shared__ uninitialized_array s_keys; - __shared__ uninitialized_array s_values; - - do_it(s_keys.data(), s_values.data()); - } -}; // merge_subtiles_by_key_closure - -// merge_subtiles_by_key() merges each sub-tile independently. As explained in rank_splitters(), -// the sub-tiles are defined by the ranks of the splitter elements d_rank1 and d_rank2 in the odd and even tiles resp. -// It can be easily shown that each sub-tile cannot contain more than block_size elements of either the odd or even tile. - -// the function calls merge_subblocks_binarysearch_kernel() for the remaining N_splitterS sub-tiles -// We use 1 thread block per splitter: For instance, thread block 0 will merge rank1[0] -> rank1[1] of array i with -// rank2[0] -> rank2[1] of array i^1, with i being the thread block to which the splitter belongs. - -// We implement each sub-tile merge using a binary search. We compute the rank of each element belonging to a sub-tile -// of an odd numbered tile in the corresponding sub-tile of its even numbered pair. It then adds this rank to -// the index of the element in its own sub-tile to find the output index of the element in the merged sub-tile. - -template - void merge_subtiles_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - RandomAccessIterator3 splitters_pos_first, - RandomAccessIterator3 splitters_pos_last, - RandomAccessIterator4 ranks_first1, - RandomAccessIterator5 ranks_first2, - RandomAccessIterator6 keys_result, - RandomAccessIterator7 values_result, - unsigned int log_tile_size, - StrictWeakOrdering comp) -{ - typedef typename iterator_value::type KeyType; - typedef typename iterator_value::type ValueType; - - const unsigned int block_size = stable_merge_sort_detail::block_size::value; - - typedef merge_subtiles_by_key_closure< - block_size, - RandomAccessIterator1, - RandomAccessIterator2, - RandomAccessIterator4, - RandomAccessIterator5, - RandomAccessIterator6, - RandomAccessIterator7, - StrictWeakOrdering, - detail::statically_blocked_thread_array - > Closure; - - Closure closure(keys_first, - values_first, - keys_last - keys_first, - ranks_first1, - ranks_first2, - log_tile_size, - splitters_pos_last - splitters_pos_first, - keys_result, - values_result, - comp); - - detail::launch_closure(closure, closure.grid_size(), block_size); -} - - -template - void merge_small_tiles_by_key(execution_policy &, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - size_t log_tile_size, - RandomAccessIterator3 keys_result, - RandomAccessIterator4 values_result, - StrictWeakOrdering comp) -{ - typedef merge_small_tiles_by_key_closure< - block_size, - RandomAccessIterator1, - RandomAccessIterator2, - RandomAccessIterator3, - RandomAccessIterator4, - StrictWeakOrdering, - detail::statically_blocked_thread_array - > Closure; - - Closure closure(keys_first, values_first, keys_last - keys_first, log_tile_size, keys_result, values_result, comp); - - detail::launch_closure(closure, closure.grid_size(), block_size); -} // end merge_small_tiles_by_key() - - -template - void merge_tiles_by_key_recursive(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - RandomAccessIterator3 keys_result, - RandomAccessIterator4 values_result, - size_t log_tile_size, - StrictWeakOrdering comp) -{ - typedef typename iterator_value::type KeyType; - typedef typename iterator_value::type ValueType; - - const size_t tile_size = 1<::value; - - // Case (a): tile_size <= block_size - if(tile_size <= block_size) - { - return merge_small_tiles_by_key<2*block_size>(exec, keys_first, keys_last, values_first, log_tile_size, keys_result, values_result, comp); - } // end if - - // Case (b) tile_size >= block_size - - // step 1 of the recursive case: gather one splitter per block_size entries in each odd-even tile pair. - thrust::detail::temporary_array splitters(exec, thrust::detail::util::divide_ri(keys_last - keys_first, block_size)); - static_strided_integer_range splitters_pos(splitters.size()); - thrust::gather(exec, splitters_pos.begin(), splitters_pos.end(), keys_first, splitters.begin()); - - // step 2 of the recursive case: merge the splitters & their positions - thrust::detail::temporary_array merged_splitters(exec, splitters.size()); - thrust::detail::temporary_array merged_splitters_pos(exec, splitters.size()); - - const unsigned int log_block_size = thrust::detail::mpl::math::log2::value; - size_t log_num_splitters_per_tile = log_tile_size - log_block_size; - merge_tiles_by_key_recursive(exec, - splitters.begin(), - splitters.end(), - splitters_pos.begin(), - merged_splitters.begin(), - merged_splitters_pos.begin(), - log_num_splitters_per_tile, - comp); - - // step 3 of the recursive case: find the ranks of each splitter in the respective two tiles. - // reuse the merged_splitters_pos storage - thrust::detail::temporary_array &rank1 = merged_splitters_pos; - thrust::detail::temporary_array rank2(exec, rank1.size()); - - rank_splitters(merged_splitters.begin(), - merged_splitters.end(), - merged_splitters_pos.begin(), - keys_first, - keys_last, - log_tile_size, - rank1.begin(), - rank2.begin(), - comp); - - // step 4 of the recursive case: merge each sub-tile independently in parallel. - merge_subtiles_by_key(keys_first, - keys_last, - values_first, - merged_splitters_pos.begin(), - merged_splitters_pos.end(), - rank1.begin(), - rank2.begin(), - keys_result, - values_result, - log_tile_size, - comp); -} - - -template - void merge_tiles_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - size_t n, - RandomAccessIterator3 keys_result, - RandomAccessIterator4 values_result, - unsigned int log_tile_size, - StrictWeakOrdering comp) -{ - const unsigned int tile_size = 1 << log_tile_size; - const size_t num_tiles = thrust::detail::util::divide_ri(n, tile_size); - - // if there is an odd number of tiles, we should exclude the last one - // without a twin in merge_recursive - const size_t last_tile_offset = (num_tiles%2)?((num_tiles-1)*tile_size):n; - - merge_tiles_by_key_recursive(exec, - keys_first, - keys_first + last_tile_offset, - values_first, - keys_result, - values_result, - log_tile_size, - comp); - - // copy the last tile without a twin, should it exist - if(last_tile_offset < n) - { - thrust::copy(exec, keys_first + last_tile_offset, keys_first + n, keys_result + last_tile_offset); - thrust::copy(exec, values_first + last_tile_offset, values_first + n, values_result + last_tile_offset); - } // end if -} // end merge_tiles_by_key() - - -} // end stable_merge_sort_detail - - - -template -void stable_merge_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // XXX it's potentially unsafe to pass the same array for keys & values - thrust::system::cuda::detail::detail::stable_merge_sort_by_key(exec, first, last, first, comp); -} - - -template - void stable_merge_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_traits::value_type KeyType; - typedef typename thrust::iterator_traits::value_type ValueType; - - // compute the block_size based on the types we're sorting - const unsigned int block_size = stable_merge_sort_detail::block_size::value; - - // XXX WAR unused variable warning issued by nvcc - (void) block_size; - - // first, sort each tile of block_size elements - stable_sort_by_count(exec, keys_first, keys_last, values_first, comp); - - // merge tiles if there is more than one - const size_t n = keys_last - keys_first; - if(n > block_size) - { - // allocate scratch space - using namespace thrust::detail; - using namespace stable_merge_sort_detail; - temporary_array temp_keys(exec, n); - temporary_array temp_values(exec, n); - - // use a caching allocator for the calls to merge_tiles_by_key - // XXX unfortunately g++-4.2 can't deal with this special execution policy -#if defined(THRUST_GCC_VERSION) && THRUST_GCC_VERSION < 40300 - execution_policy &merge_exec = exec; -#else - cached_temporary_allocator merge_exec(exec); -#endif - - // The log(n) iterations start here. Each call to 'merge' merges an odd-even pair of tiles - unsigned int log_tile_size = thrust::detail::mpl::math::log2::value; - bool ping = true; - for(; (1u << log_tile_size) < n; ++log_tile_size, ping = !ping) - { - // we ping-pong back and forth - if(ping) - { - merge_tiles_by_key(merge_exec, keys_first, values_first, n, temp_keys.begin(), temp_values.begin(), log_tile_size, comp); - } // end if - else - { - merge_tiles_by_key(merge_exec, temp_keys.begin(), temp_values.begin(), n, keys_first, values_first, log_tile_size, comp); - } // end else - } // end for - - // this is to make sure that our data is finally in the data and keys arrays - // and not in the temporary arrays - if(!ping) - { - thrust::copy(exec, temp_keys.begin(), temp_keys.end(), keys_first); - thrust::copy(exec, temp_values.begin(), temp_values.end(), values_first); - } // end if - } // end if -} // end stable_merge_sort_by_key() - - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - diff --git a/compat/thrust/system/cuda/detail/detail/stable_primitive_sort.h b/compat/thrust/system/cuda/detail/detail/stable_primitive_sort.h deleted file mode 100644 index 8449a17..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_primitive_sort.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -void stable_primitive_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last); - -template -void stable_primitive_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/stable_primitive_sort.inl b/compat/thrust/system/cuda/detail/detail/stable_primitive_sort.inl deleted file mode 100644 index d6f4c77..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_primitive_sort.inl +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace stable_primitive_sort_detail -{ - - -template - struct enable_if_bool_sort - : thrust::detail::enable_if< - thrust::detail::is_same< - bool, - typename thrust::iterator_value::type - >::value - > -{}; - - -template - struct disable_if_bool_sort - : thrust::detail::disable_if< - thrust::detail::is_same< - bool, - typename thrust::iterator_value::type - >::value - > -{}; - - -template - typename enable_if_bool_sort::type - stable_primitive_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - // use stable_partition if we're sorting bool - // stable_partition puts true values first, so we need to logical_not - thrust::stable_partition(exec, first, last, thrust::logical_not()); -} - - -template - typename disable_if_bool_sort::type - stable_primitive_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - // call stable_radix_sort - thrust::system::cuda::detail::detail::stable_radix_sort(exec,first,last); -} - - -struct logical_not_first -{ - template - __host__ __device__ - bool operator()(Tuple t) - { - return !thrust::get<0>(t); - } -}; - - -template - typename enable_if_bool_sort::type - stable_primitive_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - // use stable_partition if we're sorting bool - // stable_partition puts true values first, so we need to logical_not - thrust::stable_partition(exec, - thrust::make_zip_iterator(thrust::make_tuple(keys_first, values_first)), - thrust::make_zip_iterator(thrust::make_tuple(keys_last, values_first)), - logical_not_first()); -} - - -template - typename disable_if_bool_sort::type - stable_primitive_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - // call stable_radix_sort_by_key - thrust::system::cuda::detail::detail::stable_radix_sort_by_key(exec, keys_first, keys_last, values_first); -} - - - -} - -template -void stable_primitive_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - thrust::system::cuda::detail::detail::stable_primitive_sort_detail::stable_primitive_sort(exec,first,last); -} - -template -void stable_primitive_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - thrust::system::cuda::detail::detail::stable_primitive_sort_detail::stable_primitive_sort_by_key(exec, keys_first, keys_last, values_first); -} - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/detail/stable_radix_sort.h b/compat/thrust/system/cuda/detail/detail/stable_radix_sort.h deleted file mode 100644 index 7a8b996..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_radix_sort.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file stable_radix_sort_dev.h - * \brief Defines the interface for a stable radix sort implementation on CUDA - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -void stable_radix_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last); - -template -void stable_radix_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/stable_radix_sort.inl b/compat/thrust/system/cuda/detail/detail/stable_radix_sort.inl deleted file mode 100644 index 9ea1977..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_radix_sort.inl +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -// do not attempt to compile this file with any other compiler -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - -#include -#include -#include -#include - -#include -#include -#include -#include - - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - -template -void stable_radix_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - typedef typename thrust::iterator_value::type K; - - unsigned int num_elements = last - first; - - // ensure data is properly aligned - if (!thrust::detail::util::is_aligned(thrust::raw_pointer_cast(&*first), 2*sizeof(K))) - { - thrust::detail::temporary_array aligned_keys(exec, first, last); - stable_radix_sort(exec, aligned_keys.begin(), aligned_keys.end()); - thrust::copy(exec, aligned_keys.begin(), aligned_keys.end(), first); - return; - } - - thrust::system::cuda::detail::detail::b40c_thrust::RadixSortingEnactor sorter(num_elements); - thrust::system::cuda::detail::detail::b40c_thrust::RadixSortStorage storage; - - // allocate temporary buffers - thrust::detail::temporary_array temp_keys(exec, num_elements); - thrust::detail::temporary_array temp_spine(exec, sorter.SpineElements()); - thrust::detail::temporary_array temp_from_alt(exec, 2); - - // define storage - storage.d_keys = thrust::raw_pointer_cast(&*first); - storage.d_alt_keys = thrust::raw_pointer_cast(&temp_keys[0]); - storage.d_spine = thrust::raw_pointer_cast(&temp_spine[0]); - storage.d_from_alt_storage = thrust::raw_pointer_cast(&temp_from_alt[0]); - - // perform the sort - sorter.EnactSort(storage); - - // radix sort sometimes leaves results in the alternate buffers - if (storage.using_alternate_storage) - { - thrust::copy(exec, temp_keys.begin(), temp_keys.end(), first); - } -} - -/////////////////////// -// Key-Value Sorting // -/////////////////////// - -// sort values directly -template -void stable_radix_sort_by_key(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - thrust::detail::true_type) -{ - typedef typename thrust::iterator_value::type K; - typedef typename thrust::iterator_value::type V; - - unsigned int num_elements = last1 - first1; - - // ensure data is properly aligned - if (!thrust::detail::util::is_aligned(thrust::raw_pointer_cast(&*first1), 2*sizeof(K))) - { - thrust::detail::temporary_array aligned_keys(exec, first1, last1); - stable_radix_sort_by_key(exec, aligned_keys.begin(), aligned_keys.end(), first2); - thrust::copy(exec, aligned_keys.begin(), aligned_keys.end(), first1); - return; - } - if (!thrust::detail::util::is_aligned(thrust::raw_pointer_cast(&*first2), 2*sizeof(V))) - { - thrust::detail::temporary_array aligned_values(exec, first2, first2 + num_elements); - stable_radix_sort_by_key(exec, first1, last1, aligned_values.begin()); - thrust::copy(exec, aligned_values.begin(), aligned_values.end(), first2); - return; - } - - thrust::system::cuda::detail::detail::b40c_thrust::RadixSortingEnactor sorter(num_elements); - thrust::system::cuda::detail::detail::b40c_thrust::RadixSortStorage storage; - - // allocate temporary buffers - thrust::detail::temporary_array temp_keys(exec, num_elements); - thrust::detail::temporary_array temp_values(exec, num_elements); - thrust::detail::temporary_array temp_spine(exec, sorter.SpineElements()); - thrust::detail::temporary_array temp_from_alt(exec, 2); - - // define storage - storage.d_keys = thrust::raw_pointer_cast(&*first1); - storage.d_values = thrust::raw_pointer_cast(&*first2); - storage.d_alt_keys = thrust::raw_pointer_cast(&temp_keys[0]); - storage.d_alt_values = thrust::raw_pointer_cast(&temp_values[0]); - storage.d_spine = thrust::raw_pointer_cast(&temp_spine[0]); - storage.d_from_alt_storage = thrust::raw_pointer_cast(&temp_from_alt[0]); - - // perform the sort - sorter.EnactSort(storage); - - // radix sort sometimes leaves results in the alternate buffers - if (storage.using_alternate_storage) - { - thrust::copy(exec, temp_keys.begin(), temp_keys.end(), first1); - thrust::copy(exec, temp_values.begin(), temp_values.end(), first2); - } -} - - -// sort values indirectly -template -void stable_radix_sort_by_key(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - thrust::detail::false_type) -{ - typedef typename thrust::iterator_value::type V; - - unsigned int num_elements = last1 - first1; - - // sort with integer values and then permute the real values accordingly - thrust::detail::temporary_array permutation(exec, num_elements); - thrust::sequence(exec, permutation.begin(), permutation.end()); - - stable_radix_sort_by_key(exec, first1, last1, permutation.begin()); - - // copy values into temp vector and then permute - thrust::detail::temporary_array temp_values(exec, first2, first2 + num_elements); - - // permute values - thrust::gather(exec, - permutation.begin(), permutation.end(), - temp_values.begin(), - first2); -} - - -template -void stable_radix_sort_by_key(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2) -{ - typedef typename thrust::iterator_value::type V; - - // decide how to handle values - static const bool sort_values_directly = thrust::detail::is_trivial_iterator::value && - thrust::detail::is_arithmetic::value && - sizeof(V) <= 8; // TODO profile this - - // XXX WAR unused variable warning - (void) sort_values_directly; - - stable_radix_sort_by_key(exec, first1, last1, first2, - thrust::detail::integral_constant()); -} - -} // end namespace detail -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - - -#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - diff --git a/compat/thrust/system/cuda/detail/detail/stable_sort_by_count.h b/compat/thrust/system/cuda/detail/detail/stable_sort_by_count.h deleted file mode 100644 index b563654..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_sort_by_count.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - - -template -void stable_sort_by_count(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - Compare comp); - - -} // end detail -} // end detail -} // end cuda -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/detail/stable_sort_by_count.inl b/compat/thrust/system/cuda/detail/detail/stable_sort_by_count.inl deleted file mode 100644 index 5efb36b..0000000 --- a/compat/thrust/system/cuda/detail/detail/stable_sort_by_count.inl +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include - - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ -namespace stable_sort_by_count_detail -{ - - -template -struct stable_sort_by_count_closure -{ - typedef Context context_type; - - RandomAccessIterator1 keys_first; - RandomAccessIterator2 values_first; - StrictWeakOrdering comp; // XXX this should probably be thrust::detail::device_function - const unsigned int n; - context_type context; - - stable_sort_by_count_closure(RandomAccessIterator1 keys_first, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp, - const unsigned int n, - context_type context = context_type()) - : keys_first(keys_first), - values_first(values_first), - comp(comp), - n(n), - context(context) - {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename iterator_value::type KeyType; - typedef typename iterator_value::type ValueType; - - __shared__ uninitialized_array s_keys; - __shared__ uninitialized_array s_data; - - const unsigned int grid_size = context.grid_dimension() * context.block_dimension(); - - // block_offset records the global index of this block's 0th thread - unsigned int block_offset = context.block_index() * block_size; - unsigned int i = context.thread_index() + block_offset; - - // advance iterators - keys_first += i; - values_first += i; - - for(; - block_offset < n; - block_offset += grid_size, i += grid_size, keys_first += grid_size, values_first += grid_size) - { - context.barrier(); - // copy input to shared - if(i < n) - { - s_keys[context.thread_index()] = *keys_first; - s_data[context.thread_index()] = *values_first; - } // end if - context.barrier(); - - // this block could be partially full - unsigned int length = block_size; - if(block_offset + block_size > n) - { - length = n - block_offset; - } // end if - - // run merge_sort over the block - block::merging_sort(context, s_keys.begin(), s_data.begin(), length, comp); - - // write result - if(i < n) - { - *keys_first = s_keys[context.thread_index()]; - *values_first = s_data[context.thread_index()]; - } // end if - } // end for i - } - - - static size_t max_grid_size() - { - const device_properties_t& properties = device_properties(); - - const unsigned int max_threads = properties.maxThreadsPerMultiProcessor * properties.multiProcessorCount; - const unsigned int max_blocks = properties.maxGridSize[0]; - - return thrust::min(max_blocks, 3 * max_threads / block_size); - } // end max_grid_size() - - - size_t grid_size() const - { - // compute the maximum number of blocks we can launch on this arch - const unsigned int max_num_blocks = max_grid_size(); - - // first, sort within each block - size_t num_blocks = n / block_size; - if(n % block_size) ++num_blocks; - - return thrust::min(num_blocks, max_num_blocks); - } // end grid_size() -}; // stable_sort_by_count_closure - - -} // end stable_sort_by_count_detail - - -template -void stable_sort_by_count(execution_policy &, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - Compare comp) -{ - typedef stable_sort_by_count_detail::stable_sort_by_count_closure< - count, - RandomAccessIterator1, - RandomAccessIterator2, - Compare, - detail::statically_blocked_thread_array - > Closure; - - Closure closure(keys_first, values_first, comp, keys_last - keys_first); - - // do an odd-even sort per block of data - detail::launch_closure(closure, closure.grid_size(), count); -} // end stable_sort_by_count() - - -} // end detail -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/detail/uninitialized.h b/compat/thrust/system/cuda/detail/detail/uninitialized.h deleted file mode 100644 index a3e3dd2..0000000 --- a/compat/thrust/system/cuda/detail/detail/uninitialized.h +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - - -template - class uninitialized -{ - private: - typename aligned_storage< - sizeof(T), - alignment_of::value - >::type storage; - - __device__ __thrust_forceinline__ const T* ptr() const - { - return reinterpret_cast(storage.data); - } - - __device__ __thrust_forceinline__ T* ptr() - { - return reinterpret_cast(storage.data); - } - - public: - // copy assignment - __device__ __thrust_forceinline__ uninitialized &operator=(const T &other) - { - T& self = *this; - self = other; - return *this; - } - - __device__ __thrust_forceinline__ T& get() - { - return *ptr(); - } - - __device__ __thrust_forceinline__ const T& get() const - { - return *ptr(); - } - - __device__ __thrust_forceinline__ operator T& () - { - return get(); - } - - __device__ __thrust_forceinline__ operator const T&() const - { - return get(); - } - - __thrust_forceinline__ __device__ void construct() - { - ::new(ptr()) T(); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg &a) - { - ::new(ptr()) T(a); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2) - { - ::new(ptr()) T(a1,a2); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3) - { - ::new(ptr()) T(a1,a2,a3); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4) - { - ::new(ptr()) T(a1,a2,a3,a4); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5) - { - ::new(ptr()) T(a1,a2,a3,a4,a5); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6) - { - ::new(ptr()) T(a1,a2,a3,a4,a5,a6); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7) - { - ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7, const Arg8 &a8) - { - ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7,a8); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7, const Arg8 &a8, const Arg9 &a9) - { - ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7,a8,a9); - } - - template - __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7, const Arg8 &a8, const Arg9 &a9, const Arg10 &a10) - { - ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); - } - - __thrust_forceinline__ __device__ void destroy() - { - T& self = *this; - self.~T(); - } -}; - - -template - class uninitialized_array -{ - public: - typedef T value_type; - typedef T& reference; - typedef const T& const_reference; - typedef T* pointer; - typedef const T* const_pointer; - typedef pointer iterator; - typedef const_pointer const_iterator; - typedef std::size_t size_type; - - __thrust_forceinline__ __device__ iterator begin() - { - return data(); - } - - __thrust_forceinline__ __device__ const_iterator begin() const - { - return data(); - } - - __thrust_forceinline__ __device__ iterator end() - { - return begin() + size(); - } - - __thrust_forceinline__ __device__ const_iterator end() const - { - return begin() + size(); - } - - __thrust_forceinline__ __device__ const_iterator cbegin() const - { - return begin(); - } - - __thrust_forceinline__ __device__ const_iterator cend() const - { - return end(); - } - - __thrust_forceinline__ __device__ size_type size() const - { - return N; - } - - __thrust_forceinline__ __device__ bool empty() const - { - return false; - } - - __thrust_forceinline__ __device__ T* data() - { - return impl.get(); - } - - __thrust_forceinline__ __device__ const T* data() const - { - return impl.get(); - } - - // element access - __thrust_forceinline__ __device__ reference operator[](size_type n) - { - return data()[n]; - } - - __thrust_forceinline__ __device__ const_reference operator[](size_type n) const - { - return data()[n]; - } - - __thrust_forceinline__ __device__ reference front() - { - return *data(); - } - - __thrust_forceinline__ __device__ const_reference front() const - { - return *data(); - } - - __thrust_forceinline__ __device__ reference back() - { - return data()[size() - size_type(1)]; - } - - __thrust_forceinline__ __device__ const_reference back() const - { - return data()[size() - size_type(1)]; - } - - private: - uninitialized impl; -}; - - -} // end detail -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/equal.h b/compat/thrust/system/cuda/detail/equal.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/equal.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/error.inl b/compat/thrust/system/cuda/detail/error.inl deleted file mode 100644 index 41b928f..0000000 --- a/compat/thrust/system/cuda/detail/error.inl +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace system -{ - - -error_code make_error_code(cuda::errc::errc_t e) -{ - return error_code(static_cast(e), cuda_category()); -} // end make_error_code() - - -error_condition make_error_condition(cuda::errc::errc_t e) -{ - return error_condition(static_cast(e), cuda_category()); -} // end make_error_condition() - - -namespace cuda -{ - -namespace detail -{ - - -class cuda_error_category - : public error_category -{ - public: - inline cuda_error_category(void) {} - - inline virtual const char *name(void) const - { - return "cuda"; - } - - inline virtual std::string message(int ev) const - { - static const std::string unknown_err("Unknown error"); - const char *c_str = ::cudaGetErrorString(static_cast(ev)); - return c_str ? std::string(c_str) : unknown_err; - } - - inline virtual error_condition default_error_condition(int ev) const - { - using namespace cuda::errc; - - if(ev < ::cudaErrorApiFailureBase) - { - return make_error_condition(static_cast(ev)); - } - - return system_category().default_error_condition(ev); - } -}; // end cuda_error_category - -} // end detail - -} // end namespace cuda - - -const error_category &cuda_category(void) -{ - static const cuda::detail::cuda_error_category result; - return result; -} - - -} // end namespace system - -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/execution_policy.h b/compat/thrust/system/cuda/detail/execution_policy.h deleted file mode 100644 index 7dae04c..0000000 --- a/compat/thrust/system/cuda/detail/execution_policy.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -// put the canonical tag in the same ns as the backend's entry points -namespace detail -{ - -// this awkward sequence of definitions arise -// from the desire both for tag to derive -// from execution_policy and for execution_policy -// to convert to tag (when execution_policy is not -// an ancestor of tag) - -// forward declaration of tag -struct tag; - -// forward declaration of execution_policy -template struct execution_policy; - -// specialize execution_policy for tag -template<> - struct execution_policy - : thrust::execution_policy -{}; - -// tag's definition comes before the -// generic definition of execution_policy -struct tag : execution_policy {}; - -// allow conversion to tag when it is not a successor -template - struct execution_policy - : thrust::execution_policy -{ - // allow conversion to tag - inline operator tag () const - { - return tag(); - } -}; - - -template - struct cross_system - : thrust::execution_policy > -{ - inline __host__ __device__ - cross_system(thrust::execution_policy &system1, - thrust::execution_policy &system2) - : system1(system1), system2(system2) - {} - - thrust::execution_policy &system1; - thrust::execution_policy &system2; - - inline __host__ __device__ - cross_system rotate() const - { - return cross_system(system2,system1); - } -}; - - -// overloads of select_system - -// cpp interop -template -inline __host__ __device__ -cross_system select_system(const execution_policy &system1, const thrust::cpp::execution_policy &system2) -{ - thrust::execution_policy &non_const_system1 = const_cast&>(system1); - thrust::cpp::execution_policy &non_const_system2 = const_cast&>(system2); - return cross_system(non_const_system1,non_const_system2); -} - - -template -inline __host__ __device__ -cross_system select_system(const thrust::cpp::execution_policy &system1, execution_policy &system2) -{ - thrust::cpp::execution_policy &non_const_system1 = const_cast&>(system1); - thrust::execution_policy &non_const_system2 = const_cast&>(system2); - return cross_system(non_const_system1,non_const_system2); -} - - -} // end detail - -// alias execution_policy and tag here -using thrust::system::cuda::detail::execution_policy; -using thrust::system::cuda::detail::tag; - -} // end cuda -} // end system - -// alias items at top-level -namespace cuda -{ - -using thrust::system::cuda::execution_policy; -using thrust::system::cuda::tag; - -} // end cuda -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/extern_shared_ptr.h b/compat/thrust/system/cuda/detail/extern_shared_ptr.h deleted file mode 100644 index 5f34cc8..0000000 --- a/compat/thrust/system/cuda/detail/extern_shared_ptr.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - class extern_shared_ptr -{ -// don't attempt to compile with any compiler other than nvcc -// due to use of __shared__ below -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - public: - __device__ - inline operator T * (void) - { - extern __shared__ int4 smem[]; - return reinterpret_cast(smem); - } - - __device__ - inline operator const T * (void) const - { - extern __shared__ int4 smem[]; - return reinterpret_cast(smem); - } -#endif // THRUST_DEVICE_COMPILER_NVCC -}; // end extern_shared_ptr - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/extrema.h b/compat/thrust/system/cuda/detail/extrema.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/extrema.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/fill.h b/compat/thrust/system/cuda/detail/fill.h deleted file mode 100644 index 9c753bb..0000000 --- a/compat/thrust/system/cuda/detail/fill.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file fill.h - * \brief Device implementation of fill. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - void fill(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &value); - -template - OutputIterator fill_n(execution_policy &exec, - OutputIterator first, - Size n, - const T &value); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/fill.inl b/compat/thrust/system/cuda/detail/fill.inl deleted file mode 100644 index 3c1feb8..0000000 --- a/compat/thrust/system/cuda/detail/fill.inl +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file fill.inl - * \brief Inline file for fill.h. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace detail -{ - - -template - WidePtr widen_raw_ptr(T *ptr) -{ - typedef thrust::detail::pointer_traits WideTraits; - typedef typename WideTraits::element_type WideT; - - // carefully widen the pointer to avoid warnings about conversions between differently aligned types on ARM - WideT *wide_raw_ptr = static_cast(static_cast(ptr)); - - return WideTraits::pointer_to(*wide_raw_ptr); -} - - -template - Pointer wide_fill_n(execution_policy &exec, - Pointer first, - Size n, - const T &value) -{ - typedef typename thrust::iterator_value::type OutputType; - - size_t ALIGNMENT_BOUNDARY = 128; // begin copying blocks at this byte boundary - - WideType wide_exemplar; - OutputType narrow_exemplars[sizeof(WideType) / sizeof(OutputType)]; - - for (size_t i = 0; i < sizeof(WideType) / sizeof(OutputType); i++) - narrow_exemplars[i] = static_cast(value); - - // cast through char * to avoid type punning warnings - for (size_t i = 0; i < sizeof(WideType); i++) - reinterpret_cast(&wide_exemplar)[i] = reinterpret_cast(narrow_exemplars)[i]; - - OutputType *first_raw = thrust::raw_pointer_cast(first); - OutputType *last_raw = first_raw + n; - - OutputType *block_first_raw = (thrust::min)(first_raw + n, thrust::detail::util::align_up(first_raw, ALIGNMENT_BOUNDARY)); - OutputType *block_last_raw = (thrust::max)(block_first_raw, thrust::detail::util::align_down(last_raw, sizeof(WideType))); - - // rebind Pointer to WideType - typedef typename thrust::detail::rebind_pointer::type WidePtr; - - // point to the widened range - // XXX since we've got an execution policy, we probably don't even need to deal with rebinding pointers - WidePtr block_first_wide = widen_raw_ptr(block_first_raw); - WidePtr block_last_wide = widen_raw_ptr(block_last_raw); - - thrust::generate(exec, first, Pointer(block_first_raw), thrust::detail::fill_functor(value)); - thrust::generate(exec, block_first_wide, block_last_wide, thrust::detail::fill_functor(wide_exemplar)); - thrust::generate(exec, Pointer(block_last_raw), first + n, thrust::detail::fill_functor(value)); - - return first + n; -} - -template - OutputIterator fill_n(execution_policy &exec, - OutputIterator first, - Size n, - const T &value, - thrust::detail::false_type) -{ - thrust::detail::fill_functor func(value); - return thrust::generate_n(exec, first, n, func); -} - -template - OutputIterator fill_n(execution_policy &exec, - OutputIterator first, - Size n, - const T &value, - thrust::detail::true_type) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - - if ( thrust::detail::util::is_aligned(thrust::raw_pointer_cast(&*first)) ) - { - if (compute_capability() < 20) - { - // 32-bit writes are faster on G80 and GT200 - typedef unsigned int WideType; - wide_fill_n(exec, &*first, n, value); - } - else - { - // 64-bit writes are faster on Fermi - typedef unsigned long long WideType; - wide_fill_n(exec, &*first, n, value); - } - - return first + n; - } - else - { - return fill_n(exec, first, n, value, thrust::detail::false_type()); - } -} - -} // end detail - -template - OutputIterator fill_n(execution_policy &exec, - OutputIterator first, - Size n, - const T &value) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - - // we're compiling with nvcc, launch a kernel - const bool use_wide_fill = thrust::detail::is_trivial_iterator::value - && thrust::detail::has_trivial_assign::value - && (sizeof(OutputType) == 1 || sizeof(OutputType) == 2 || sizeof(OutputType) == 4); - - // XXX WAR usused variable warning - (void)use_wide_fill; - - return detail::fill_n(exec, first, n, value, thrust::detail::integral_constant()); -} - -template - void fill(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &value) -{ - thrust::system::cuda::detail::fill_n(exec, first, thrust::distance(first,last), value); -} // end fill() - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/find.h b/compat/thrust/system/cuda/detail/find.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/find.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/for_each.h b/compat/thrust/system/cuda/detail/for_each.h deleted file mode 100644 index 56be13b..0000000 --- a/compat/thrust/system/cuda/detail/for_each.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.h - * \brief Defines the interface for a function that executes a - * function or functional for each value in a given range. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - RandomAccessIterator for_each(execution_policy &s, - RandomAccessIterator first, - RandomAccessIterator last, - UnaryFunction f); - -template - RandomAccessIterator for_each_n(execution_policy &s, - RandomAccessIterator first, - Size n, - UnaryFunction f); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/for_each.inl b/compat/thrust/system/cuda/detail/for_each.inl deleted file mode 100644 index be6e561..0000000 --- a/compat/thrust/system/cuda/detail/for_each.inl +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.inl - * \brief Inline file for for_each.h. - */ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace for_each_n_detail -{ - - -template -struct for_each_n_closure -{ - typedef void result_type; - typedef Context context_type; - - RandomAccessIterator first; - Size n; - thrust::detail::device_function f; - Context context; - - for_each_n_closure(RandomAccessIterator first, - Size n, - UnaryFunction f, - Context context = Context()) - : first(first), n(n), f(f), context(context) - {} - - __device__ __thrust_forceinline__ - result_type operator()(void) - { - const Size grid_size = context.block_dimension() * context.grid_dimension(); - - Size i = context.linear_index(); - - // advance iterator - first += i; - - while(i < n) - { - f(*first); - i += grid_size; - first += grid_size; - } - } -}; // end for_each_n_closure - - -template -thrust::tuple configure_launch(Size n) -{ - // calculate launch configuration - detail::launch_calculator calculator; - - thrust::tuple config = calculator.with_variable_block_size(); - size_t max_blocks = thrust::get<0>(config); - size_t block_size = thrust::get<1>(config); - size_t num_blocks = thrust::min(max_blocks, thrust::detail::util::divide_ri(n, block_size)); - - return thrust::make_tuple(num_blocks, block_size); -} - - -template -bool use_big_closure(Size n, unsigned int little_grid_size) -{ - // use the big closure when n will not fit within an unsigned int - // or if incrementing an unsigned int by little_grid_size would overflow - // the counter - - Size threshold = std::numeric_limits::max(); - - bool result = (sizeof(Size) > sizeof(unsigned int)) && (n > threshold); - - if(!result) - { - // check if we'd overflow the little closure's counter - unsigned int little_n = static_cast(n); - - if((little_n - 1u) + little_grid_size < little_n) - { - result = true; - } - } - - return result; -} - - -} // end for_each_n_detail - - -template -RandomAccessIterator for_each_n(execution_policy &, - RandomAccessIterator first, - Size n, - UnaryFunction f) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - if(n <= 0) return first; // empty range - - // create two candidate closures to implement the for_each - // choose between them based on the whether we can fit n into a smaller integer - // and whether or not we'll overflow the closure's counter - - typedef detail::blocked_thread_array Context; - typedef for_each_n_detail::for_each_n_closure BigClosure; - typedef for_each_n_detail::for_each_n_closure LittleClosure; - - BigClosure big_closure(first, n, f); - LittleClosure little_closure(first, static_cast(n), f); - - thrust::tuple little_config = for_each_n_detail::configure_launch(n); - - unsigned int little_grid_size = thrust::get<0>(little_config) * thrust::get<1>(little_config); - - if(for_each_n_detail::use_big_closure(n, little_grid_size)) - { - // launch the big closure - thrust::tuple big_config = for_each_n_detail::configure_launch(n); - detail::launch_closure(big_closure, thrust::get<0>(big_config), thrust::get<1>(big_config)); - } - else - { - // launch the little closure - detail::launch_closure(little_closure, thrust::get<0>(little_config), thrust::get<1>(little_config)); - } - - return first + n; -} - - -template - InputIterator for_each(execution_policy &exec, - InputIterator first, - InputIterator last, - UnaryFunction f) -{ - return cuda::detail::for_each_n(exec, first, thrust::distance(first,last), f); -} // end for_each() - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/gather.h b/compat/thrust/system/cuda/detail/gather.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/gather.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/generate.h b/compat/thrust/system/cuda/detail/generate.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/generate.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/get_value.h b/compat/thrust/system/cuda/detail/get_value.h deleted file mode 100644 index 273023f..0000000 --- a/compat/thrust/system/cuda/detail/get_value.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -namespace -{ - - -template -inline __host__ __device__ - typename thrust::iterator_value::type - get_value_msvc2005_war(execution_policy &exec, Pointer ptr) -{ - typedef typename thrust::iterator_value::type result_type; - - // XXX war nvbugs/881631 - struct war_nvbugs_881631 - { - __host__ inline static result_type host_path(execution_policy &exec, Pointer ptr) - { - // when called from host code, implement with assign_value - // note that this requires a type with default constructor - result_type result; - - thrust::host_system_tag host_tag; - cross_system systems(host_tag, exec); - assign_value(systems, &result, ptr); - - return result; - } - - __device__ inline static result_type device_path(execution_policy &, Pointer ptr) - { - // when called from device code, just do simple deref - return *thrust::raw_pointer_cast(ptr); - } - }; - -#ifndef __CUDA_ARCH__ - return war_nvbugs_881631::host_path(exec, ptr); -#else - return war_nvbugs_881631::device_path(exec, ptr); -#endif // __CUDA_ARCH__ -} // end get_value_msvc2005_war() - - -} // end anon namespace - - -template -inline __host__ __device__ - typename thrust::iterator_value::type - get_value(execution_policy &exec, Pointer ptr) -{ - return get_value_msvc2005_war(exec,ptr); -} // end get_value() - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/guarded_cuda_runtime_api.h b/compat/thrust/system/cuda/detail/guarded_cuda_runtime_api.h deleted file mode 100644 index e6c0d28..0000000 --- a/compat/thrust/system/cuda/detail/guarded_cuda_runtime_api.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to check for the existence of macros -// such as __host__ and __device__, which may already be defined by thrust -// and to undefine them before entering cuda_runtime_api.h (which will redefine them) - -// we only try to do this stuff if cuda/include/host_defines.h has been included -#if !defined(__HOST_DEFINES_H__) - -#ifdef __host__ -#undef __host__ -#endif // __host__ - -#ifdef __device__ -#undef __device__ -#endif // __device__ - -#endif // __HOST_DEFINES_H__ - -#include - diff --git a/compat/thrust/system/cuda/detail/inner_product.h b/compat/thrust/system/cuda/detail/inner_product.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/inner_product.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/iter_swap.h b/compat/thrust/system/cuda/detail/iter_swap.h deleted file mode 100644 index 9b2bcf0..0000000 --- a/compat/thrust/system/cuda/detail/iter_swap.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template -inline __host__ __device__ -void iter_swap(tag, Pointer1 a, Pointer2 b) -{ - // XXX war nvbugs/881631 - struct war_nvbugs_881631 - { - __host__ inline static void host_path(Pointer1 a, Pointer2 b) - { - thrust::swap_ranges(a, a + 1, b); - } - - __device__ inline static void device_path(Pointer1 a, Pointer2 b) - { - using thrust::swap; - swap(*thrust::raw_pointer_cast(a), - *thrust::raw_pointer_cast(b)); - } - }; - -#ifndef __CUDA_ARCH__ - return war_nvbugs_881631::host_path(a,b); -#else - return war_nvbugs_881631::device_path(a,b); -#endif // __CUDA_ARCH__ -} // end iter_swap() - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/logical.h b/compat/thrust/system/cuda/detail/logical.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/logical.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/malloc_and_free.h b/compat/thrust/system/cuda/detail/malloc_and_free.h deleted file mode 100644 index 676dd7c..0000000 --- a/compat/thrust/system/cuda/detail/malloc_and_free.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -// note that malloc returns a raw pointer to avoid -// depending on the heavyweight thrust/system/cuda/memory.h header -template - void *malloc(execution_policy &, std::size_t n) -{ - void *result = 0; - - cudaError_t error = cudaMalloc(reinterpret_cast(&result), n); - - if(error) - { - throw thrust::system::detail::bad_alloc(thrust::cuda_category().message(error).c_str()); - } // end if - - return result; -} // end malloc() - - -template - void free(execution_policy &, Pointer ptr) -{ - cudaError_t error = cudaFree(thrust::raw_pointer_cast(ptr)); - - if(error) - { - throw thrust::system_error(error, thrust::cuda_category()); - } // end error -} // end free() - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/memory.inl b/compat/thrust/system/cuda/detail/memory.inl deleted file mode 100644 index 998b54e..0000000 --- a/compat/thrust/system/cuda/detail/memory.inl +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ - -// XXX WAR an issue with MSVC 2005 (cl v14.00) incorrectly implementing -// pointer_raw_pointer for pointer by specializing it here -// note that we specialize it here, before the use of raw_pointer_cast -// below, which causes pointer_raw_pointer's instantiation -#if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400) -namespace detail -{ - -template - struct pointer_raw_pointer< thrust::cuda::pointer > -{ - typedef typename thrust::cuda::pointer::raw_pointer type; -}; // end pointer_raw_pointer - -} // end detail -#endif - -namespace system -{ -namespace cuda -{ - - -template - template - reference & - reference - ::operator=(const reference &other) -{ - return super_t::operator=(other); -} // end reference::operator=() - -template - reference & - reference - ::operator=(const value_type &x) -{ - return super_t::operator=(x); -} // end reference::operator=() - -template -__host__ __device__ -void swap(reference a, reference b) -{ - a.swap(b); -} // end swap() - -pointer malloc(std::size_t n) -{ - tag cuda_tag; - return pointer(thrust::system::cuda::detail::malloc(cuda_tag, n)); -} // end malloc() - -template -pointer malloc(std::size_t n) -{ - pointer raw_ptr = thrust::system::cuda::malloc(sizeof(T) * n); - return pointer(reinterpret_cast(raw_ptr.get())); -} // end malloc() - -void free(pointer ptr) -{ - tag cuda_tag; - return thrust::system::cuda::detail::free(cuda_tag, ptr.get()); -} // end free() - -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/merge.h b/compat/thrust/system/cuda/detail/merge.h deleted file mode 100644 index e01b705..0000000 --- a/compat/thrust/system/cuda/detail/merge.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - RandomAccessIterator3 merge(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - StrictWeakOrdering comp); - -} // end detail -} // end cuda -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/merge.inl b/compat/thrust/system/cuda/detail/merge.inl deleted file mode 100644 index bf7516f..0000000 --- a/compat/thrust/system/cuda/detail/merge.inl +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace merge_detail -{ - - -template -__device__ __thrust_forceinline__ -thrust::pair - partition_search(RandomAccessIterator1 first1, - RandomAccessIterator2 first2, - Size diag, - Size lower_bound1, - Size upper_bound1, - Size lower_bound2, - Size upper_bound2, - Compare comp) -{ - Size begin = thrust::max(lower_bound1, diag - upper_bound2); - Size end = thrust::min(diag - lower_bound2, upper_bound1); - - while(begin < end) - { - Size mid = (begin + end) / 2; - Size index1 = mid; - Size index2 = diag - mid - 1; - - if(comp(first2[index2], first1[index1])) - { - end = mid; - } - else - { - begin = mid + 1; - } - } - - return thrust::make_pair(begin, diag - begin); -} - - -template -__device__ __thrust_forceinline__ -void merge_n(Context &ctx, - RandomAccessIterator1 first1, - Size n1, - RandomAccessIterator2 first2, - Size n2, - RandomAccessIterator3 result, - Compare comp_, - unsigned int work_per_thread) -{ - const unsigned int block_size = ctx.block_dimension(); - thrust::detail::device_function comp(comp_); - typedef typename thrust::iterator_value::type value_type1; - typedef typename thrust::iterator_value::type value_type2; - - Size result_size = n1 + n2; - - // this is just oversubscription_rate * block_size * work_per_thread - // but it makes no sense to send oversubscription_rate as an extra parameter - Size work_per_block = thrust::detail::util::divide_ri(result_size, ctx.grid_dimension()); - - using thrust::system::cuda::detail::detail::uninitialized; - __shared__ uninitialized > s_block_input_begin; - - Size result_block_offset = ctx.block_index() * work_per_block; - - // find where this block's input begins in both input sequences - if(ctx.thread_index() == 0) - { - s_block_input_begin = (ctx.block_index() == 0) ? - thrust::pair(0,0) : - partition_search(first1, first2, - result_block_offset, - Size(0), n1, - Size(0), n2, - comp); - } - - ctx.barrier(); - - // iterate to consume this block's input - Size work_per_iteration = block_size * work_per_thread; - thrust::pair block_input_end = s_block_input_begin; - block_input_end.first += work_per_iteration; - block_input_end.second += work_per_iteration; - Size result_block_offset_last = result_block_offset + thrust::min(work_per_block, result_size - result_block_offset); - - for(; - result_block_offset < result_block_offset_last; - result_block_offset += work_per_iteration, - block_input_end.first += work_per_iteration, - block_input_end.second += work_per_iteration - ) - { - // find where this thread's input begins in both input sequences for this iteration - thrust::pair thread_input_begin = - partition_search(first1, first2, - Size(result_block_offset + ctx.thread_index() * work_per_thread), - s_block_input_begin.get().first, thrust::min(block_input_end.first , n1), - s_block_input_begin.get().second, thrust::min(block_input_end.second, n2), - comp); - - ctx.barrier(); - - // XXX the performance impact of not keeping x1 & x2 - // in registers is about 10% for int32 - uninitialized x1; - uninitialized x2; - - // XXX this is just a serial merge -- try to simplify or abstract this loop - Size i = result_block_offset + ctx.thread_index() * work_per_thread; - Size last_i = i + thrust::min(work_per_thread, result_size - thread_input_begin.first - thread_input_begin.second); - for(; - i < last_i; - ++i) - { - // optionally load x1 & x2 - bool output_x2 = true; - if(thread_input_begin.second < n2) - { - x2 = first2[thread_input_begin.second]; - } - else - { - output_x2 = false; - } - - if(thread_input_begin.first < n1) - { - x1 = first1[thread_input_begin.first]; - - if(output_x2) - { - output_x2 = comp(x2.get(), x1.get()); - } - } - - result[i] = output_x2 ? x2.get() : x1.get(); - - if(output_x2) - { - ++thread_input_begin.second; - } - else - { - ++thread_input_begin.first; - } - } // end for - - // the block's last thread has conveniently located the - // beginning of the next iteration's input - if(ctx.thread_index() == block_size-1) - { - s_block_input_begin = thread_input_begin; - } - ctx.barrier(); - } // end for -} // end merge_n - - -template - struct merge_n_closure -{ - typedef thrust::system::cuda::detail::detail::blocked_thread_array context_type; - - RandomAccessIterator1 first1; - Size n1; - RandomAccessIterator2 first2; - Size n2; - RandomAccessIterator3 result; - Compare comp; - Size work_per_thread; - - merge_n_closure(RandomAccessIterator1 first1, Size n1, RandomAccessIterator2 first2, Size n2, RandomAccessIterator3 result, Compare comp, Size work_per_thread) - : first1(first1), n1(n1), first2(first2), n2(n2), result(result), comp(comp), work_per_thread(work_per_thread) - {} - - __device__ __forceinline__ - void operator()() - { - context_type ctx; - merge_n(ctx, first1, n1, first2, n2, result, comp, work_per_thread); - } -}; - - -// returns (work_per_thread, threads_per_block, oversubscription_factor) -template - thrust::tuple - tunables(RandomAccessIterator1, RandomAccessIterator1, RandomAccessIterator2, RandomAccessIterator2, RandomAccessIterator3, Compare comp) -{ - // determined by empirical testing on GTX 480 - // ~4500 Mkeys/s on GTX 480 - const unsigned int work_per_thread = 5; - const unsigned int threads_per_block = 128; - const unsigned int oversubscription_factor = 30; - - return thrust::make_tuple(work_per_thread, threads_per_block, oversubscription_factor); -} - - -} // end merge_detail - - -template -RandomAccessIterator3 merge(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp) -{ - typedef typename thrust::iterator_difference::type Size; - Size n1 = last1 - first1; - Size n2 = last2 - first2; - typename thrust::iterator_difference::type n = n1 + n2; - - // empty result - if(n <= 0) return result; - - unsigned int work_per_thread = 0, threads_per_block = 0, oversubscription_factor = 0; - thrust::tie(work_per_thread,threads_per_block,oversubscription_factor) - = merge_detail::tunables(first1, last1, first2, last2, result, comp); - - const unsigned int work_per_block = work_per_thread * threads_per_block; - - const unsigned int num_processors = device_properties().multiProcessorCount; - const unsigned int num_blocks = thrust::min(oversubscription_factor * num_processors, thrust::detail::util::divide_ri(n, work_per_block)); - - typedef merge_detail::merge_n_closure closure_type; - closure_type closure(first1, n1, first2, n2, result, comp, work_per_thread); - - detail::launch_closure(closure, num_blocks, threads_per_block); - - return result + n1 + n2; -} // end merge() - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/mismatch.h b/compat/thrust/system/cuda/detail/mismatch.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/mismatch.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/par.h b/compat/thrust/system/cuda/detail/par.h deleted file mode 100644 index e56128c..0000000 --- a/compat/thrust/system/cuda/detail/par.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -struct par_t : thrust::system::cuda::detail::execution_policy -{ - par_t() : thrust::system::cuda::detail::execution_policy() {} - - template - thrust::detail::execute_with_allocator - operator()(Allocator &alloc) const - { - return thrust::detail::execute_with_allocator(alloc); - } -}; - - -} // end detail - - -static const detail::par_t par; - - -} // end cuda -} // end system - - -// alias par here -namespace cuda -{ - - -using thrust::system::cuda::par; - - -} // end cuda -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/partition.h b/compat/thrust/system/cuda/detail/partition.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/partition.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/reduce.h b/compat/thrust/system/cuda/detail/reduce.h deleted file mode 100644 index d188f60..0000000 --- a/compat/thrust/system/cuda/detail/reduce.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief Reduce a sequence of elements with a given length. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template - OutputType reduce(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputType init, - BinaryFunction binary_op); - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/reduce.inl b/compat/thrust/system/cuda/detail/reduce.inl deleted file mode 100644 index 66b4ac7..0000000 --- a/compat/thrust/system/cuda/detail/reduce.inl +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.inl - * \brief Inline file for reduce.h - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -namespace reduce_detail -{ - -/* - * Reduce a vector of n elements using binary_op() - * - * The order of reduction is not defined, so binary_op() should - * be a commutative (and associative) operator such as - * (integer) addition. Since floating point operations - * do not completely satisfy these criteria, the result is - * generally not the same as a consecutive reduction of - * the elements. - * - * Uses the same pattern as reduce6() in the CUDA SDK - * - */ -template -struct unordered_reduce_closure -{ - InputIterator input; - Size n; - T init; - OutputIterator output; - BinaryFunction binary_op; - unsigned int shared_array_size; - - typedef Context context_type; - context_type context; - - unordered_reduce_closure(InputIterator input, Size n, T init, OutputIterator output, BinaryFunction binary_op, unsigned int shared_array_size, Context context = Context()) - : input(input), n(n), init(init), output(output), binary_op(binary_op), shared_array_size(shared_array_size), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename thrust::iterator_value::type OutputType; - extern_shared_ptr shared_array; - - Size grid_size = context.block_dimension() * context.grid_dimension(); - - Size i = context.linear_index(); - - input += i; - - // compute reduction with all blockDim.x threads - OutputType sum = thrust::raw_reference_cast(*input); - - i += grid_size; - input += grid_size; - - while (i < n) - { - OutputType val = thrust::raw_reference_cast(*input); - - sum = binary_op(sum, val); - - i += grid_size; - input += grid_size; - } - - // write first shared_array_size values into shared memory - if (context.thread_index() < shared_array_size) - shared_array[context.thread_index()] = sum; - - // accumulate remaining values (if any) to shared memory in stages - if (context.block_dimension() > shared_array_size) - { - unsigned int lb = shared_array_size; - unsigned int ub = shared_array_size + lb; - - while (lb < context.block_dimension()) - { - context.barrier(); - - if (lb <= context.thread_index() && context.thread_index() < ub) - { - OutputType tmp = shared_array[context.thread_index() - lb]; - shared_array[context.thread_index() - lb] = binary_op(tmp, sum); - } - - lb += shared_array_size; - ub += shared_array_size; - } - } - - context.barrier(); - - block::reduce_n(context, shared_array, thrust::min(context.block_dimension(), shared_array_size), binary_op); - - if (context.thread_index() == 0) - { - OutputType tmp = shared_array[0]; - - if (context.grid_dimension() == 1) - tmp = binary_op(init, tmp); - - output += context.block_index(); - *output = tmp; - } - } -}; - - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - -template - OutputType reduce(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputType init, - BinaryFunction binary_op) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - typedef typename thrust::iterator_difference::type difference_type; - - difference_type n = thrust::distance(first,last); - - if (n == 0) - return init; - - typedef thrust::detail::temporary_array OutputArray; - typedef typename OutputArray::iterator OutputIterator; - - typedef detail::blocked_thread_array Context; - typedef unordered_reduce_closure Closure; - - function_attributes_t attributes = detail::closure_attributes(); - - // TODO chose this in a more principled manner - size_t threshold = thrust::max(2 * attributes.maxThreadsPerBlock, 1024); - - device_properties_t properties = device_properties(); - - // launch configuration - size_t num_blocks; - size_t block_size; - size_t array_size; - size_t smem_bytes; - - // first level reduction - if (static_cast(n) < threshold) - { - num_blocks = 1; - block_size = thrust::min(static_cast(n), static_cast(attributes.maxThreadsPerBlock)); - array_size = thrust::min(block_size, (properties.sharedMemPerBlock - attributes.sharedSizeBytes) / sizeof(OutputType)); - smem_bytes = sizeof(OutputType) * array_size; - } - else - { - detail::launch_calculator calculator; - - thrust::tuple config = calculator.with_variable_block_size_available_smem(); - - num_blocks = thrust::min(thrust::get<0>(config), static_cast(n) / thrust::get<1>(config)); - block_size = thrust::get<1>(config); - array_size = thrust::min(block_size, thrust::get<2>(config) / sizeof(OutputType)); - smem_bytes = sizeof(OutputType) * array_size; - } - - // TODO assert(n <= num_blocks * block_size); - // TODO if (shared_array_size < 1) throw cuda exception "insufficient shared memory" - - OutputArray output(exec, num_blocks); - - Closure closure(first, n, init, output.begin(), binary_op, array_size); - - //std::cout << "Launching " << num_blocks << " blocks of kernel with " << block_size << " threads and " << smem_bytes << " shared memory per block " << std::endl; - - detail::launch_closure(closure, num_blocks, block_size, smem_bytes); - - // second level reduction - if (num_blocks > 1) - { - typedef detail::blocked_thread_array Context; - typedef unordered_reduce_closure Closure; - - function_attributes_t attributes = detail::closure_attributes(); - - num_blocks = 1; - block_size = thrust::min(output.size(), static_cast(attributes.maxThreadsPerBlock)); - array_size = thrust::min(block_size, (properties.sharedMemPerBlock - attributes.sharedSizeBytes) / sizeof(OutputType)); - smem_bytes = sizeof(OutputType) * array_size; - - // TODO if (shared_array_size < 1) throw cuda exception "insufficient shared memory" - - Closure closure(output.begin(), output.size(), init, output.begin(), binary_op, array_size); - - //std::cout << "Launching " << num_blocks << " blocks of kernel with " << block_size << " threads and " << smem_bytes << " shared memory per block " << std::endl; - - detail::launch_closure(closure, num_blocks, block_size, smem_bytes); - } - - return output[0]; -} // end reduce - -} // end reduce_detail - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - -template - OutputType reduce(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputType init, - BinaryFunction binary_op) -{ - return reduce_detail::reduce(exec, first, last, init, binary_op); -} // end reduce() - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/reduce_by_key.h b/compat/thrust/system/cuda/detail/reduce_by_key.h deleted file mode 100644 index 9b8ec10..0000000 --- a/compat/thrust/system/cuda/detail/reduce_by_key.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce_by_key.h - * \brief CUDA implementation of reduce_by_key - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - thrust::pair - reduce_by_key(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/reduce_by_key.inl b/compat/thrust/system/cuda/detail/reduce_by_key.inl deleted file mode 100644 index 18dc1e4..0000000 --- a/compat/thrust/system/cuda/detail/reduce_by_key.inl +++ /dev/null @@ -1,705 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace reduce_by_key_detail -{ - -template -struct tail_flag_functor -{ - BinaryPredicate binary_pred; // NB: this must be the first member for performance reasons - IndexType n; - - typedef FlagType result_type; - - tail_flag_functor(IndexType n, BinaryPredicate binary_pred) - : n(n), binary_pred(binary_pred) - {} - - // XXX why is this noticably faster? (it may read past the end of input) - //FlagType operator()(const thrust::tuple& t) const - - template - __host__ __device__ __thrust_forceinline__ - FlagType operator()(const Tuple& t) - { - if (thrust::get<0>(t) == (n - 1) || !binary_pred(thrust::get<1>(t), thrust::get<2>(t))) - return 1; - else - return 0; - } -}; - - -template -__device__ __thrust_forceinline__ -FlagType load_flags(Context context, - const unsigned int n, - FlagIterator iflags, - FlagType (&sflag)[CTA_SIZE]) -{ - FlagType flag_bits = 0; - - // load flags in unordered fashion - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = k*CTA_SIZE + context.thread_index(); - - if (FullBlock || offset < n) - { - FlagIterator temp = iflags + offset; - if (*temp) - flag_bits |= FlagType(1) << k; - } - } - - sflag[context.thread_index()] = flag_bits; - - context.barrier(); - - flag_bits = 0; - - // obtain flags for iflags[K * context.thread_index(), K * context.thread_index() + K) - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = K * context.thread_index() + k; - - if (FullBlock || offset < n) - { - flag_bits |= ((sflag[offset % CTA_SIZE] >> (offset / CTA_SIZE)) & FlagType(1)) << k; - } - } - - context.barrier(); - - sflag[context.thread_index()] = flag_bits; - - context.barrier(); - - return flag_bits; -} - -template -__device__ __thrust_forceinline__ -void load_values(Context context, - const unsigned int n, - InputIterator2 ivals, - ValueType (&sdata)[K][CTA_SIZE + 1]) -{ - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = k*CTA_SIZE + context.thread_index(); - - if (FullBlock || offset < n) - { - InputIterator2 temp = ivals + offset; - sdata[offset % K][offset / K] = *temp; - } - } - - context.barrier(); -} - - -template -__device__ __thrust_forceinline__ -void reduce_by_key_body(Context context, - const unsigned int n, - InputIterator1 ikeys, - InputIterator2 ivals, - OutputIterator1 okeys, - OutputIterator2 ovals, - BinaryPredicate binary_pred, - BinaryFunction binary_op, - FlagIterator iflags, - FlagType (&sflag)[CTA_SIZE], - ValueType (&sdata)[K][CTA_SIZE + 1], - bool& carry_in, - IndexType& carry_index, - ValueType& carry_value) -{ - // load flags - const FlagType flag_bits = load_flags(context, n, iflags, sflag); - const FlagType flag_count = __popc(flag_bits); // TODO hide this behind a template - const FlagType left_flag = (context.thread_index() == 0) ? 0 : sflag[context.thread_index() - 1]; - const FlagType head_flag = (context.thread_index() == 0 || flag_bits & ((1 << (K - 1)) - 1) || left_flag & (1 << (K - 1))) ? 1 : 0; - - context.barrier(); - - // scan flag counts - sflag[context.thread_index()] = flag_count; context.barrier(); - - block::inclusive_scan(context, sflag, thrust::plus()); - - const FlagType output_position = (context.thread_index() == 0) ? 0 : sflag[context.thread_index() - 1]; - const FlagType num_outputs = sflag[CTA_SIZE - 1]; - - context.barrier(); - - // shuffle keys and write keys out - if (!thrust::detail::is_discard_iterator::value) - { - // XXX this could be improved - for (unsigned int i = 0; i < num_outputs; i += CTA_SIZE) - { - FlagType position = output_position; - - for(unsigned int k = 0; k < K; k++) - { - if (flag_bits & (FlagType(1) << k)) - { - if (i <= position && position < i + CTA_SIZE) - sflag[position - i] = K * context.thread_index() + k; - position++; - } - } - - context.barrier(); - - if (i + context.thread_index() < num_outputs) - { - InputIterator1 tmp1 = ikeys + sflag[context.thread_index()]; - OutputIterator1 tmp2 = okeys + (i + context.thread_index()); - *tmp2 = *tmp1; - } - - context.barrier(); - } - } - - // load values - load_values (context, n, ivals, sdata); - - ValueType ldata[K]; - for (unsigned int k = 0; k < K; k++) - ldata[k] = sdata[k][context.thread_index()]; - - // carry in (if necessary) - if (context.thread_index() == 0 && carry_in) - { - // XXX WAR sm_10 issue - ValueType tmp1 = carry_value; - ldata[0] = binary_op(tmp1, ldata[0]); - } - - context.barrier(); - - // sum local values - { - for(unsigned int k = 1; k < K; k++) - { - const unsigned int offset = K * context.thread_index() + k; - - if (FullBlock || offset < n) - { - if (!(flag_bits & (FlagType(1) << (k - 1)))) - ldata[k] = binary_op(ldata[k - 1], ldata[k]); - } - } - } - - // second level segmented scan - { - // use head flags for segmented scan - sflag[context.thread_index()] = head_flag; sdata[K - 1][context.thread_index()] = ldata[K - 1]; context.barrier(); - - if (FullBlock) - block::inclusive_scan_by_flag(context, sflag, sdata[K-1], binary_op); - else - block::inclusive_scan_by_flag_n(context, sflag, sdata[K-1], n, binary_op); - } - - // update local values - if (context.thread_index() > 0) - { - unsigned int update_bits = (flag_bits << 1) | (left_flag >> (K - 1)); -// TODO remove guard -#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC - unsigned int update_count = __ffs(update_bits) - 1u; // NB: this might wrap around to UINT_MAX -#else - unsigned int update_count = 0; -#endif // THRUST_DEVICE_COMPILER_NVCC - - if (!FullBlock && (K + 1) * context.thread_index() > n) - update_count = thrust::min(n - K * context.thread_index(), update_count); - - ValueType left = sdata[K - 1][context.thread_index() - 1]; - - for(unsigned int k = 0; k < K; k++) - { - if (k < update_count) - ldata[k] = binary_op(left, ldata[k]); - } - } - - context.barrier(); - - // store carry out - if (FullBlock) - { - if (context.thread_index() == CTA_SIZE - 1) - { - carry_value = ldata[K - 1]; - carry_in = (flag_bits & (FlagType(1) << (K - 1))) ? false : true; - carry_index = num_outputs; - } - } - else - { - if (context.thread_index() == (n - 1) / K) - { - for (unsigned int k = 0; k < K; k++) - if (k == (n - 1) % K) - carry_value = ldata[k]; - carry_in = (flag_bits & (FlagType(1) << ((n - 1) % K))) ? false : true; - carry_index = num_outputs; - } - } - - // shuffle values - { - FlagType position = output_position; - - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = K * context.thread_index() + k; - - if (FullBlock || offset < n) - { - if (flag_bits & (FlagType(1) << k)) - { - sdata[position / CTA_SIZE][position % CTA_SIZE] = ldata[k]; - position++; - } - } - } - } - - context.barrier(); - - - // write values out - for(unsigned int k = 0; k < K; k++) - { - const unsigned int offset = CTA_SIZE * k + context.thread_index(); - - if (offset < num_outputs) - { - OutputIterator2 tmp = ovals + offset; - *tmp = sdata[k][context.thread_index()]; - } - } - - context.barrier(); -} - -template -struct reduce_by_key_closure -{ - InputIterator1 ikeys; - InputIterator2 ivals; - OutputIterator1 okeys; - OutputIterator2 ovals; - BinaryPredicate binary_pred; - BinaryFunction binary_op; - FlagIterator iflags; - IndexIterator interval_counts; - ValueIterator interval_values; - BoolIterator interval_carry; - Decomposition decomp; - Context context; - - typedef Context context_type; - - reduce_by_key_closure(InputIterator1 ikeys, - InputIterator2 ivals, - OutputIterator1 okeys, - OutputIterator2 ovals, - BinaryPredicate binary_pred, - BinaryFunction binary_op, - FlagIterator iflags, - IndexIterator interval_counts, - ValueIterator interval_values, - BoolIterator interval_carry, - Decomposition decomp, - Context context = Context()) - : ikeys(ikeys), ivals(ivals), okeys(okeys), ovals(ovals), binary_pred(binary_pred), binary_op(binary_op), - iflags(iflags), interval_counts(interval_counts), interval_values(interval_values), interval_carry(interval_carry), - decomp(decomp), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename thrust::iterator_value::type KeyType; - typedef typename thrust::iterator_value::type ValueType; - typedef typename Decomposition::index_type IndexType; - typedef typename thrust::iterator_value::type FlagType; - - const unsigned int CTA_SIZE = context_type::ThreadsPerBlock::value; - -// TODO centralize this mapping (__CUDA_ARCH__ -> smem bytes) -#if __CUDA_ARCH__ >= 200 - const unsigned int SMEM = (48 * 1024); -#else - const unsigned int SMEM = (16 * 1024) - 256; -#endif - const unsigned int SMEM_FIXED = CTA_SIZE * sizeof(FlagType) + sizeof(ValueType) + sizeof(IndexType) + sizeof(bool); - const unsigned int BOUND_1 = (SMEM - SMEM_FIXED) / ((CTA_SIZE + 1) * sizeof(ValueType)); - const unsigned int BOUND_2 = 8 * sizeof(FlagType); - const unsigned int BOUND_3 = 6; - - // TODO replace this with a static_min::value - const unsigned int K = (BOUND_1 < BOUND_2) ? (BOUND_1 < BOUND_3 ? BOUND_1 : BOUND_3) : (BOUND_2 < BOUND_3 ? BOUND_2 : BOUND_3); - - __shared__ detail::uninitialized sflag; - __shared__ detail::uninitialized sdata; // padded to avoid bank conflicts - - __shared__ detail::uninitialized carry_value; // storage for carry in and carry out - __shared__ detail::uninitialized carry_index; - __shared__ detail::uninitialized carry_in; - - typename Decomposition::range_type interval = decomp[context.block_index()]; - //thrust::system::detail::internal::index_range interval = decomp[context.block_index()]; - - - if (context.thread_index() == 0) - { - carry_in = false; // act as though the previous segment terminated just before us - - if (context.block_index() == 0) - { - carry_index = 0; - } - else - { - interval_counts += (context.block_index() - 1); - carry_index = *interval_counts; - } - } - - context.barrier(); - - IndexType base = interval.begin(); - - // advance input and output iterators - ikeys += base; - ivals += base; - iflags += base; - okeys += carry_index; - ovals += carry_index; - - const unsigned int unit_size = K * CTA_SIZE; - - // process full units - while (base + unit_size <= interval.end()) - { - const unsigned int n = unit_size; - reduce_by_key_body(context, n, ikeys, ivals, okeys, ovals, binary_pred, binary_op, iflags, sflag.get(), sdata.get(), carry_in.get(), carry_index.get(), carry_value.get()); - base += unit_size; - ikeys += unit_size; - ivals += unit_size; - iflags += unit_size; - okeys += carry_index; - ovals += carry_index; - } - - // process partially full unit at end of input (if necessary) - if (base < interval.end()) - { - const unsigned int n = interval.end() - base; - reduce_by_key_body(context, n, ikeys, ivals, okeys, ovals, binary_pred, binary_op, iflags, sflag.get(), sdata.get(), carry_in.get(), carry_index.get(), carry_value.get()); - } - - if (context.thread_index() == 0) - { - interval_values += context.block_index(); - interval_carry += context.block_index(); - *interval_values = carry_value; - *interval_carry = carry_in; - } - } -}; // end reduce_by_key_closure - -template -struct DefaultPolicy -{ - // typedefs - typedef unsigned int FlagType; - typedef typename thrust::iterator_traits::difference_type IndexType; - typedef typename thrust::iterator_traits::value_type KeyType; - typedef thrust::system::detail::internal::uniform_decomposition Decomposition; - - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator2 is a "pure" output iterator - // TemporaryType = InputIterator2::value_type - // else - // TemporaryType = OutputIterator2::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - typedef typename thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - // XXX WAR problem on sm_11 - // TODO tune this - const static unsigned int ThreadsPerBlock = (thrust::detail::is_pod::value) ? 256 : 192; - - DefaultPolicy(InputIterator1 first1, InputIterator1 last1) - : decomp(default_decomposition(last1 - first1)) - {} - - // member variables - Decomposition decomp; -}; - -template - thrust::pair - reduce_by_key(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op, - Policy policy) -{ - typedef typename Policy::FlagType FlagType; - typedef typename Policy::Decomposition Decomposition; - typedef typename Policy::IndexType IndexType; - typedef typename Policy::KeyType KeyType; - typedef typename Policy::ValueType ValueType; - - // temporary arrays - typedef thrust::detail::temporary_array IndexArray; - typedef thrust::detail::temporary_array KeyArray; - typedef thrust::detail::temporary_array ValueArray; - typedef thrust::detail::temporary_array BoolArray; - - Decomposition decomp = policy.decomp; - - // input size - IndexType n = keys_last - keys_first; - - if (n == 0) - return thrust::make_pair(keys_output, values_output); - - IndexArray interval_counts(exec, decomp.size()); - ValueArray interval_values(exec, decomp.size()); - BoolArray interval_carry(exec, decomp.size()); - - // an ode to c++11 auto - typedef thrust::counting_iterator CountingIterator; - typedef thrust::transform_iterator< - tail_flag_functor, - thrust::zip_iterator< - thrust::tuple - > - > FlagIterator; - - FlagIterator iflag= thrust::make_transform_iterator - (thrust::make_zip_iterator(thrust::make_tuple(thrust::counting_iterator(0), keys_first, keys_first + 1)), - tail_flag_functor(n, binary_pred)); - - // count number of tail flags per interval - thrust::system::cuda::detail::reduce_intervals(exec, iflag, interval_counts.begin(), thrust::plus(), decomp); - - thrust::inclusive_scan(exec, - interval_counts.begin(), interval_counts.end(), - interval_counts.begin(), - thrust::plus()); - - // determine output size - const IndexType N = interval_counts[interval_counts.size() - 1]; - - const static unsigned int ThreadsPerBlock = Policy::ThreadsPerBlock; - typedef typename IndexArray::iterator IndexIterator; - typedef typename ValueArray::iterator ValueIterator; - typedef typename BoolArray::iterator BoolIterator; - typedef detail::statically_blocked_thread_array Context; - typedef reduce_by_key_closure Closure; - Closure closure - (keys_first, values_first, - keys_output, values_output, - binary_pred, binary_op, - iflag, - interval_counts.begin(), - interval_values.begin(), - interval_carry.begin(), - decomp); - detail::launch_closure(closure, decomp.size(), ThreadsPerBlock); - - if (decomp.size() > 1) - { - ValueArray interval_values2(exec, decomp.size()); - IndexArray interval_counts2(exec, decomp.size()); - BoolArray interval_carry2(exec, decomp.size()); - - IndexType N2 = - thrust::reduce_by_key - (exec, - thrust::make_zip_iterator(thrust::make_tuple(interval_counts.begin(), interval_carry.begin())), - thrust::make_zip_iterator(thrust::make_tuple(interval_counts.end(), interval_carry.end())), - interval_values.begin(), - thrust::make_zip_iterator(thrust::make_tuple(interval_counts2.begin(), interval_carry2.begin())), - interval_values2.begin(), - thrust::equal_to< thrust::tuple >(), - binary_op).first - - - thrust::make_zip_iterator(thrust::make_tuple(interval_counts2.begin(), interval_carry2.begin())); - - thrust::transform_if - (exec, - interval_values2.begin(), interval_values2.begin() + N2, - thrust::make_permutation_iterator(values_output, interval_counts2.begin()), - interval_carry2.begin(), - thrust::make_permutation_iterator(values_output, interval_counts2.begin()), - binary_op, - thrust::identity()); - } - - return thrust::make_pair(keys_output + N, values_output + N); -} - -} // end namespace reduce_by_key_detail - - -template - thrust::pair - reduce_by_key(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - return reduce_by_key_detail::reduce_by_key - (exec, - keys_first, keys_last, values_first, keys_output, values_output, binary_pred, binary_op, - reduce_by_key_detail::DefaultPolicy(keys_first, keys_last)); -} // end reduce_by_key() - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - diff --git a/compat/thrust/system/cuda/detail/reduce_intervals.h b/compat/thrust/system/cuda/detail/reduce_intervals.h deleted file mode 100644 index 505d136..0000000 --- a/compat/thrust/system/cuda/detail/reduce_intervals.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce_intervals.h - * \brief CUDA implementations of reduce_intervals algorithms. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template -void reduce_intervals(execution_policy &exec, - InputIterator input, - OutputIterator output, - BinaryFunction binary_op, - Decomposition decomp); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/reduce_intervals.inl b/compat/thrust/system/cuda/detail/reduce_intervals.inl deleted file mode 100644 index 2381769..0000000 --- a/compat/thrust/system/cuda/detail/reduce_intervals.inl +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template -struct commutative_reduce_intervals_closure -{ - InputIterator input; - OutputIterator output; - BinaryFunction binary_op; - Decomposition decomposition; - unsigned int shared_array_size; - - typedef Context context_type; - context_type context; - - commutative_reduce_intervals_closure(InputIterator input, OutputIterator output, BinaryFunction binary_op, Decomposition decomposition, unsigned int shared_array_size, Context context = Context()) - : input(input), output(output), binary_op(binary_op), decomposition(decomposition), shared_array_size(shared_array_size), context(context) {} - - __device__ __thrust_forceinline__ - void operator()(void) - { - typedef typename thrust::iterator_value::type OutputType; - extern_shared_ptr shared_array; - - typedef typename Decomposition::index_type index_type; - - // this block processes results in [range.begin(), range.end()) - thrust::system::detail::internal::index_range range = decomposition[context.block_index()]; - - index_type i = range.begin() + context.thread_index(); - - input += i; - - if (range.size() < context.block_dimension()) - { - // compute reduction with the first shared_array_size threads - if (context.thread_index() < thrust::min(shared_array_size,range.size())) - { - OutputType sum = *input; - - i += shared_array_size; - input += shared_array_size; - - while (i < range.end()) - { - OutputType val = *input; - - sum = binary_op(sum, val); - - i += shared_array_size; - input += shared_array_size; - } - - shared_array[context.thread_index()] = sum; - } - } - else - { - // compute reduction with all blockDim.x threads - OutputType sum = *input; - - i += context.block_dimension(); - input += context.block_dimension(); - - while (i < range.end()) - { - OutputType val = *input; - - sum = binary_op(sum, val); - - i += context.block_dimension(); - input += context.block_dimension(); - } - - // write first shared_array_size values into shared memory - if (context.thread_index() < shared_array_size) - shared_array[context.thread_index()] = sum; - - // accumulate remaining values (if any) to shared memory in stages - if (context.block_dimension() > shared_array_size) - { - unsigned int lb = shared_array_size; - unsigned int ub = shared_array_size + lb; - - while (lb < context.block_dimension()) - { - context.barrier(); - - if (lb <= context.thread_index() && context.thread_index() < ub) - { - OutputType tmp = shared_array[context.thread_index() - lb]; - shared_array[context.thread_index() - lb] = binary_op(tmp, sum); - } - - lb += shared_array_size; - ub += shared_array_size; - } - } - } - - context.barrier(); - - block::reduce_n(context, shared_array, thrust::min(range.size(), shared_array_size), binary_op); - - if (context.thread_index() == 0) - { - output += context.block_index(); - *output = shared_array[0]; - } - } -}; - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN - -template -void reduce_intervals(execution_policy &, - InputIterator input, - OutputIterator output, - BinaryFunction binary_op, - Decomposition decomp) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - if (decomp.size() == 0) - return; - - // TODO if (decomp.size() > deviceProperties.maxGridSize[0]) throw cuda exception (or handle general case) - - typedef detail::blocked_thread_array Context; - typedef commutative_reduce_intervals_closure Closure; - typedef typename thrust::iterator_value::type OutputType; - - detail::launch_calculator calculator; - - thrust::tuple config = calculator.with_variable_block_size_available_smem(); - - //size_t max_blocks = thrust::get<0>(config); - size_t block_size = thrust::get<1>(config); - size_t max_memory = thrust::get<2>(config); - - // determine shared array size - size_t shared_array_size = thrust::min(max_memory / sizeof(OutputType), block_size); - size_t shared_array_bytes = sizeof(OutputType) * shared_array_size; - - // TODO if (shared_array_size < 1) throw cuda exception "insufficient shared memory" - - Closure closure(input, output, binary_op, decomp, shared_array_size); - detail::launch_closure(closure, decomp.size(), block_size, shared_array_bytes); -} - -__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/remove.h b/compat/thrust/system/cuda/detail/remove.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/remove.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/replace.h b/compat/thrust/system/cuda/detail/replace.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/replace.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/reverse.h b/compat/thrust/system/cuda/detail/reverse.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/reverse.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/runtime_introspection.h b/compat/thrust/system/cuda/detail/runtime_introspection.h deleted file mode 100644 index 39f6c9f..0000000 --- a/compat/thrust/system/cuda/detail/runtime_introspection.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file runtime_introspection.h - * \brief Defines the interface to functions - * providing introspection into the architecture - * of CUDA devices. - */ - -#pragma once - -#include - -// #include this for device_properties_t and function_attributes_t -#include - -// #include this for size_t -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -/*! Returns the current device ordinal. - */ -inline int current_device(); - -/*! Returns a copy of the device_properties_t structure - * that is associated with a given device. - */ -inline device_properties_t device_properties(int device_id); - -/*! Returns a copy of the device_properties_t structure - * that is associated with the current device. - */ -inline device_properties_t device_properties(void); - -/*! Returns a copy of the function_attributes_t structure - * that is associated with a given __global__ function - */ -template -inline function_attributes_t function_attributes(KernelFunction kernel); - -/*! Returns the compute capability of a device in integer format. - * For example, returns 10 for sm_10 and 21 for sm_21 - * \return The compute capability as an integer - */ -inline size_t compute_capability(const device_properties_t &properties); -inline size_t compute_capability(void); - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/runtime_introspection.inl b/compat/thrust/system/cuda/detail/runtime_introspection.inl deleted file mode 100644 index a5cc382..0000000 --- a/compat/thrust/system/cuda/detail/runtime_introspection.inl +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace runtime_introspection_detail -{ - - -inline void get_device_properties(device_properties_t &p, int device_id) -{ - cudaDeviceProp properties; - - cudaError_t error = cudaGetDeviceProperties(&properties, device_id); - - if(error) - throw thrust::system_error(error, thrust::cuda_category()); - - // be careful about how this is initialized! - device_properties_t temp = { - properties.major, - { - properties.maxGridSize[0], - properties.maxGridSize[1], - properties.maxGridSize[2] - }, - properties.maxThreadsPerBlock, - properties.maxThreadsPerMultiProcessor, - properties.minor, - properties.multiProcessorCount, - properties.regsPerBlock, - properties.sharedMemPerBlock, - properties.warpSize - }; - - p = temp; -} // end get_device_properties() - - -} // end runtime_introspection_detail - - -inline device_properties_t device_properties(int device_id) -{ - // cache the result of get_device_properties, because it is slow - // only cache the first few devices - static const int max_num_devices = 16; - - static bool properties_exist[max_num_devices] = {0}; - static device_properties_t device_properties[max_num_devices] = {}; - - if(device_id >= max_num_devices) - { - device_properties_t result; - runtime_introspection_detail::get_device_properties(result, device_id); - return result; - } - - if(!properties_exist[device_id]) - { - runtime_introspection_detail::get_device_properties(device_properties[device_id], device_id); - - // disallow the compiler to move the write to properties_exist[device_id] - // before the initialization of device_properties[device_id] - __thrust_compiler_fence(); - - properties_exist[device_id] = true; - } - - return device_properties[device_id]; -} - -inline int current_device() -{ - int result = -1; - - cudaError_t error = cudaGetDevice(&result); - - if(error) - throw thrust::system_error(error, thrust::cuda_category()); - - if(result < 0) - throw thrust::system_error(cudaErrorNoDevice, thrust::cuda_category()); - - return result; -} - -inline device_properties_t device_properties(void) -{ - return device_properties(current_device()); -} - -template -inline function_attributes_t function_attributes(KernelFunction kernel) -{ -// cudaFuncGetAttributes(), used below, only exists when __CUDACC__ is defined -#ifdef __CUDACC__ - typedef void (*fun_ptr_type)(); - - fun_ptr_type fun_ptr = reinterpret_cast(kernel); - - cudaFuncAttributes attributes; - - cudaError_t error = cudaFuncGetAttributes(&attributes, fun_ptr); - - if(error) - { - throw thrust::system_error(error, thrust::cuda_category()); - } - - // be careful about how this is initialized! - function_attributes_t result = { - attributes.constSizeBytes, - attributes.localSizeBytes, - attributes.maxThreadsPerBlock, - attributes.numRegs, - attributes.sharedSizeBytes - }; - - return result; -#else - return function_attributes_t(); -#endif // __CUDACC__ -} - -inline size_t compute_capability(const device_properties_t &properties) -{ - return 10 * properties.major + properties.minor; -} - -inline size_t compute_capability(void) -{ - return compute_capability(device_properties()); -} - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/scan.h b/compat/thrust/system/cuda/detail/scan.h deleted file mode 100644 index 036c89a..0000000 --- a/compat/thrust/system/cuda/detail/scan.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.h - * \brief Scan operations (parallel prefix-sum) [cuda] - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - OutputIterator inclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - AssociativeOperator binary_op); - -template - OutputIterator exclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - AssociativeOperator binary_op); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/scan.inl b/compat/thrust/system/cuda/detail/scan.inl deleted file mode 100644 index 9d9c6d2..0000000 --- a/compat/thrust/system/cuda/detail/scan.inl +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.inl - * \brief Inline file for scan.h. - */ - -#include -#include - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - OutputIterator inclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - AssociativeOperator binary_op) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - return thrust::system::cuda::detail::detail::fast_scan::inclusive_scan(exec, first, last, result, binary_op); -} - -template - OutputIterator exclusive_scan(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - AssociativeOperator binary_op) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - return thrust::system::cuda::detail::detail::fast_scan::exclusive_scan(exec, first, last, result, init, binary_op); -} - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/scan_by_key.h b/compat/thrust/system/cuda/detail/scan_by_key.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/scan_by_key.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/scatter.h b/compat/thrust/system/cuda/detail/scatter.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/scatter.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/sequence.h b/compat/thrust/system/cuda/detail/sequence.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/sequence.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/set_difference.inl b/compat/thrust/system/cuda/detail/set_difference.inl deleted file mode 100644 index 33d9884..0000000 --- a/compat/thrust/system/cuda/detail/set_difference.inl +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace set_difference_detail -{ - - -struct serial_bounded_set_difference -{ - // max_input_size <= 32 - template - inline __device__ - thrust::detail::uint32_t operator()(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp) - { - thrust::detail::uint32_t active_mask = 0; - thrust::detail::uint32_t active_bit = 1; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - *result = *first1; - active_mask |= active_bit; - ++first1; - } // end if - else if(comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - ++first1; - ++first2; - } // end else - - ++result; - active_bit <<= 1; - } // end while - - while(first1 != last1) - { - *result = *first1; - ++first1; - ++result; - active_mask |= active_bit; - active_bit <<= 1; - } - - return active_mask; - } - - - template - inline __device__ - Size count(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - Size result = 0; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - ++first1; - ++result; - } // end if - else if(comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - ++first1; - ++first2; - } // end else - } // end while - - return result + last1 - first1; - } -}; // end serial_bounded_set_difference - - -} // end namespace set_difference_detail - - -template -RandomAccessIterator3 set_difference(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp) -{ - return thrust::system::cuda::detail::detail::set_operation(exec, first1, last1, first2, last2, result, comp, set_difference_detail::serial_bounded_set_difference()); -} // end set_difference - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/set_intersection.inl b/compat/thrust/system/cuda/detail/set_intersection.inl deleted file mode 100644 index e4810b6..0000000 --- a/compat/thrust/system/cuda/detail/set_intersection.inl +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace set_intersection_detail -{ - - -struct serial_bounded_set_intersection -{ - // max_input_size <= 32 - template - inline __device__ - thrust::detail::uint32_t operator()(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp) - { - thrust::detail::uint32_t active_mask = 0; - thrust::detail::uint32_t active_bit = 1; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - ++first1; - } // end if - else if(comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - *result = *first1; - ++first1; - ++first2; - active_mask |= active_bit; - } // end else - - ++result; - active_bit <<= 1; - } // end while - - return active_mask; - } - - - template - inline __device__ - Size count(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - Size result = 0; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - ++first1; - } // end if - else if(comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - ++result; - ++first1; - ++first2; - } // end else - } // end while - - return result; - } -}; // end serial_bounded_set_intersection - - -} // end namespace set_intersection_detail - - -template -RandomAccessIterator3 set_intersection(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp) -{ - return thrust::system::cuda::detail::detail::set_operation(exec, first1, last1, first2, last2, result, comp, set_intersection_detail::serial_bounded_set_intersection()); -} // end set_intersection - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/set_operations.h b/compat/thrust/system/cuda/detail/set_operations.h deleted file mode 100644 index 040e341..0000000 --- a/compat/thrust/system/cuda/detail/set_operations.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template -RandomAccessIterator3 set_difference(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp); - - -template -RandomAccessIterator3 set_intersection(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp); - - -template -RandomAccessIterator3 set_symmetric_difference(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp); - - -template -RandomAccessIterator3 set_union(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp); - - -} // end detail -} // end cuda -} // end system -} // end thrust - -#include -#include -#include -#include - diff --git a/compat/thrust/system/cuda/detail/set_symmetric_difference.inl b/compat/thrust/system/cuda/detail/set_symmetric_difference.inl deleted file mode 100644 index 112c955..0000000 --- a/compat/thrust/system/cuda/detail/set_symmetric_difference.inl +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace set_symmetric_difference_detail -{ - - -struct serial_bounded_set_symmetric_difference -{ - // max_input_size <= 32 - template - inline __device__ - thrust::detail::uint32_t operator()(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp) - { - thrust::detail::uint32_t active_mask = 0; - thrust::detail::uint32_t active_bit = 1; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - *result = *first1; - active_mask |= active_bit; - ++first1; - } // end if - else if(comp(*first2,*first1)) - { - *result = *first2; - active_mask |= active_bit; - ++first2; - } // end else if - else - { - ++first1; - ++first2; - } // end else - - ++result; - active_bit <<= 1; - } // end while - - while(first1 != last1) - { - *result = *first1; - ++first1; - ++result; - active_mask |= active_bit; - active_bit <<= 1; - } - - while(first2 != last2) - { - *result = *first2; - ++first2; - ++result; - active_mask |= active_bit; - active_bit <<= 1; - } - - return active_mask; - } - - - template - inline __device__ - Size count(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - Size result = 0; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - ++first1; - ++result; - } // end if - else if(comp(*first2,*first1)) - { - ++first2; - ++result; - } // end else if - else - { - ++first1; - ++first2; - } // end else - } // end while - - return result + thrust::max(last1 - first1,last2 - first2); - } -}; // end serial_bounded_set_symmetric_difference - - -} // end namespace set_symmetric_difference_detail - - -template -RandomAccessIterator3 set_symmetric_difference(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp) -{ - return thrust::system::cuda::detail::detail::set_operation(exec, first1, last1, first2, last2, result, comp, set_symmetric_difference_detail::serial_bounded_set_symmetric_difference()); -} // end set_symmetric_difference - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/set_union.inl b/compat/thrust/system/cuda/detail/set_union.inl deleted file mode 100644 index 66cccab..0000000 --- a/compat/thrust/system/cuda/detail/set_union.inl +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ -namespace set_union_detail -{ - - -struct serial_bounded_set_union -{ - // max_input_size <= 32 - template - inline __device__ - thrust::detail::uint32_t operator()(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - Compare comp) - { - thrust::detail::uint32_t active_mask = 0; - thrust::detail::uint32_t active_bit = 1; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - *result = *first1; - ++first1; - } // end if - else if(comp(*first2,*first1)) - { - *result = *first2; - ++first2; - } // end else if - else - { - *result = *first1; - ++first1; - ++first2; - } // end else - - ++result; - active_mask |= active_bit; - active_bit <<= 1; - } // end while - - while(first1 != last1) - { - *result = *first1; - ++first1; - ++result; - active_mask |= active_bit; - active_bit <<= 1; - } - - while(first2 != last2) - { - *result = *first2; - ++first2; - ++result; - active_mask |= active_bit; - active_bit <<= 1; - } - - return active_mask; - } - - - template - inline __device__ - Size count(Size max_input_size, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - Size result = 0; - - while(first1 != last1 && first2 != last2) - { - if(comp(*first1,*first2)) - { - ++first1; - } // end if - else if(comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - ++first1; - ++first2; - } // end else - - ++result; - } // end while - - return result + thrust::max(last1 - first1,last2 - first2); - } -}; // end serial_bounded_set_union - - -} // end namespace set_union_detail - - -template -RandomAccessIterator3 set_union(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - RandomAccessIterator2 last2, - RandomAccessIterator3 result, - Compare comp) -{ - return thrust::system::cuda::detail::detail::set_operation(exec, first1, last1, first2, last2, result, comp, set_union_detail::serial_bounded_set_union()); -} // end set_union - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/sort.h b/compat/thrust/system/cuda/detail/sort.h deleted file mode 100644 index e78d36a..0000000 --- a/compat/thrust/system/cuda/detail/sort.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - void stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - -template - void stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/sort.inl b/compat/thrust/system/cuda/detail/sort.inl deleted file mode 100644 index d7e0a60..0000000 --- a/compat/thrust/system/cuda/detail/sort.inl +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file sort.inl - * \brief Inline file for sort.h - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - - -/* - * This file implements the following dispatch procedure for cuda::stable_sort() - * and cuda::stable_sort_by_key(). The first level inspects the KeyType - * and StrictWeakOrdering to determine whether a sort assuming primitive-typed - * data may be applied. - * - * If a sort assuming primitive-typed data can be applied (i.e., a radix sort), - * the input ranges are first trivialized (turned into simple contiguous ranges - * if they are not already). To implement descending orderings, an ascending - * sort will be reversed. - * - * If a sort assuming primitive-typed data cannot be applied, a comparison-based - * sort is used. Depending on the size of the key and value types, one level of - * indirection may be applied to their input ranges. This transformation - * may be applied to either range to convert an ill-suited problem (i.e. sorting with - * large keys or large value) into a problem more amenable to the underlying - * merge sort algorithm. - */ - - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -namespace stable_sort_detail -{ - - -template - struct can_use_primitive_sort - : thrust::detail::and_< - thrust::detail::is_arithmetic, - thrust::detail::or_< - thrust::detail::is_same >, - thrust::detail::is_same > - > - > -{}; - - -template - struct enable_if_primitive_sort - : thrust::detail::enable_if< - can_use_primitive_sort< - typename iterator_value::type, - StrictWeakCompare - >::value - > -{}; - - -template - struct enable_if_comparison_sort - : thrust::detail::disable_if< - can_use_primitive_sort< - typename iterator_value::type, - StrictWeakCompare - >::value - > -{}; - - -template - typename enable_if_primitive_sort::type - stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // ensure sequence has trivial iterators - thrust::detail::trivial_sequence keys(exec, first, last); - - // CUDA path for thrust::stable_sort with primitive keys - // (e.g. int, float, short, etc.) and a less or greater comparison - // method is implemented with a primitive sort - thrust::system::cuda::detail::detail::stable_primitive_sort(exec, keys.begin(), keys.end()); - - // copy results back, if necessary - if(!thrust::detail::is_trivial_iterator::value) - { - thrust::copy(exec, keys.begin(), keys.end(), first); - } - - // if comp is greater then reverse the keys - typedef typename thrust::iterator_traits::value_type KeyType; - const static bool reverse = thrust::detail::is_same >::value; - - if(reverse) - { - thrust::reverse(first, last); - } -} - -template - typename enable_if_comparison_sort::type - stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // decide whether to sort keys indirectly - typedef typename thrust::iterator_value::type KeyType; - typedef thrust::detail::integral_constant 8)> use_key_indirection; - - conditional_temporary_indirect_ordering potentially_indirect_keys(derived_cast(exec), first, last, comp); - - thrust::system::cuda::detail::detail::stable_merge_sort(exec, - potentially_indirect_keys.begin(), - potentially_indirect_keys.end(), - potentially_indirect_keys.comp()); -} - -template - typename enable_if_primitive_sort::type - stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - // path for thrust::stable_sort_by_key with primitive keys - // (e.g. int, float, short, etc.) and a less or greater comparison - // method is implemented with stable_primitive_sort_by_key - - // if comp is greater then reverse the keys and values - typedef typename thrust::iterator_traits::value_type KeyType; - const static bool reverse = thrust::detail::is_same >::value; - - // note, we also have to reverse the (unordered) input to preserve stability - if (reverse) - { - thrust::reverse(exec, keys_first, keys_last); - thrust::reverse(exec, values_first, values_first + (keys_last - keys_first)); - } - - // ensure sequences have trivial iterators - thrust::detail::trivial_sequence keys(exec, keys_first, keys_last); - thrust::detail::trivial_sequence values(exec, values_first, values_first + (keys_last - keys_first)); - - thrust::system::cuda::detail::detail::stable_primitive_sort_by_key(exec, keys.begin(), keys.end(), values.begin()); - - // copy results back, if necessary - if(!thrust::detail::is_trivial_iterator::value) - thrust::copy(exec, keys.begin(), keys.end(), keys_first); - if(!thrust::detail::is_trivial_iterator::value) - thrust::copy(exec, values.begin(), values.end(), values_first); - - if (reverse) - { - thrust::reverse(exec, keys_first, keys_last); - thrust::reverse(exec, values_first, values_first + (keys_last - keys_first)); - } -} - - -template - typename enable_if_comparison_sort::type - stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - // decide whether to apply indirection to either range - typedef typename thrust::iterator_value::type KeyType; - typedef typename thrust::iterator_value::type ValueType; - - typedef thrust::detail::integral_constant 8)> use_key_indirection; - typedef thrust::detail::integral_constant 4)> use_value_indirection; - - conditional_temporary_indirect_ordering< - use_key_indirection, - DerivedPolicy, - RandomAccessIterator1, - StrictWeakOrdering - > potentially_indirect_keys(derived_cast(exec), keys_first, keys_last, comp); - - conditional_temporary_indirect_permutation< - use_value_indirection, - DerivedPolicy, - RandomAccessIterator2 - > potentially_indirect_values(derived_cast(exec), values_first, values_first + (keys_last - keys_first)); - - thrust::system::cuda::detail::detail::stable_merge_sort_by_key(exec, - potentially_indirect_keys.begin(), - potentially_indirect_keys.end(), - potentially_indirect_values.begin(), - potentially_indirect_keys.comp()); -} - - -} // end namespace stable_sort_detail - - -template - void stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - stable_sort_detail::stable_sort(exec, first, last, comp); -} - - -template - void stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - // we're attempting to launch a kernel, assert we're compiling with nvcc - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to compile your code using nvcc, rather than g++ or cl.exe X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - stable_sort_detail::stable_sort_by_key(exec, keys_first, keys_last, values_first, comp); -} - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/swap_ranges.h b/compat/thrust/system/cuda/detail/swap_ranges.h deleted file mode 100644 index 9b1949e..0000000 --- a/compat/thrust/system/cuda/detail/swap_ranges.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// cuda has no special swap_ranges - diff --git a/compat/thrust/system/cuda/detail/synchronize.h b/compat/thrust/system/cuda/detail/synchronize.h deleted file mode 100644 index 762f4a3..0000000 --- a/compat/thrust/system/cuda/detail/synchronize.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -inline void synchronize(const char *message = ""); - -inline void synchronize_if_enabled(const char *message = ""); - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/synchronize.inl b/compat/thrust/system/cuda/detail/synchronize.inl deleted file mode 100644 index 5f70f79..0000000 --- a/compat/thrust/system/cuda/detail/synchronize.inl +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -void synchronize(const char *message) -{ - cudaError_t error = cudaThreadSynchronize(); - if(error) - { - throw thrust::system_error(error, thrust::cuda_category(), std::string("synchronize: ") + message); - } // end if -} // end synchronize() - -void synchronize_if_enabled(const char *message) -{ -// XXX this could potentially be a runtime decision -#if __THRUST_SYNCHRONOUS - synchronize(message); -#else - // WAR "unused parameter" warning - (void) message; -#endif -} // end synchronize_if_enabled() - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/tabulate.h b/compat/thrust/system/cuda/detail/tabulate.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/tabulate.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/temporary_buffer.h b/compat/thrust/system/cuda/detail/temporary_buffer.h deleted file mode 100644 index 628bd75..0000000 --- a/compat/thrust/system/cuda/detail/temporary_buffer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special temporary buffer functions - diff --git a/compat/thrust/system/cuda/detail/temporary_indirect_permutation.h b/compat/thrust/system/cuda/detail/temporary_indirect_permutation.h deleted file mode 100644 index 3d05f44..0000000 --- a/compat/thrust/system/cuda/detail/temporary_indirect_permutation.h +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - - -template - struct temporary_indirect_permutation -{ - private: - typedef unsigned int size_type; - typedef thrust::detail::temporary_array array_type; - - public: - temporary_indirect_permutation(DerivedPolicy &exec, RandomAccessIterator first, RandomAccessIterator last) - : m_exec(exec), - m_src_first(first), - m_src_last(last), - m_permutation(0, m_exec, last - first) - { - // generate sorted index sequence - thrust::sequence(exec, m_permutation.begin(), m_permutation.end()); - } - - ~temporary_indirect_permutation() - { - // permute the source array using the indices - typedef typename thrust::iterator_value::type value_type; - thrust::detail::temporary_array temp(m_exec, m_src_first, m_src_last); - thrust::gather(m_exec, m_permutation.begin(), m_permutation.end(), temp.begin(), m_src_first); - } - - typedef typename array_type::iterator iterator; - - iterator begin() - { - return m_permutation.begin(); - } - - iterator end() - { - return m_permutation.end(); - } - - private: - DerivedPolicy &m_exec; - RandomAccessIterator m_src_first, m_src_last; - thrust::detail::temporary_array m_permutation; -}; - - -template - struct iterator_range_with_execution_policy -{ - iterator_range_with_execution_policy(DerivedPolicy &exec, RandomAccessIterator first, RandomAccessIterator last) - : m_exec(exec), m_first(first), m_last(last) - {} - - typedef RandomAccessIterator iterator; - - iterator begin() - { - return m_first; - } - - iterator end() - { - return m_last; - } - - DerivedPolicy &exec() - { - return m_exec; - } - - DerivedPolicy &m_exec; - RandomAccessIterator m_first, m_last; -}; - - -template - struct conditional_temporary_indirect_permutation - : thrust::detail::eval_if< - Condition::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - >::type -{ - typedef typename thrust::detail::eval_if< - Condition::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - >::type super_t; - - conditional_temporary_indirect_permutation(DerivedPolicy &exec, RandomAccessIterator first, RandomAccessIterator last) - : super_t(exec, first, last) - {} -}; - - -template - struct temporary_indirect_ordering - : temporary_indirect_permutation -{ - private: - typedef temporary_indirect_permutation super_t; - - public: - temporary_indirect_ordering(DerivedPolicy &exec, RandomAccessIterator first, RandomAccessIterator last, Compare comp) - : super_t(exec, first, last), - m_comp(first, comp) - {} - - struct compare - { - RandomAccessIterator first; - - thrust::detail::host_device_function< - Compare, - bool - > comp; - - compare(RandomAccessIterator first, Compare comp) - : first(first), comp(comp) - {} - - template - __host__ __device__ - bool operator()(Integral a, Integral b) - { - return comp(first[a], first[b]); - } - }; - - compare comp() const - { - return m_comp; - } - - private: - compare m_comp; -}; - - -template - struct iterator_range_with_execution_policy_and_compare - : iterator_range_with_execution_policy -{ - typedef iterator_range_with_execution_policy super_t; - - iterator_range_with_execution_policy_and_compare(DerivedPolicy &exec, RandomAccessIterator first, RandomAccessIterator last, Compare comp) - : super_t(exec, first, last), m_comp(comp) - {} - - typedef Compare compare; - - compare comp() - { - return m_comp; - } - - Compare m_comp; -}; - - -template - struct conditional_temporary_indirect_ordering - : thrust::detail::eval_if< - Condition::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - >::type -{ - typedef typename thrust::detail::eval_if< - Condition::value, - thrust::detail::identity_ >, - thrust::detail::identity_ > - >::type super_t; - - conditional_temporary_indirect_ordering(DerivedPolicy &exec, RandomAccessIterator first, RandomAccessIterator last, Compare comp) - : super_t(exec, first, last, comp) - {} -}; - - -} // end detail -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/detail/transform.h b/compat/thrust/system/cuda/detail/transform.h deleted file mode 100644 index 0af8705..0000000 --- a/compat/thrust/system/cuda/detail/transform.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// cuda has no special transform - diff --git a/compat/thrust/system/cuda/detail/transform_reduce.h b/compat/thrust/system/cuda/detail/transform_reduce.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/transform_reduce.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/transform_scan.h b/compat/thrust/system/cuda/detail/transform_scan.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/transform_scan.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/trivial_copy.h b/compat/thrust/system/cuda/detail/trivial_copy.h deleted file mode 100644 index e0e898a..0000000 --- a/compat/thrust/system/cuda/detail/trivial_copy.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -template - void trivial_copy_n(execution_policy &exec, - RandomAccessIterator1 first, - Size n, - RandomAccessIterator2 result); - -template - void trivial_copy_n(cross_system &exec, - RandomAccessIterator1 first, - Size n, - RandomAccessIterator2 result); - -} // end detail -} // end cuda -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/detail/trivial_copy.inl b/compat/thrust/system/cuda/detail/trivial_copy.inl deleted file mode 100644 index d23a4ef..0000000 --- a/compat/thrust/system/cuda/detail/trivial_copy.inl +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ -namespace detail -{ - -namespace trivial_copy_detail -{ - -inline void checked_cudaMemcpy(void *dst, const void *src, size_t count, enum cudaMemcpyKind kind) -{ - cudaError_t error = cudaMemcpy(dst,src,count,kind); - if(error) - { - throw thrust::system_error(error, thrust::cuda_category()); - } // end error -} // end checked_cudaMemcpy() - - -template - cudaMemcpyKind cuda_memcpy_kind(const thrust::cuda::execution_policy &, - const thrust::cpp::execution_policy &) -{ - return cudaMemcpyDeviceToHost; -} // end cuda_memcpy_kind() - - -template - cudaMemcpyKind cuda_memcpy_kind(const thrust::cpp::execution_policy &, - const thrust::cuda::execution_policy &) -{ - return cudaMemcpyHostToDevice; -} // end cuda_memcpy_kind() - - -} // end namespace trivial_copy_detail - - -template - void trivial_copy_n(execution_policy &exec, - RandomAccessIterator1 first, - Size n, - RandomAccessIterator2 result) -{ - typedef typename thrust::iterator_value::type T; - - void *dst = thrust::raw_pointer_cast(&*result); - const void *src = thrust::raw_pointer_cast(&*first); - - trivial_copy_detail::checked_cudaMemcpy(dst, src, n * sizeof(T), cudaMemcpyDeviceToDevice); -} - - -template - void trivial_copy_n(cross_system &systems, - RandomAccessIterator1 first, - Size n, - RandomAccessIterator2 result) -{ - typedef typename thrust::iterator_value::type T; - - void *dst = thrust::raw_pointer_cast(&*result); - const void *src = thrust::raw_pointer_cast(&*first); - - cudaMemcpyKind kind = trivial_copy_detail::cuda_memcpy_kind(thrust::detail::derived_cast(systems.system1), thrust::detail::derived_cast(systems.system2)); - - trivial_copy_detail::checked_cudaMemcpy(dst, src, n * sizeof(T), kind); -} - - -} // end namespace detail -} // end namespace cuda -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/cuda/detail/uninitialized_copy.h b/compat/thrust/system/cuda/detail/uninitialized_copy.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/uninitialized_copy.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/uninitialized_fill.h b/compat/thrust/system/cuda/detail/uninitialized_fill.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/uninitialized_fill.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/unique.h b/compat/thrust/system/cuda/detail/unique.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/unique.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/unique_by_key.h b/compat/thrust/system/cuda/detail/unique_by_key.h deleted file mode 100644 index a307fc5..0000000 --- a/compat/thrust/system/cuda/detail/unique_by_key.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special version of this algorithm - diff --git a/compat/thrust/system/cuda/detail/vector.inl b/compat/thrust/system/cuda/detail/vector.inl deleted file mode 100644 index 3659876..0000000 --- a/compat/thrust/system/cuda/detail/vector.inl +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ccudaliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ - -template - vector - ::vector() - : super_t() -{} - -template - vector - ::vector(size_type n) - : super_t(n) -{} - -template - vector - ::vector(size_type n, const value_type &value) - : super_t(n,value) -{} - -template - vector - ::vector(const vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(const thrust::detail::vector_base &x) - : super_t(x) -{} - -template - template - vector - ::vector(const std::vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(InputIterator first, InputIterator last) - : super_t(first,last) -{} - -template - template - vector & - vector - ::operator=(const std::vector &x) -{ - super_t::operator=(x); - return *this; -} - -template - template - vector & - vector - ::operator=(const thrust::detail::vector_base &x) -{ - super_t::operator=(x); - return *this; -} - -} // end cuda -} // end system -} // end thrust - diff --git a/compat/thrust/system/cuda/error.h b/compat/thrust/system/cuda/error.h deleted file mode 100644 index 8d09853..0000000 --- a/compat/thrust/system/cuda/error.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file thrust/system/cuda/error.h - * \brief CUDA-specific error reporting - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace system -{ - -namespace cuda -{ - -/*! \addtogroup system - * \{ - */ - -// To construct an error_code after a CUDA Runtime error: -// -// error_code(::cudaGetLastError(), cuda_category()) - -// XXX N3000 prefers enum class errc { ... } -namespace errc -{ - -/*! \p errc_t enumerates the kinds of CUDA Runtime errors. - */ -enum errc_t -{ - // from cuda/include/driver_types.h - // mirror their order - success = cudaSuccess, - missing_configuration = cudaErrorMissingConfiguration, - memory_allocation = cudaErrorMemoryAllocation, - initialization_error = cudaErrorInitializationError, - launch_failure = cudaErrorLaunchFailure, - prior_launch_failure = cudaErrorPriorLaunchFailure, - launch_timeout = cudaErrorLaunchTimeout, - launch_out_of_resources = cudaErrorLaunchOutOfResources, - invalid_device_function = cudaErrorInvalidDeviceFunction, - invalid_configuration = cudaErrorInvalidConfiguration, - invalid_device = cudaErrorInvalidDevice, - invalid_value = cudaErrorInvalidValue, - invalid_pitch_value = cudaErrorInvalidPitchValue, - invalid_symbol = cudaErrorInvalidSymbol, - map_buffer_object_failed = cudaErrorMapBufferObjectFailed, - unmap_buffer_object_failed = cudaErrorUnmapBufferObjectFailed, - invalid_host_pointer = cudaErrorInvalidHostPointer, - invalid_device_pointer = cudaErrorInvalidDevicePointer, - invalid_texture = cudaErrorInvalidTexture, - invalid_texture_binding = cudaErrorInvalidTextureBinding, - invalid_channel_descriptor = cudaErrorInvalidChannelDescriptor, - invalid_memcpy_direction = cudaErrorInvalidMemcpyDirection, - address_of_constant_error = cudaErrorAddressOfConstant, - texture_fetch_failed = cudaErrorTextureFetchFailed, - texture_not_bound = cudaErrorTextureNotBound, - synchronization_error = cudaErrorSynchronizationError, - invalid_filter_setting = cudaErrorInvalidFilterSetting, - invalid_norm_setting = cudaErrorInvalidNormSetting, - mixed_device_execution = cudaErrorMixedDeviceExecution, - cuda_runtime_unloading = cudaErrorCudartUnloading, - unknown = cudaErrorUnknown, - not_yet_implemented = cudaErrorNotYetImplemented, - memory_value_too_large = cudaErrorMemoryValueTooLarge, - invalid_resource_handle = cudaErrorInvalidResourceHandle, - not_ready = cudaErrorNotReady, - insufficient_driver = cudaErrorInsufficientDriver, - set_on_active_process_error = cudaErrorSetOnActiveProcess, - no_device = cudaErrorNoDevice, - ecc_uncorrectable = cudaErrorECCUncorrectable, - -#if CUDART_VERSION >= 4020 - shared_object_symbol_not_found = cudaErrorSharedObjectSymbolNotFound, - shared_object_init_failed = cudaErrorSharedObjectInitFailed, - unsupported_limit = cudaErrorUnsupportedLimit, - duplicate_variable_name = cudaErrorDuplicateVariableName, - duplicate_texture_name = cudaErrorDuplicateTextureName, - duplicate_surface_name = cudaErrorDuplicateSurfaceName, - devices_unavailable = cudaErrorDevicesUnavailable, - invalid_kernel_image = cudaErrorInvalidKernelImage, - no_kernel_image_for_device = cudaErrorNoKernelImageForDevice, - incompatible_driver_context = cudaErrorIncompatibleDriverContext, - peer_access_already_enabled = cudaErrorPeerAccessAlreadyEnabled, - peer_access_not_enabled = cudaErrorPeerAccessNotEnabled, - device_already_in_use = cudaErrorDeviceAlreadyInUse, - profiler_disabled = cudaErrorProfilerDisabled, - assert_triggered = cudaErrorAssert, - too_many_peers = cudaErrorTooManyPeers, - host_memory_already_registered = cudaErrorHostMemoryAlreadyRegistered, - host_memory_not_registered = cudaErrorHostMemoryNotRegistered, - operating_system_error = cudaErrorOperatingSystem, -#endif - -#if CUDART_VERSION >= 5000 - peer_access_unsupported = cudaErrorPeerAccessUnsupported, - launch_max_depth_exceeded = cudaErrorLaunchMaxDepthExceeded, - launch_file_scoped_texture_used = cudaErrorLaunchFileScopedTex, - launch_file_scoped_surface_used = cudaErrorLaunchFileScopedSurf, - sync_depth_exceeded = cudaErrorSyncDepthExceeded, - attempted_operation_not_permitted = cudaErrorNotPermitted, - attempted_operation_not_supported = cudaErrorNotSupported, -#endif - - startup_failure = cudaErrorStartupFailure -}; // end errc_t - - -} // end namespace errc - -} // end namespace cuda - -/*! \return A reference to an object of a type derived from class \p thrust::error_category. - * \note The object's \p equivalent virtual functions shall behave as specified - * for the class \p thrust::error_category. The object's \p name virtual function shall - * return a pointer to the string "cuda". The object's - * \p default_error_condition virtual function shall behave as follows: - * - * If the argument ev corresponds to a CUDA error value, the function - * shall return error_condition(ev,cuda_category()). - * Otherwise, the function shall return system_category.default_error_condition(ev). - */ -inline const error_category &cuda_category(void); - - -// XXX N3000 prefers is_error_code_enum - -/*! Specialization of \p is_error_code_enum for \p cuda::errc::errc_t - */ -template<> struct is_error_code_enum : thrust::detail::true_type {}; - - -// XXX replace cuda::errc::errc_t with cuda::errc upon c++0x -/*! \return error_code(static_cast(e), cuda::error_category()) - */ -inline error_code make_error_code(cuda::errc::errc_t e); - - -// XXX replace cuda::errc::errc_t with cuda::errc upon c++0x -/*! \return error_condition(static_cast(e), cuda::error_category()). - */ -inline error_condition make_error_condition(cuda::errc::errc_t e); - -/*! \} // end system - */ - - -} // end system - -namespace cuda -{ - -// XXX replace with using system::cuda_errc upon c++0x -namespace errc = system::cuda::errc; - -} // end cuda - -using system::cuda_category; - -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/cuda/execution_policy.h b/compat/thrust/system/cuda/execution_policy.h deleted file mode 100644 index bbd33de..0000000 --- a/compat/thrust/system/cuda/execution_policy.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -/*! \file thrust/system/cuda/execution_policy.h - * \brief Execution policies for Thrust's CUDA system. - */ - -#include - -// get the execution policies definitions first -#include - -// get the definition of par -#include - -// now get all the algorithm defintitions - -// the order of the following #includes seems to matter, unfortunately - -// primitives come first, in order of increasing sophistication -#include -#include -#include - -#include -#include -#include -#include -#include - -// these are alphabetical -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// define these entities here for the purpose of Doxygenating them -// they are actually defined elsewhere -#if 0 -namespace thrust -{ -namespace system -{ -namespace cuda -{ - - -/*! \addtogroup execution_policies - * \{ - */ - - -/*! \p thrust::cuda::execution_policy is the base class for all Thrust parallel execution - * policies which are derived from Thrust's CUDA backend system. - */ -template -struct execution_policy : thrust::execution_policy -{}; - - -/*! \p cuda::tag is a type representing Thrust's CUDA backend system in C++'s type system. - * Iterators "tagged" with a type which is convertible to \p cuda::tag assert that they may be - * "dispatched" to algorithm implementations in the \p cuda system. - */ -struct tag : thrust::system::cuda::execution_policy { unspecified }; - - -/*! \p thrust::cuda::par is the parallel execution policy associated with Thrust's CUDA - * backend system. - * - * Instead of relying on implicit algorithm dispatch through iterator system tags, users may - * directly target Thrust's CUDA backend system by providing \p thrust::cuda::par as an algorithm - * parameter. - * - * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such - * as \p thrust::cuda::vector. - * - * The type of \p thrust::cuda::par is implementation-defined. - * - * The following code snippet demonstrates how to use \p thrust::cuda::par to explicitly dispatch an - * invocation of \p thrust::for_each to the CUDA backend system: - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * printf("%d\n"); - * } - * }; - * ... - * int vec[3]; - * vec[0] = 0; vec[1] = 1; vec[2] = 2; - * - * thrust::for_each(thrust::cuda::par, vec.begin(), vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - */ -static const unspecified par; - - -/*! \} - */ - - -} // end cuda -} // end system -} // end thrust -#endif - - diff --git a/compat/thrust/system/cuda/experimental/pinned_allocator.h b/compat/thrust/system/cuda/experimental/pinned_allocator.h deleted file mode 100644 index 5294659..0000000 --- a/compat/thrust/system/cuda/experimental/pinned_allocator.h +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/cuda/experimental/pinned_allocator.h - * \brief An allocator which creates new elements in "pinned" memory with \p cudaMallocHost - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ - -namespace system -{ - -namespace cuda -{ - -namespace experimental -{ - -/*! \addtogroup memory_management Memory Management - * \addtogroup memory_management_classes - * \ingroup memory_management - * \{ - */ - -/*! \p pinned_allocator is a CUDA-specific host memory allocator - * that employs \c cudaMallocHost for allocation. - * - * \see http://www.sgi.com/tech/stl/Allocators.html - */ -template class pinned_allocator; - -template<> - class pinned_allocator -{ - public: - typedef void value_type; - typedef void * pointer; - typedef const void * const_pointer; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - - // convert a pinned_allocator to pinned_allocator - template - struct rebind - { - typedef pinned_allocator other; - }; // end rebind -}; // end pinned_allocator - - -template - class pinned_allocator -{ - public: - typedef T value_type; - typedef T* pointer; - typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - - // convert a pinned_allocator to pinned_allocator - template - struct rebind - { - typedef pinned_allocator other; - }; // end rebind - - /*! \p pinned_allocator's null constructor does nothing. - */ - __host__ __device__ - inline pinned_allocator() {} - - /*! \p pinned_allocator's null destructor does nothing. - */ - __host__ __device__ - inline ~pinned_allocator() {} - - /*! \p pinned_allocator's copy constructor does nothing. - */ - __host__ __device__ - inline pinned_allocator(pinned_allocator const &) {} - - /*! This version of \p pinned_allocator's copy constructor - * is templated on the \c value_type of the \p pinned_allocator - * to copy from. It is provided merely for convenience; it - * does nothing. - */ - template - __host__ __device__ - inline pinned_allocator(pinned_allocator const &) {} - - /*! This method returns the address of a \c reference of - * interest. - * - * \p r The \c reference of interest. - * \return \c r's address. - */ - __host__ __device__ - inline pointer address(reference r) { return &r; } - - /*! This method returns the address of a \c const_reference - * of interest. - * - * \p r The \c const_reference of interest. - * \return \c r's address. - */ - __host__ __device__ - inline const_pointer address(const_reference r) { return &r; } - - /*! This method allocates storage for objects in pinned host - * memory. - * - * \p cnt The number of objects to allocate. - * \return a \c pointer to the newly allocated objects. - * \note This method does not invoke \p value_type's constructor. - * It is the responsibility of the caller to initialize the - * objects at the returned \c pointer. - */ - __host__ - inline pointer allocate(size_type cnt, - const_pointer = 0) - { - if(cnt > this->max_size()) - { - throw std::bad_alloc(); - } // end if - - pointer result(0); - cudaError_t error = cudaMallocHost(reinterpret_cast(&result), cnt * sizeof(value_type)); - - if(error) - { - throw std::bad_alloc(); - } // end if - - return result; - } // end allocate() - - /*! This method deallocates pinned host memory previously allocated - * with this \c pinned_allocator. - * - * \p p A \c pointer to the previously allocated memory. - * \p cnt The number of objects previously allocated at - * \p p. - * \note This method does not invoke \p value_type's destructor. - * It is the responsibility of the caller to destroy - * the objects stored at \p p. - */ - __host__ - inline void deallocate(pointer p, size_type cnt) - { - cudaError_t error = cudaFreeHost(p); - - if(error) - { - throw thrust::system_error(error, thrust::cuda_category()); - } // end if - } // end deallocate() - - /*! This method returns the maximum size of the \c cnt parameter - * accepted by the \p allocate() method. - * - * \return The maximum number of objects that may be allocated - * by a single call to \p allocate(). - */ - inline size_type max_size() const - { - return (std::numeric_limits::max)() / sizeof(T); - } // end max_size() - - /*! This method tests this \p pinned_allocator for equality to - * another. - * - * \param x The other \p pinned_allocator of interest. - * \return This method always returns \c true. - */ - __host__ __device__ - inline bool operator==(pinned_allocator const& x) { return true; } - - /*! This method tests this \p pinned_allocator for inequality - * to another. - * - * \param x The other \p pinned_allocator of interest. - * \return This method always returns \c false. - */ - __host__ __device__ - inline bool operator!=(pinned_allocator const &x) { return !operator==(x); } -}; // end pinned_allocator - -/*! \} - */ - -} // end experimental - -} // end cuda - -} // end system - -// alias cuda's members at top-level -namespace cuda -{ - -namespace experimental -{ - -using thrust::system::cuda::experimental::pinned_allocator; - -} // end experimental - -} // end cuda - -} // end thrust - diff --git a/compat/thrust/system/cuda/memory.h b/compat/thrust/system/cuda/memory.h deleted file mode 100644 index 368eea2..0000000 --- a/compat/thrust/system/cuda/memory.h +++ /dev/null @@ -1,421 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ccudaliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/cuda/memory.h - * \brief Managing memory associated with Thrust's CUDA system. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace cuda -{ - -template class pointer; - -} // end cuda -} // end system -} // end thrust - - -/*! \cond - */ - -// specialize std::iterator_traits to avoid problems with the name of -// pointer's constructor shadowing its nested pointer type -// do this before pointer is defined so the specialization is correctly -// used inside the definition -namespace std -{ - -template - struct iterator_traits > -{ - private: - typedef thrust::system::cuda::pointer ptr; - - public: - typedef typename ptr::iterator_category iterator_category; - typedef typename ptr::value_type value_type; - typedef typename ptr::difference_type difference_type; - typedef ptr pointer; - typedef typename ptr::reference reference; -}; // end iterator_traits - -} // end std - -/*! \endcond - */ - - -namespace thrust -{ -namespace system -{ - -/*! \addtogroup system_backends Systems - * \ingroup system - * \{ - */ - -/*! \namespace thrust::system::cuda - * \brief \p thrust::system::cuda is the namespace containing functionality for allocating, manipulating, - * and deallocating memory available to Thrust's CUDA backend system. - * The identifiers are provided in a separate namespace underneath thrust::system - * for import convenience but are also aliased in the top-level thrust::tbb - * namespace for easy access. - * - */ -namespace cuda -{ - -// forward declaration of reference for pointer -template class reference; - -/*! \cond - */ - -// XXX nvcc + msvc have trouble instantiating reference below -// this is a workaround -namespace detail -{ - -template - struct reference_msvc_workaround -{ - typedef thrust::system::cuda::reference type; -}; // end reference_msvc_workaround - -} // end detail - -/*! \endcond - */ - -#if 0 -/*! \p cuda::tag is type representing Thrust's CUDA backend system in C++'s type system. - * Iterators "tagged" with a type which is convertible to \p cuda::tag assert that they may be - * "dispatched" to algorithm implementations in the \p cuda system. - */ -struct tag { unspecified }; -#endif - -/*! \p pointer stores a pointer to an object allocated in memory available to the cuda system. - * This type provides type safety when dispatching standard algorithms on ranges resident - * in cuda memory. - * - * \p pointer has pointer semantics: it may be dereferenced and manipulated with pointer arithmetic. - * - * \p pointer can be created with the function \p cuda::malloc, or by explicitly calling its constructor - * with a raw pointer. - * - * The raw pointer encapsulated by a \p pointer may be obtained by eiter its get member function - * or the \p raw_pointer_cast function. - * - * \note \p pointer is not a "smart" pointer; it is the programmer's responsibility to deallocate memory - * pointed to by \p pointer. - * - * \tparam T specifies the type of the pointee. - * - * \see cuda::malloc - * \see cuda::free - * \see raw_pointer_cast - */ -template - class pointer - : public thrust::pointer< - T, - thrust::system::cuda::tag, - thrust::system::cuda::reference, - thrust::system::cuda::pointer - > -{ - /*! \cond - */ - - private: - typedef thrust::pointer< - T, - thrust::system::cuda::tag, - //thrust::system::cuda::reference, - typename detail::reference_msvc_workaround::type, - thrust::system::cuda::pointer - > super_t; - - /*! \endcond - */ - - public: - - /*! \p pointer's no-argument constructor initializes its encapsulated pointer to \c 0. - */ - __host__ __device__ - pointer() : super_t() {} - - /*! This constructor allows construction of a pointer from a T*. - * - * \param ptr A raw pointer to copy from, presumed to point to a location in memory - * accessible by the \p tbb system. - * \tparam OtherT \p OtherT shall be convertible to \p T. - */ - template - __host__ __device__ - explicit pointer(OtherT *ptr) : super_t(ptr) {} - - /*! This constructor allows construction from another pointer-like object with related type. - * - * \param other The \p OtherPointer to copy. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::cuda::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type * = 0) : super_t(other) {} - - /*! Assignment operator allows assigning from another pointer-like object with related type. - * - * \param other The other pointer-like object to assign from. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::cuda::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - pointer & - >::type - operator=(const OtherPointer &other) - { - return super_t::operator=(other); - } -}; // end pointer - - -/*! \p reference is a wrapped reference to an object stored in memory available to the \p cuda system. - * \p reference is the type of the result of dereferencing a \p cuda::pointer. - * - * \tparam T Specifies the type of the referenced object. - */ -template - class reference - : public thrust::reference< - T, - thrust::system::cuda::pointer, - thrust::system::cuda::reference - > -{ - /*! \cond - */ - - private: - typedef thrust::reference< - T, - thrust::system::cuda::pointer, - thrust::system::cuda::reference - > super_t; - - /*! \endcond - */ - - public: - /*! \cond - */ - - typedef typename super_t::value_type value_type; - typedef typename super_t::pointer pointer; - - /*! \endcond - */ - - /*! This constructor initializes this \p reference to refer to an object - * pointed to by the given \p pointer. After this \p reference is constructed, - * it shall refer to the object pointed to by \p ptr. - * - * \param ptr A \p pointer to copy from. - */ - __host__ __device__ - explicit reference(const pointer &ptr) - : super_t(ptr) - {} - - /*! This constructor accepts a const reference to another \p reference of related type. - * After this \p reference is constructed, it shall refer to the same object as \p other. - * - * \param other A \p reference to copy from. - * \tparam OtherT The element type of the other \p reference. - * - * \note This constructor is templated primarily to allow initialization of reference - * from reference. - */ - template - __host__ __device__ - reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type * = 0) - : super_t(other) - {} - - /*! Copy assignment operator copy assigns from another \p reference of related type. - * - * \param other The other \p reference to assign from. - * \return *this - * \tparam OtherT The element type of the other \p reference. - */ - template - __host__ __device__ - reference &operator=(const reference &other); - - /*! Assignment operator assigns from a \p value_type. - * - * \param x The \p value_type to assign from. - * \return *this - */ - __host__ __device__ - reference &operator=(const value_type &x); -}; // end reference - -/*! Exchanges the values of two objects referred to by \p reference. - * \p x The first \p reference of interest. - * \p y The second \p reference ot interest. - */ -template -__host__ __device__ -void swap(reference x, reference y); - -/*! Allocates an area of memory available to Thrust's cuda system. - * \param n Number of bytes to allocate. - * \return A cuda::pointer pointing to the beginning of the newly - * allocated memory. A null cuda::pointer is returned if - * an error occurs. - * \note The cuda::pointer returned by this function must be - * deallocated with \p cuda::free. - * \see cuda::free - * \see std::malloc - */ -inline pointer malloc(std::size_t n); - -/*! Allocates a typed area of memory available to Thrust's cuda system. - * \param n Number of elements to allocate. - * \return A cuda::pointer pointing to the beginning of the newly - * allocated memory. A null cuda::pointer is returned if - * an error occurs. - * \note The cuda::pointer returned by this function must be - * deallocated with \p cuda::free. - * \see cuda::free - * \see std::malloc - */ -template -inline pointer malloc(std::size_t n); - -/*! Deallocates an area of memory previously allocated by cuda::malloc. - * \param ptr A cuda::pointer pointing to the beginning of an area - * of memory previously allocated with cuda::malloc. - * \see cuda::malloc - * \see std::free - */ -inline void free(pointer ptr); - -// XXX upon c++11 -// template using allocator = thrust::detail::malloc_allocator >; - -/*! \p cuda::allocator is the default allocator used by the \p cuda system's containers such as - * cuda::vector if no user-specified allocator is provided. \p cuda::allocator allocates - * (deallocates) storage with \p cuda::malloc (\p cuda::free). - */ -template - struct allocator - : thrust::detail::malloc_allocator< - T, - tag, - pointer - > -{ - /*! The \p rebind metafunction provides the type of an \p allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p allocator. - */ - typedef allocator other; - }; - - /*! No-argument constructor has no effect. - */ - __host__ __device__ - inline allocator() {} - - /*! Copy constructor has no effect. - */ - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Constructor from other \p allocator has no effect. - */ - template - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Destructor has no effect. - */ - __host__ __device__ - inline ~allocator() {} -}; // end allocator - -} // end cuda - -/*! \} - */ - -} // end system - -/*! \namespace thrust::cuda - * \brief \p thrust::cuda is a top-level alias for thrust::system::cuda. - */ -namespace cuda -{ - -using thrust::system::cuda::pointer; -using thrust::system::cuda::reference; -using thrust::system::cuda::malloc; -using thrust::system::cuda::free; -using thrust::system::cuda::allocator; - -} // end cuda - -} // end thrust - -#include - diff --git a/compat/thrust/system/cuda/vector.h b/compat/thrust/system/cuda/vector.h deleted file mode 100644 index ac47a84..0000000 --- a/compat/thrust/system/cuda/vector.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ccudaliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/cuda/vector.h - * \brief A dynamically-sizable array of elements which reside in memory available to - * Thrust's CUDA system. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -// forward declaration of host_vector -template class host_vector; - -namespace system -{ -namespace cuda -{ - -// XXX upon c++11 -// template > using vector = thrust::detail::vector_base; - -/*! \p cuda::vector is a container that supports random access to elements, - * constant time removal of elements at the end, and linear time insertion - * and removal of elements at the beginning or in the middle. The number of - * elements in a \p cuda::vector may vary dynamically; memory management is - * automatic. The elements contained in a \p cuda::vector reside in memory - * available to the \p cuda system. - * - * \tparam T The element type of the \p cuda::vector. - * \tparam Allocator The allocator type of the \p cuda::vector. Defaults to \p cuda::allocator. - * - * \see http://www.sgi.com/tech/stl/Vector.html - * \see host_vector For the documentation of the complete interface which is - * shared by \p cuda::vector - * \see device_vector - */ -template > - class vector - : public thrust::detail::vector_base -{ - /*! \cond - */ - private: - typedef thrust::detail::vector_base super_t; - /*! \endcond - */ - - public: - - /*! \cond - */ - typedef typename super_t::size_type size_type; - typedef typename super_t::value_type value_type; - /*! \endcond - */ - - /*! This constructor creates an empty \p cuda::vector. - */ - vector(); - - /*! This constructor creates a \p cuda::vector with \p n default-constructed elements. - * \param n The size of the \p cuda::vector to create. - */ - explicit vector(size_type n); - - /*! This constructor creates a \p cuda::vector with \p n copies of \p value. - * \param n The size of the \p cuda::vector to create. - * \param value An element to copy. - */ - explicit vector(size_type n, const value_type &value); - - /*! Copy constructor copies from another \p cuda::vector. - * \param x The other \p cuda::vector to copy. - */ - vector(const vector &x); - - /*! This constructor copies from another Thrust vector-like object. - * \param x The other object to copy from. - */ - template - vector(const thrust::detail::vector_base &x); - - /*! This constructor copies from a \c std::vector. - * \param x The \c std::vector to copy from. - */ - template - vector(const std::vector &x); - - /*! This constructor creates a \p cuda::vector by copying from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - vector(InputIterator first, InputIterator last); - - // XXX vector_base should take a Derived type so we don't have to define these superfluous assigns - // - /*! Assignment operator assigns from a \c std::vector. - * \param x The \c std::vector to assign from. - * \return *this - */ - template - vector &operator=(const std::vector &x); - - /*! Assignment operator assigns from another Thrust vector-like object. - * \param x The other object to assign from. - * \return *this - */ - template - vector &operator=(const thrust::detail::vector_base &x); -}; // end vector - -} // end cuda -} // end system - -// alias system::cuda names at top-level -namespace cuda -{ - -using thrust::system::cuda::vector; - -} // end cuda - -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/adl/adjacent_difference.h b/compat/thrust/system/detail/adl/adjacent_difference.h deleted file mode 100644 index 246c116..0000000 --- a/compat/thrust/system/detail/adl/adjacent_difference.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the adjacent_difference.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch adjacent_difference - -#define __THRUST_HOST_SYSTEM_ADJACENT_DIFFERENCE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/adjacent_difference.h> -#include __THRUST_HOST_SYSTEM_ADJACENT_DIFFERENCE_HEADER -#undef __THRUST_HOST_SYSTEM_ADJACENT_DIFFERENCE_HEADER - -#define __THRUST_DEVICE_SYSTEM_ADJACENT_DIFFERENCE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/adjacent_difference.h> -#include __THRUST_DEVICE_SYSTEM_ADJACENT_DIFFERENCE_HEADER -#undef __THRUST_DEVICE_SYSTEM_ADJACENT_DIFFERENCE_HEADER - diff --git a/compat/thrust/system/detail/adl/assign_value.h b/compat/thrust/system/detail/adl/assign_value.h deleted file mode 100644 index b5c588a..0000000 --- a/compat/thrust/system/detail/adl/assign_value.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the assign_value.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch assign_value - -#define __THRUST_HOST_SYSTEM_ASSIGN_VALUE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/assign_value.h> -#include __THRUST_HOST_SYSTEM_ASSIGN_VALUE_HEADER -#undef __THRUST_HOST_SYSTEM_ASSIGN_VALUE_HEADER - -#define __THRUST_DEVICE_SYSTEM_ASSIGN_VALUE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/assign_value.h> -#include __THRUST_DEVICE_SYSTEM_ASSIGN_VALUE_HEADER -#undef __THRUST_DEVICE_SYSTEM_ASSIGN_VALUE_HEADER - diff --git a/compat/thrust/system/detail/adl/binary_search.h b/compat/thrust/system/detail/adl/binary_search.h deleted file mode 100644 index 7accfbc..0000000 --- a/compat/thrust/system/detail/adl/binary_search.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the binary_search.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch binary_search - -#define __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/binary_search.h> -#include __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER -#undef __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER - -#define __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/binary_search.h> -#include __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER -#undef __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER - diff --git a/compat/thrust/system/detail/adl/copy.h b/compat/thrust/system/detail/adl/copy.h deleted file mode 100644 index 91a32cd..0000000 --- a/compat/thrust/system/detail/adl/copy.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the copy.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch copy - -#define __THRUST_HOST_SYSTEM_COPY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/copy.h> -#include __THRUST_HOST_SYSTEM_COPY_HEADER -#undef __THRUST_HOST_SYSTEM_COPY_HEADER - -#define __THRUST_DEVICE_SYSTEM_COPY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/copy.h> -#include __THRUST_DEVICE_SYSTEM_COPY_HEADER -#undef __THRUST_DEVICE_SYSTEM_COPY_HEADER - diff --git a/compat/thrust/system/detail/adl/copy_if.h b/compat/thrust/system/detail/adl/copy_if.h deleted file mode 100644 index fd1df97..0000000 --- a/compat/thrust/system/detail/adl/copy_if.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy_if.h of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the copy_if.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch copy_if - -#define __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/copy_if.h> -#include __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER -#undef __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER - -#define __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/copy_if.h> -#include __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER -#undef __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER - diff --git a/compat/thrust/system/detail/adl/count.h b/compat/thrust/system/detail/adl/count.h deleted file mode 100644 index 0dd9591..0000000 --- a/compat/thrust/system/detail/adl/count.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a count of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the count.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch count - -#define __THRUST_HOST_SYSTEM_COUNT_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/count.h> -#include __THRUST_HOST_SYSTEM_COUNT_HEADER -#undef __THRUST_HOST_SYSTEM_COUNT_HEADER - -#define __THRUST_DEVICE_SYSTEM_COUNT_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/count.h> -#include __THRUST_DEVICE_SYSTEM_COUNT_HEADER -#undef __THRUST_DEVICE_SYSTEM_COUNT_HEADER - diff --git a/compat/thrust/system/detail/adl/equal.h b/compat/thrust/system/detail/adl/equal.h deleted file mode 100644 index f933d4f..0000000 --- a/compat/thrust/system/detail/adl/equal.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a equal of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the equal.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch equal - -#define __THRUST_HOST_SYSTEM_EQUAL_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/equal.h> -#include __THRUST_HOST_SYSTEM_EQUAL_HEADER -#undef __THRUST_HOST_SYSTEM_EQUAL_HEADER - -#define __THRUST_DEVICE_SYSTEM_EQUAL_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/equal.h> -#include __THRUST_DEVICE_SYSTEM_EQUAL_HEADER -#undef __THRUST_DEVICE_SYSTEM_EQUAL_HEADER - diff --git a/compat/thrust/system/detail/adl/extrema.h b/compat/thrust/system/detail/adl/extrema.h deleted file mode 100644 index c766570..0000000 --- a/compat/thrust/system/detail/adl/extrema.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a extrema of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the extrema.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch extrema - -#define __THRUST_HOST_SYSTEM_EXTREMA_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/extrema.h> -#include __THRUST_HOST_SYSTEM_EXTREMA_HEADER -#undef __THRUST_HOST_SYSTEM_EXTREMA_HEADER - -#define __THRUST_DEVICE_SYSTEM_EXTREMA_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/extrema.h> -#include __THRUST_DEVICE_SYSTEM_EXTREMA_HEADER -#undef __THRUST_DEVICE_SYSTEM_EXTREMA_HEADER - diff --git a/compat/thrust/system/detail/adl/fill.h b/compat/thrust/system/detail/adl/fill.h deleted file mode 100644 index b241b8a..0000000 --- a/compat/thrust/system/detail/adl/fill.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the fill.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch fill - -#define __THRUST_HOST_SYSTEM_FILL_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/fill.h> -#include __THRUST_HOST_SYSTEM_FILL_HEADER -#undef __THRUST_HOST_SYSTEM_FILL_HEADER - -#define __THRUST_DEVICE_SYSTEM_FILL_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/fill.h> -#include __THRUST_DEVICE_SYSTEM_FILL_HEADER -#undef __THRUST_DEVICE_SYSTEM_FILL_HEADER - diff --git a/compat/thrust/system/detail/adl/find.h b/compat/thrust/system/detail/adl/find.h deleted file mode 100644 index 7c99f3e..0000000 --- a/compat/thrust/system/detail/adl/find.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the find.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch find - -#define __THRUST_HOST_SYSTEM_FIND_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/find.h> -#include __THRUST_HOST_SYSTEM_FIND_HEADER -#undef __THRUST_HOST_SYSTEM_FIND_HEADER - -#define __THRUST_DEVICE_SYSTEM_FIND_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/find.h> -#include __THRUST_DEVICE_SYSTEM_FIND_HEADER -#undef __THRUST_DEVICE_SYSTEM_FIND_HEADER - diff --git a/compat/thrust/system/detail/adl/for_each.h b/compat/thrust/system/detail/adl/for_each.h deleted file mode 100644 index 0b2717f..0000000 --- a/compat/thrust/system/detail/adl/for_each.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the for_each.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch for_each - -#define __THRUST_HOST_SYSTEM_FOR_EACH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/for_each.h> -#include __THRUST_HOST_SYSTEM_FOR_EACH_HEADER -#undef __THRUST_HOST_SYSTEM_FOR_EACH_HEADER - -#define __THRUST_DEVICE_SYSTEM_FOR_EACH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/for_each.h> -#include __THRUST_DEVICE_SYSTEM_FOR_EACH_HEADER -#undef __THRUST_DEVICE_SYSTEM_FOR_EACH_HEADER - diff --git a/compat/thrust/system/detail/adl/gather.h b/compat/thrust/system/detail/adl/gather.h deleted file mode 100644 index da4c1d1..0000000 --- a/compat/thrust/system/detail/adl/gather.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the gather.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch gather - -#define __THRUST_HOST_SYSTEM_FOR_EACH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/gather.h> -#include __THRUST_HOST_SYSTEM_FOR_EACH_HEADER -#undef __THRUST_HOST_SYSTEM_FOR_EACH_HEADER - -#define __THRUST_DEVICE_SYSTEM_FOR_EACH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/gather.h> -#include __THRUST_DEVICE_SYSTEM_FOR_EACH_HEADER -#undef __THRUST_DEVICE_SYSTEM_FOR_EACH_HEADER - diff --git a/compat/thrust/system/detail/adl/generate.h b/compat/thrust/system/detail/adl/generate.h deleted file mode 100644 index 3a98847..0000000 --- a/compat/thrust/system/detail/adl/generate.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the generate.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch generate - -#define __THRUST_HOST_SYSTEM_GENERATE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/generate.h> -#include __THRUST_HOST_SYSTEM_GENERATE_HEADER -#undef __THRUST_HOST_SYSTEM_GENERATE_HEADER - -#define __THRUST_DEVICE_SYSTEM_GENERATE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/generate.h> -#include __THRUST_DEVICE_SYSTEM_GENERATE_HEADER -#undef __THRUST_DEVICE_SYSTEM_GENERATE_HEADER - diff --git a/compat/thrust/system/detail/adl/get_value.h b/compat/thrust/system/detail/adl/get_value.h deleted file mode 100644 index ed4ef2c..0000000 --- a/compat/thrust/system/detail/adl/get_value.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the get_value.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch get_value - -#define __THRUST_HOST_SYSTEM_GET_VALUE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/get_value.h> -#include __THRUST_HOST_SYSTEM_GET_VALUE_HEADER -#undef __THRUST_HOST_SYSTEM_GET_VALUE_HEADER - -#define __THRUST_DEVICE_SYSTEM_GET_VALUE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/get_value.h> -#include __THRUST_DEVICE_SYSTEM_GET_VALUE_HEADER -#undef __THRUST_DEVICE_SYSTEM_GET_VALUE_HEADER - diff --git a/compat/thrust/system/detail/adl/inner_product.h b/compat/thrust/system/detail/adl/inner_product.h deleted file mode 100644 index 18cc65b..0000000 --- a/compat/thrust/system/detail/adl/inner_product.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the inner_product.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch inner_product - -#define __THRUST_HOST_SYSTEM_INNER_PRODUCT_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/inner_product.h> -#include __THRUST_HOST_SYSTEM_INNER_PRODUCT_HEADER -#undef __THRUST_HOST_SYSTEM_INNER_PRODUCT_HEADER - -#define __THRUST_DEVICE_SYSTEM_INNER_PRODUCT_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/inner_product.h> -#include __THRUST_DEVICE_SYSTEM_INNER_PRODUCT_HEADER -#undef __THRUST_DEVICE_SYSTEM_INNER_PRODUCT_HEADER - diff --git a/compat/thrust/system/detail/adl/iter_swap.h b/compat/thrust/system/detail/adl/iter_swap.h deleted file mode 100644 index b302c25..0000000 --- a/compat/thrust/system/detail/adl/iter_swap.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the iter_swap.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch iter_swap - -#define __THRUST_HOST_SYSTEM_ITER_SWAP_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/iter_swap.h> -#include __THRUST_HOST_SYSTEM_ITER_SWAP_HEADER -#undef __THRUST_HOST_SYSTEM_ITER_SWAP_HEADER - -#define __THRUST_DEVICE_SYSTEM_ITER_SWAP_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/iter_swap.h> -#include __THRUST_DEVICE_SYSTEM_ITER_SWAP_HEADER -#undef __THRUST_DEVICE_SYSTEM_ITER_SWAP_HEADER - diff --git a/compat/thrust/system/detail/adl/logical.h b/compat/thrust/system/detail/adl/logical.h deleted file mode 100644 index 585f71a..0000000 --- a/compat/thrust/system/detail/adl/logical.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the logical.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch logical - -#define __THRUST_HOST_SYSTEM_LOGICAL_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/logical.h> -#include __THRUST_HOST_SYSTEM_LOGICAL_HEADER -#undef __THRUST_HOST_SYSTEM_LOGICAL_HEADER - -#define __THRUST_DEVICE_SYSTEM_LOGICAL_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/logical.h> -#include __THRUST_DEVICE_SYSTEM_LOGICAL_HEADER -#undef __THRUST_DEVICE_SYSTEM_LOGICAL_HEADER - diff --git a/compat/thrust/system/detail/adl/malloc_and_free.h b/compat/thrust/system/detail/adl/malloc_and_free.h deleted file mode 100644 index 7d99a26..0000000 --- a/compat/thrust/system/detail/adl/malloc_and_free.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the malloc_and_free.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch malloc_and_free - -#define __THRUST_HOST_SYSTEM_MALLOC_AND_FREE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/malloc_and_free.h> -#include __THRUST_HOST_SYSTEM_MALLOC_AND_FREE_HEADER -#undef __THRUST_HOST_SYSTEM_MALLOC_AND_FREE_HEADER - -#define __THRUST_DEVICE_SYSTEM_MALLOC_AND_FREE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/malloc_and_free.h> -#include __THRUST_DEVICE_SYSTEM_MALLOC_AND_FREE_HEADER -#undef __THRUST_DEVICE_SYSTEM_MALLOC_AND_FREE_HEADER - diff --git a/compat/thrust/system/detail/adl/merge.h b/compat/thrust/system/detail/adl/merge.h deleted file mode 100644 index 59d8ace..0000000 --- a/compat/thrust/system/detail/adl/merge.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the merge.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch merge - -#define __THRUST_HOST_SYSTEM_MERGE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/merge.h> -#include __THRUST_HOST_SYSTEM_MERGE_HEADER -#undef __THRUST_HOST_SYSTEM_MERGE_HEADER - -#define __THRUST_DEVICE_SYSTEM_MERGE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/merge.h> -#include __THRUST_DEVICE_SYSTEM_MERGE_HEADER -#undef __THRUST_DEVICE_SYSTEM_MERGE_HEADER - diff --git a/compat/thrust/system/detail/adl/mismatch.h b/compat/thrust/system/detail/adl/mismatch.h deleted file mode 100644 index d2d1831..0000000 --- a/compat/thrust/system/detail/adl/mismatch.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the mismatch.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch mismatch - -#define __THRUST_HOST_SYSTEM_MISMATCH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/mismatch.h> -#include __THRUST_HOST_SYSTEM_MISMATCH_HEADER -#undef __THRUST_HOST_SYSTEM_MISMATCH_HEADER - -#define __THRUST_DEVICE_SYSTEM_MISMATCH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/mismatch.h> -#include __THRUST_DEVICE_SYSTEM_MISMATCH_HEADER -#undef __THRUST_DEVICE_SYSTEM_MISMATCH_HEADER - diff --git a/compat/thrust/system/detail/adl/partition.h b/compat/thrust/system/detail/adl/partition.h deleted file mode 100644 index efdc605..0000000 --- a/compat/thrust/system/detail/adl/partition.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the partition.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch partition - -#define __THRUST_HOST_SYSTEM_PARTITION_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/partition.h> -#include __THRUST_HOST_SYSTEM_PARTITION_HEADER -#undef __THRUST_HOST_SYSTEM_PARTITION_HEADER - -#define __THRUST_DEVICE_SYSTEM_PARTITION_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/partition.h> -#include __THRUST_DEVICE_SYSTEM_PARTITION_HEADER -#undef __THRUST_DEVICE_SYSTEM_PARTITION_HEADER - diff --git a/compat/thrust/system/detail/adl/reduce.h b/compat/thrust/system/detail/adl/reduce.h deleted file mode 100644 index afa00f9..0000000 --- a/compat/thrust/system/detail/adl/reduce.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the reduce.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch reduce - -#define __THRUST_HOST_SYSTEM_REDUCE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/reduce.h> -#include __THRUST_HOST_SYSTEM_REDUCE_HEADER -#undef __THRUST_HOST_SYSTEM_REDUCE_HEADER - -#define __THRUST_DEVICE_SYSTEM_REDUCE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/reduce.h> -#include __THRUST_DEVICE_SYSTEM_REDUCE_HEADER -#undef __THRUST_DEVICE_SYSTEM_REDUCE_HEADER - diff --git a/compat/thrust/system/detail/adl/reduce_by_key.h b/compat/thrust/system/detail/adl/reduce_by_key.h deleted file mode 100644 index eac65b7..0000000 --- a/compat/thrust/system/detail/adl/reduce_by_key.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the reduce_by_key.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch reduce_by_key - -#define __THRUST_HOST_SYSTEM_REDUCE_BY_KEY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/reduce_by_key.h> -#include __THRUST_HOST_SYSTEM_REDUCE_BY_KEY_HEADER -#undef __THRUST_HOST_SYSTEM_REDUCE_BY_KEY_HEADER - -#define __THRUST_DEVICE_SYSTEM_REDUCE_BY_KEY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/reduce_by_key.h> -#include __THRUST_DEVICE_SYSTEM_REDUCE_BY_KEY_HEADER -#undef __THRUST_DEVICE_SYSTEM_REDUCE_BY_KEY_HEADER - diff --git a/compat/thrust/system/detail/adl/remove.h b/compat/thrust/system/detail/adl/remove.h deleted file mode 100644 index 9d64be8..0000000 --- a/compat/thrust/system/detail/adl/remove.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the remove.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch remove - -#define __THRUST_HOST_SYSTEM_REMOVE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/remove.h> -#include __THRUST_HOST_SYSTEM_REMOVE_HEADER -#undef __THRUST_HOST_SYSTEM_REMOVE_HEADER - -#define __THRUST_DEVICE_SYSTEM_REMOVE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/remove.h> -#include __THRUST_DEVICE_SYSTEM_REMOVE_HEADER -#undef __THRUST_DEVICE_SYSTEM_REMOVE_HEADER - diff --git a/compat/thrust/system/detail/adl/replace.h b/compat/thrust/system/detail/adl/replace.h deleted file mode 100644 index e4d8bd2..0000000 --- a/compat/thrust/system/detail/adl/replace.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the replace.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch replace - -#define __THRUST_HOST_SYSTEM_REPLACE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/replace.h> -#include __THRUST_HOST_SYSTEM_REPLACE_HEADER -#undef __THRUST_HOST_SYSTEM_REPLACE_HEADER - -#define __THRUST_DEVICE_SYSTEM_REPLACE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/replace.h> -#include __THRUST_DEVICE_SYSTEM_REPLACE_HEADER -#undef __THRUST_DEVICE_SYSTEM_REPLACE_HEADER - diff --git a/compat/thrust/system/detail/adl/reverse.h b/compat/thrust/system/detail/adl/reverse.h deleted file mode 100644 index 8cbcfd8..0000000 --- a/compat/thrust/system/detail/adl/reverse.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the reverse.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch reverse - -#define __THRUST_HOST_SYSTEM_REVERSE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/reverse.h> -#include __THRUST_HOST_SYSTEM_REVERSE_HEADER -#undef __THRUST_HOST_SYSTEM_REVERSE_HEADER - -#define __THRUST_DEVICE_SYSTEM_REVERSE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/reverse.h> -#include __THRUST_DEVICE_SYSTEM_REVERSE_HEADER -#undef __THRUST_DEVICE_SYSTEM_REVERSE_HEADER - diff --git a/compat/thrust/system/detail/adl/scan.h b/compat/thrust/system/detail/adl/scan.h deleted file mode 100644 index e70cd9f..0000000 --- a/compat/thrust/system/detail/adl/scan.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the scan.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch scan - -#define __THRUST_HOST_SYSTEM_SCAN_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/scan.h> -#include __THRUST_HOST_SYSTEM_SCAN_HEADER -#undef __THRUST_HOST_SYSTEM_SCAN_HEADER - -#define __THRUST_DEVICE_SYSTEM_SCAN_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/scan.h> -#include __THRUST_DEVICE_SYSTEM_SCAN_HEADER -#undef __THRUST_DEVICE_SYSTEM_SCAN_HEADER - diff --git a/compat/thrust/system/detail/adl/scan_by_key.h b/compat/thrust/system/detail/adl/scan_by_key.h deleted file mode 100644 index 02c4b84..0000000 --- a/compat/thrust/system/detail/adl/scan_by_key.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the scan_by_key.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch scan_by_key - -#define __THRUST_HOST_SYSTEM_SCAN_BY_KEY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/scan_by_key.h> -#include __THRUST_HOST_SYSTEM_SCAN_BY_KEY_HEADER -#undef __THRUST_HOST_SYSTEM_SCAN_BY_KEY_HEADER - -#define __THRUST_DEVICE_SYSTEM_SCAN_BY_KEY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/scan_by_key.h> -#include __THRUST_DEVICE_SYSTEM_SCAN_BY_KEY_HEADER -#undef __THRUST_DEVICE_SYSTEM_SCAN_BY_KEY_HEADER - diff --git a/compat/thrust/system/detail/adl/scatter.h b/compat/thrust/system/detail/adl/scatter.h deleted file mode 100644 index b94b0d9..0000000 --- a/compat/thrust/system/detail/adl/scatter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the scatter.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch scatter - -#define __THRUST_HOST_SYSTEM_SCATTER_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/scatter.h> -#include __THRUST_HOST_SYSTEM_SCATTER_HEADER -#undef __THRUST_HOST_SYSTEM_SCATTER_HEADER - -#define __THRUST_DEVICE_SYSTEM_SCATTER_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/scatter.h> -#include __THRUST_DEVICE_SYSTEM_SCATTER_HEADER -#undef __THRUST_DEVICE_SYSTEM_SCATTER_HEADER - diff --git a/compat/thrust/system/detail/adl/sequence.h b/compat/thrust/system/detail/adl/sequence.h deleted file mode 100644 index 07dcc7b..0000000 --- a/compat/thrust/system/detail/adl/sequence.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the sequence.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch sequence - -#define __THRUST_HOST_SYSTEM_SEQUENCE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/sequence.h> -#include __THRUST_HOST_SYSTEM_SEQUENCE_HEADER -#undef __THRUST_HOST_SYSTEM_SEQUENCE_HEADER - -#define __THRUST_DEVICE_SYSTEM_SEQUENCE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/sequence.h> -#include __THRUST_DEVICE_SYSTEM_SEQUENCE_HEADER -#undef __THRUST_DEVICE_SYSTEM_SEQUENCE_HEADER - diff --git a/compat/thrust/system/detail/adl/set_operations.h b/compat/thrust/system/detail/adl/set_operations.h deleted file mode 100644 index 9901b46..0000000 --- a/compat/thrust/system/detail/adl/set_operations.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the set_operations.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch set_operations - -#define __THRUST_HOST_SYSTEM_SET_OPERATIONS_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/set_operations.h> -#include __THRUST_HOST_SYSTEM_SET_OPERATIONS_HEADER -#undef __THRUST_HOST_SYSTEM_SET_OPERATIONS_HEADER - -#define __THRUST_DEVICE_SYSTEM_SET_OPERATIONS_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/set_operations.h> -#include __THRUST_DEVICE_SYSTEM_SET_OPERATIONS_HEADER -#undef __THRUST_DEVICE_SYSTEM_SET_OPERATIONS_HEADER - diff --git a/compat/thrust/system/detail/adl/sort.h b/compat/thrust/system/detail/adl/sort.h deleted file mode 100644 index afcb903..0000000 --- a/compat/thrust/system/detail/adl/sort.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the sort.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch sort - -#define __THRUST_HOST_SYSTEM_SORT_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/sort.h> -#include __THRUST_HOST_SYSTEM_SORT_HEADER -#undef __THRUST_HOST_SYSTEM_SORT_HEADER - -#define __THRUST_DEVICE_SYSTEM_SORT_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/sort.h> -#include __THRUST_DEVICE_SYSTEM_SORT_HEADER -#undef __THRUST_DEVICE_SYSTEM_SORT_HEADER - diff --git a/compat/thrust/system/detail/adl/swap_ranges.h b/compat/thrust/system/detail/adl/swap_ranges.h deleted file mode 100644 index c006936..0000000 --- a/compat/thrust/system/detail/adl/swap_ranges.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the swap_ranges.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch swap_ranges - -#define __THRUST_HOST_SYSTEM_SWAP_RANGES_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/swap_ranges.h> -#include __THRUST_HOST_SYSTEM_SWAP_RANGES_HEADER -#undef __THRUST_HOST_SYSTEM_SWAP_RANGES_HEADER - -#define __THRUST_DEVICE_SYSTEM_SWAP_RANGES_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/swap_ranges.h> -#include __THRUST_DEVICE_SYSTEM_SWAP_RANGES_HEADER -#undef __THRUST_DEVICE_SYSTEM_SWAP_RANGES_HEADER - diff --git a/compat/thrust/system/detail/adl/tabulate.h b/compat/thrust/system/detail/adl/tabulate.h deleted file mode 100644 index cb1fdeb..0000000 --- a/compat/thrust/system/detail/adl/tabulate.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the tabulate.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch tabulate - -#define __THRUST_HOST_SYSTEM_TABULATE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/tabulate.h> -#include __THRUST_HOST_SYSTEM_TABULATE_HEADER -#undef __THRUST_HOST_SYSTEM_TABULATE_HEADER - -#define __THRUST_DEVICE_SYSTEM_TABULATE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/tabulate.h> -#include __THRUST_DEVICE_SYSTEM_TABULATE_HEADER -#undef __THRUST_DEVICE_SYSTEM_TABULATE_HEADER - diff --git a/compat/thrust/system/detail/adl/temporary_buffer.h b/compat/thrust/system/detail/adl/temporary_buffer.h deleted file mode 100644 index 66df0ea..0000000 --- a/compat/thrust/system/detail/adl/temporary_buffer.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the temporary_buffer.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch get_temporary_buffer or return_temporary_buffer - -#define __THRUST_HOST_SYSTEM_TEMPORARY_BUFFER_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/temporary_buffer.h> -#include __THRUST_HOST_SYSTEM_TEMPORARY_BUFFER_HEADER -#undef __THRUST_HOST_SYSTEM_TEMPORARY_BUFFER_HEADER - -#define __THRUST_DEVICE_SYSTEM_TEMPORARY_BUFFER_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/temporary_buffer.h> -#include __THRUST_DEVICE_SYSTEM_TEMPORARY_BUFFER_HEADER -#undef __THRUST_DEVICE_SYSTEM_TEMPORARY_BUFFER_HEADER - diff --git a/compat/thrust/system/detail/adl/transform.h b/compat/thrust/system/detail/adl/transform.h deleted file mode 100644 index c9e6a01..0000000 --- a/compat/thrust/system/detail/adl/transform.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the transform.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch transform - -#define __THRUST_HOST_SYSTEM_TRANSFORM_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/transform.h> -#include __THRUST_HOST_SYSTEM_TRANSFORM_HEADER -#undef __THRUST_HOST_SYSTEM_TRANSFORM_HEADER - -#define __THRUST_DEVICE_SYSTEM_TRANSFORM_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/transform.h> -#include __THRUST_DEVICE_SYSTEM_TRANSFORM_HEADER -#undef __THRUST_DEVICE_SYSTEM_TRANSFORM_HEADER - diff --git a/compat/thrust/system/detail/adl/transform_reduce.h b/compat/thrust/system/detail/adl/transform_reduce.h deleted file mode 100644 index 0a5d977..0000000 --- a/compat/thrust/system/detail/adl/transform_reduce.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the transform_reduce.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch transform_reduce - -#define __THRUST_HOST_SYSTEM_TRANSFORM_REDUCE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/transform_reduce.h> -#include __THRUST_HOST_SYSTEM_TRANSFORM_REDUCE_HEADER -#undef __THRUST_HOST_SYSTEM_TRANSFORM_REDUCE_HEADER - -#define __THRUST_DEVICE_SYSTEM_TRANSFORM_REDUCE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/transform_reduce.h> -#include __THRUST_DEVICE_SYSTEM_TRANSFORM_REDUCE_HEADER -#undef __THRUST_DEVICE_SYSTEM_TRANSFORM_REDUCE_HEADER - diff --git a/compat/thrust/system/detail/adl/transform_scan.h b/compat/thrust/system/detail/adl/transform_scan.h deleted file mode 100644 index 47c1dc3..0000000 --- a/compat/thrust/system/detail/adl/transform_scan.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the transform_scan.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch transform_scan - -#define __THRUST_HOST_SYSTEM_TRANSFORM_SCAN_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/transform_scan.h> -#include __THRUST_HOST_SYSTEM_TRANSFORM_SCAN_HEADER -#undef __THRUST_HOST_SYSTEM_TRANSFORM_SCAN_HEADER - -#define __THRUST_DEVICE_SYSTEM_TRANSFORM_SCAN_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/transform_scan.h> -#include __THRUST_DEVICE_SYSTEM_TRANSFORM_SCAN_HEADER -#undef __THRUST_DEVICE_SYSTEM_TRANSFORM_SCAN_HEADER - diff --git a/compat/thrust/system/detail/adl/uninitialized_copy.h b/compat/thrust/system/detail/adl/uninitialized_copy.h deleted file mode 100644 index 7cb0b8e..0000000 --- a/compat/thrust/system/detail/adl/uninitialized_copy.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the uninitialized_copy.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch uninitialized_copy - -#define __THRUST_HOST_SYSTEM_UNINITIALIZED_COPY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/uninitialized_copy.h> -#include __THRUST_HOST_SYSTEM_UNINITIALIZED_COPY_HEADER -#undef __THRUST_HOST_SYSTEM_UNINITIALIZED_COPY_HEADER - -#define __THRUST_DEVICE_SYSTEM_UNINITIALIZED_COPY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/uninitialized_copy.h> -#include __THRUST_DEVICE_SYSTEM_UNINITIALIZED_COPY_HEADER -#undef __THRUST_DEVICE_SYSTEM_UNINITIALIZED_COPY_HEADER - diff --git a/compat/thrust/system/detail/adl/uninitialized_fill.h b/compat/thrust/system/detail/adl/uninitialized_fill.h deleted file mode 100644 index 9f00b51..0000000 --- a/compat/thrust/system/detail/adl/uninitialized_fill.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the uninitialized_fill.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch uninitialized_fill - -#define __THRUST_HOST_SYSTEM_UNINITIALIZED_FILL_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/uninitialized_fill.h> -#include __THRUST_HOST_SYSTEM_UNINITIALIZED_FILL_HEADER -#undef __THRUST_HOST_SYSTEM_UNINITIALIZED_FILL_HEADER - -#define __THRUST_DEVICE_SYSTEM_UNINITIALIZED_FILL_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/uninitialized_fill.h> -#include __THRUST_DEVICE_SYSTEM_UNINITIALIZED_FILL_HEADER -#undef __THRUST_DEVICE_SYSTEM_UNINITIALIZED_FILL_HEADER - diff --git a/compat/thrust/system/detail/adl/unique.h b/compat/thrust/system/detail/adl/unique.h deleted file mode 100644 index 932ff58..0000000 --- a/compat/thrust/system/detail/adl/unique.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the unique.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch unique - -#define __THRUST_HOST_SYSTEM_UNIQUE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/unique.h> -#include __THRUST_HOST_SYSTEM_UNIQUE_HEADER -#undef __THRUST_HOST_SYSTEM_UNIQUE_HEADER - -#define __THRUST_DEVICE_SYSTEM_UNIQUE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/unique.h> -#include __THRUST_DEVICE_SYSTEM_UNIQUE_HEADER -#undef __THRUST_DEVICE_SYSTEM_UNIQUE_HEADER - diff --git a/compat/thrust/system/detail/adl/unique_by_key.h b/compat/thrust/system/detail/adl/unique_by_key.h deleted file mode 100644 index 30e6f2f..0000000 --- a/compat/thrust/system/detail/adl/unique_by_key.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a fill of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// the purpose of this header is to #include the unique_by_key.h header -// of the host and device systems. It should be #included in any -// code which uses adl to dispatch unique_by_key - -#define __THRUST_HOST_SYSTEM_UNIQUE_BY_KEY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/unique_by_key.h> -#include __THRUST_HOST_SYSTEM_UNIQUE_BY_KEY_HEADER -#undef __THRUST_HOST_SYSTEM_UNIQUE_BY_KEY_HEADER - -#define __THRUST_DEVICE_SYSTEM_UNIQUE_BY_KEY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/unique_by_key.h> -#include __THRUST_DEVICE_SYSTEM_UNIQUE_BY_KEY_HEADER -#undef __THRUST_DEVICE_SYSTEM_UNIQUE_BY_KEY_HEADER - diff --git a/compat/thrust/system/detail/bad_alloc.h b/compat/thrust/system/detail/bad_alloc.h deleted file mode 100644 index bb73d1f..0000000 --- a/compat/thrust/system/detail/bad_alloc.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ - -// define our own bad_alloc so we can set its .what() -class bad_alloc - : public std::bad_alloc -{ - public: - inline bad_alloc(const std::string &w) - : std::bad_alloc(), m_what() - { - m_what = std::bad_alloc::what(); - m_what += ": "; - m_what += w; - } // end bad_alloc() - - inline virtual ~bad_alloc(void) throw () {}; - - inline virtual const char *what(void) const throw() - { - return m_what.c_str(); - } // end what() - - private: - std::string m_what; -}; // end bad_alloc - -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/errno.h b/compat/thrust/system/detail/errno.h deleted file mode 100644 index 34bc8cc..0000000 --- a/compat/thrust/system/detail/errno.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -// The rationale for the existence of these apparently redundant definitions is -// to provide them portably and to avoid bringing in system headers which might -// pollute the global namespace. These identifiers are in lowercase to avoid -// colliding with the real macros in errno.h. - -namespace thrust -{ - -namespace system -{ - -namespace detail -{ - -static const int eafnosupport = 9901; -static const int eaddrinuse = 9902; -static const int eaddrnotavail = 9903; -static const int eisconn = 9904; -static const int ebadmsg = 9905; -static const int econnaborted = 9906; -static const int ealready = 9907; -static const int econnrefused = 9908; -static const int econnreset = 9909; -static const int edestaddrreq = 9910; -static const int ehostunreach = 9911; -static const int eidrm = 9912; -static const int emsgsize = 9913; -static const int enetdown = 9914; -static const int enetreset = 9915; -static const int enetunreach = 9916; -static const int enobufs = 9917; -static const int enolink = 9918; -static const int enodata = 9919; -static const int enomsg = 9920; -static const int enoprotoopt = 9921; -static const int enosr = 9922; -static const int enotsock = 9923; -static const int enostr = 9924; -static const int enotconn = 9925; -static const int enotsup = 9926; -static const int ecanceled = 9927; -static const int einprogress = 9928; -static const int eopnotsupp = 9929; -static const int ewouldblock = 9930; -static const int eownerdead = 9931; -static const int eproto = 9932; -static const int eprotonosupport = 9933; -static const int enotrecoverable = 9934; -static const int etime = 9935; -static const int etxtbsy = 9936; -static const int etimedout = 9938; -static const int eloop = 9939; -static const int eoverflow = 9940; -static const int eprototype = 9941; -static const int enosys = 9942; -static const int einval = 9943; -static const int erange = 9944; -static const int eilseq = 9945; -static const int e2big = 9946; -static const int edom = 9947; -static const int efault = 9948; -static const int ebadf = 9949; -static const int epipe = 9950; -static const int exdev = 9951; -static const int ebusy = 9952; -static const int enotempty = 9953; -static const int enoexec = 9954; -static const int eexist = 9955; -static const int efbig = 9956; -static const int enametoolong = 9957; -static const int enotty = 9958; -static const int eintr = 9959; -static const int espipe = 9960; -static const int eio = 9961; -static const int eisdir = 9962; -static const int echild = 9963; -static const int enolck = 9964; -static const int enospc = 9965; -static const int enxio = 9966; -static const int enodev = 9967; -static const int enoent = 9968; -static const int esrch = 9969; -static const int enotdir = 9970; -static const int enomem = 9971; -static const int eperm = 9972; -static const int eacces = 9973; -static const int erofs = 9974; -static const int edeadlk = 9975; -static const int eagain = 9976; -static const int enfile = 9977; -static const int emfile = 9978; -static const int emlink = 9979; - -} // end detail - -} // end system - -} // end thrust - diff --git a/compat/thrust/system/detail/error_category.inl b/compat/thrust/system/detail/error_category.inl deleted file mode 100644 index 8e19c89..0000000 --- a/compat/thrust/system/detail/error_category.inl +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace system -{ - -error_category - ::~error_category(void) -{ - ; -} // end error_category::~error_category() - - -error_condition error_category - ::default_error_condition(int ev) const -{ - return error_condition(ev, *this); -} // end error_category::default_error_condition() - - -bool error_category - ::equivalent(int code, const error_condition &condition) const -{ - return default_error_condition(code) == condition; -} // end error_condition::equivalent() - - -bool error_category - ::equivalent(const error_code &code, int condition) const -{ - bool result = (this->operator==(code.category())) && (code.value() == condition); - return result; -} // end error_code::equivalent() - - -bool error_category - ::operator==(const error_category &rhs) const -{ - return this == &rhs; -} // end error_category::operator==() - - -bool error_category - ::operator!=(const error_category &rhs) const -{ - return !this->operator==(rhs); -} // end error_category::operator!=() - - -bool error_category - ::operator<(const error_category &rhs) const -{ - return thrust::less()(this,&rhs); -} // end error_category::operator<() - - -namespace detail -{ - - -class generic_error_category - : public error_category -{ - public: - inline generic_error_category(void) {} - - inline virtual const char *name(void) const - { - return "generic"; - } - - inline virtual std::string message(int ev) const - { - static const std::string unknown_err("Unknown error"); - - // XXX strerror is not thread-safe: - // prefer strerror_r (which is not provided on windows) - const char *c_str = std::strerror(ev); - return c_str ? std::string(c_str) : unknown_err; - } -}; // end generic_category_result - - -class system_error_category - : public error_category -{ - public: - inline system_error_category(void) {} - - inline virtual const char *name(void) const - { - return "system"; - } - - inline virtual std::string message(int ev) const - { - return generic_category().message(ev); - } - - inline virtual error_condition default_error_condition(int ev) const - { - using namespace errc; - - switch(ev) - { - case eafnosupport: return make_error_condition(address_family_not_supported); - case eaddrinuse: return make_error_condition(address_in_use); - case eaddrnotavail: return make_error_condition(address_not_available); - case eisconn: return make_error_condition(already_connected); - case e2big: return make_error_condition(argument_list_too_long); - case edom: return make_error_condition(argument_out_of_domain); - case efault: return make_error_condition(bad_address); - case ebadf: return make_error_condition(bad_file_descriptor); - case ebadmsg: return make_error_condition(bad_message); - case epipe: return make_error_condition(broken_pipe); - case econnaborted: return make_error_condition(connection_aborted); - case ealready: return make_error_condition(connection_already_in_progress); - case econnrefused: return make_error_condition(connection_refused); - case econnreset: return make_error_condition(connection_reset); - case exdev: return make_error_condition(cross_device_link); - case edestaddrreq: return make_error_condition(destination_address_required); - case ebusy: return make_error_condition(device_or_resource_busy); - case enotempty: return make_error_condition(directory_not_empty); - case enoexec: return make_error_condition(executable_format_error); - case eexist: return make_error_condition(file_exists); - case efbig: return make_error_condition(file_too_large); - case enametoolong: return make_error_condition(filename_too_long); - case enosys: return make_error_condition(function_not_supported); - case ehostunreach: return make_error_condition(host_unreachable); - case eidrm: return make_error_condition(identifier_removed); - case eilseq: return make_error_condition(illegal_byte_sequence); - case enotty: return make_error_condition(inappropriate_io_control_operation); - case eintr: return make_error_condition(interrupted); - case einval: return make_error_condition(invalid_argument); - case espipe: return make_error_condition(invalid_seek); - case eio: return make_error_condition(io_error); - case eisdir: return make_error_condition(is_a_directory); - case emsgsize: return make_error_condition(message_size); - case enetdown: return make_error_condition(network_down); - case enetreset: return make_error_condition(network_reset); - case enetunreach: return make_error_condition(network_unreachable); - case enobufs: return make_error_condition(no_buffer_space); - case echild: return make_error_condition(no_child_process); - case enolink: return make_error_condition(no_link); - case enolck: return make_error_condition(no_lock_available); - case enodata: return make_error_condition(no_message_available); - case enomsg: return make_error_condition(no_message); - case enoprotoopt: return make_error_condition(no_protocol_option); - case enospc: return make_error_condition(no_space_on_device); - case enosr: return make_error_condition(no_stream_resources); - case enxio: return make_error_condition(no_such_device_or_address); - case enodev: return make_error_condition(no_such_device); - case enoent: return make_error_condition(no_such_file_or_directory); - case esrch: return make_error_condition(no_such_process); - case enotdir: return make_error_condition(not_a_directory); - case enotsock: return make_error_condition(not_a_socket); - case enostr: return make_error_condition(not_a_stream); - case enotconn: return make_error_condition(not_connected); - case enomem: return make_error_condition(not_enough_memory); - case enotsup: return make_error_condition(not_supported); - case ecanceled: return make_error_condition(operation_canceled); - case einprogress: return make_error_condition(operation_in_progress); - case eperm: return make_error_condition(operation_not_permitted); - case eopnotsupp: return make_error_condition(operation_not_supported); - case ewouldblock: return make_error_condition(operation_would_block); - case eownerdead: return make_error_condition(owner_dead); - case eacces: return make_error_condition(permission_denied); - case eproto: return make_error_condition(protocol_error); - case eprotonosupport: return make_error_condition(protocol_not_supported); - case erofs: return make_error_condition(read_only_file_system); - case edeadlk: return make_error_condition(resource_deadlock_would_occur); - case eagain: return make_error_condition(resource_unavailable_try_again); - case erange: return make_error_condition(result_out_of_range); - case enotrecoverable: return make_error_condition(state_not_recoverable); - case etime: return make_error_condition(stream_timeout); - case etxtbsy: return make_error_condition(text_file_busy); - case etimedout: return make_error_condition(timed_out); - case enfile: return make_error_condition(too_many_files_open_in_system); - case emfile: return make_error_condition(too_many_files_open); - case emlink: return make_error_condition(too_many_links); - case eloop: return make_error_condition(too_many_symbolic_link_levels); - case eoverflow: return make_error_condition(value_too_large); - case eprototype: return make_error_condition(wrong_protocol_type); - default: return error_condition(ev,system_category()); - } - } -}; // end system_category_result - - -} // end detail - - -const error_category &generic_category(void) -{ - static const detail::generic_error_category result; - return result; -} - - -const error_category &system_category(void) -{ - static const detail::system_error_category result; - return result; -} - - -} // end system - -} // end thrust - diff --git a/compat/thrust/system/detail/error_code.inl b/compat/thrust/system/detail/error_code.inl deleted file mode 100644 index 0cf86b4..0000000 --- a/compat/thrust/system/detail/error_code.inl +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -namespace thrust -{ - -namespace system -{ - -error_code - ::error_code(void) - :m_val(0),m_cat(&system_category()) -{ - ; -} // end error_code::error_code() - - -error_code - ::error_code(int val, const error_category &cat) - :m_val(val),m_cat(&cat) -{ - ; -} // end error_code::error_code() - - -template - error_code - ::error_code(ErrorCodeEnum e -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - , typename thrust::detail::enable_if::value>::type * -#endif // THRUST_HOST_COMPILER_MSVC - ) -{ - *this = make_error_code(e); -} // end error_code::error_code() - - -void error_code - ::assign(int val, const error_category &cat) -{ - m_val = val; - m_cat = &cat; -} // end error_code::assign() - - -template -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - typename thrust::detail::enable_if::value, error_code>::type & -#else - error_code & -#endif // THRUST_HOST_COMPILER_MSVC - error_code - ::operator=(ErrorCodeEnum e) -{ - *this = make_error_code(e); - return *this; -} // end error_code::operator=() - - -void error_code - ::clear(void) -{ - m_val = 0; - m_cat = &system_category(); -} // end error_code::clear() - - -int error_code - ::value(void) const -{ - return m_val; -} // end error_code::value() - - -const error_category &error_code - ::category(void) const -{ - return *m_cat; -} // end error_code::category() - - -error_condition error_code - ::default_error_condition(void) const -{ - return category().default_error_condition(value()); -} // end error_code::default_error_condition() - - -std::string error_code - ::message(void) const -{ - return category().message(value()); -} // end error_code::message() - - -error_code - ::operator bool (void) const -{ - return value() != 0; -} // end error_code::operator bool () - - -error_code make_error_code(errc::errc_t e) -{ - return error_code(static_cast(e), generic_category()); -} // end make_error_code() - - -bool operator<(const error_code &lhs, const error_code &rhs) -{ - bool result = lhs.category().operator<(rhs.category()); - result = result || lhs.category().operator==(rhs.category()); - result = result || lhs.value() < rhs.value(); - return result; -} // end operator==() - - -template - std::basic_ostream& - operator<<(std::basic_ostream &os, const error_code &ec) -{ - return os << ec.category().name() << ':' << ec.value(); -} // end operator<<() - - -bool operator==(const error_code &lhs, const error_code &rhs) -{ - return lhs.category().operator==(rhs.category()) && lhs.value() == rhs.value(); -} // end operator==() - - -bool operator==(const error_code &lhs, const error_condition &rhs) -{ - return lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs,rhs.value()); -} // end operator==() - - -bool operator==(const error_condition &lhs, const error_code &rhs) -{ - return rhs.category().equivalent(lhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value()); -} // end operator==() - - -bool operator==(const error_condition &lhs, const error_condition &rhs) -{ - return lhs.category().operator==(rhs.category()) && lhs.value() == rhs.value(); -} // end operator==() - - -bool operator!=(const error_code &lhs, const error_code &rhs) -{ - return !(lhs == rhs); -} // end operator!=() - - -bool operator!=(const error_code &lhs, const error_condition &rhs) -{ - return !(lhs == rhs); -} // end operator!=() - - -bool operator!=(const error_condition &lhs, const error_code &rhs) -{ - return !(lhs == rhs); -} // end operator!=() - - -bool operator!=(const error_condition &lhs, const error_condition &rhs) -{ - return !(lhs == rhs); -} // end operator!=() - - -} // end system - -} // end thrust - diff --git a/compat/thrust/system/detail/error_condition.inl b/compat/thrust/system/detail/error_condition.inl deleted file mode 100644 index 00fbaf0..0000000 --- a/compat/thrust/system/detail/error_condition.inl +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace system -{ - -error_condition - ::error_condition(void) - :m_val(0),m_cat(&generic_category()) -{ - ; -} // end error_condition::error_condition() - - -error_condition - ::error_condition(int val, const error_category &cat) - :m_val(val),m_cat(&cat) -{ - ; -} // end error_condition::error_condition() - - -template - error_condition - ::error_condition(ErrorConditionEnum e -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - , typename thrust::detail::enable_if::value>::type * -#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - ) -{ - *this = make_error_condition(e); -} // end error_condition::error_condition() - - -void error_condition - ::assign(int val, const error_category &cat) -{ - m_val = val; - m_cat = &cat; -} // end error_category::assign() - - -template -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - typename thrust::detail::enable_if::value, error_condition>::type & -#else - error_condition & -#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - error_condition - ::operator=(ErrorConditionEnum e) -{ - *this = make_error_condition(e); - return *this; -} // end error_condition::operator=() - - -void error_condition - ::clear(void) -{ - m_val = 0; - m_cat = &generic_category(); -} // end error_condition::clear() - - -int error_condition - ::value(void) const -{ - return m_val; -} // end error_condition::value() - - -const error_category &error_condition - ::category(void) const -{ - return *m_cat; -} // end error_condition::category() - - -std::string error_condition - ::message(void) const -{ - return category().message(value()); -} // end error_condition::message() - - -error_condition - ::operator bool (void) const -{ - return value() != 0; -} // end error_condition::operator bool () - - -error_condition make_error_condition(errc::errc_t e) -{ - return error_condition(static_cast(e), generic_category()); -} // end make_error_condition() - - -bool operator<(const error_condition &lhs, - const error_condition &rhs) -{ - return lhs.category().operator<(rhs.category()) || (lhs.category().operator==(rhs.category()) && (lhs.value() < rhs.value())); -} // end operator<() - - -} // end system - -} // end thrust - diff --git a/compat/thrust/system/detail/generic/adjacent_difference.h b/compat/thrust/system/detail/generic/adjacent_difference.h deleted file mode 100644 index bb340df..0000000 --- a/compat/thrust/system/detail/generic/adjacent_difference.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file adjacent_difference.h - * \brief Generic implementation of adjacent_difference. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -OutputIterator adjacent_difference(thrust::execution_policy &exec, - InputIterator first, InputIterator last, - OutputIterator result); - -template -OutputIterator adjacent_difference(thrust::execution_policy &exec, - InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/adjacent_difference.inl b/compat/thrust/system/detail/generic/adjacent_difference.inl deleted file mode 100644 index 619b29f..0000000 --- a/compat/thrust/system/detail/generic/adjacent_difference.inl +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -OutputIterator adjacent_difference(thrust::execution_policy &exec, - InputIterator first, InputIterator last, - OutputIterator result) -{ - typedef typename thrust::iterator_traits::value_type InputType; - thrust::minus binary_op; - - return thrust::adjacent_difference(exec, first, last, result, binary_op); -} // end adjacent_difference() - -template -OutputIterator adjacent_difference(thrust::execution_policy &exec, - InputIterator first, InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - if(first == last) - { - // empty range, nothing to do - return result; - } - else - { - // an in-place operation is requested, copy the input and call the entry point - // XXX a special-purpose kernel would be faster here since - // only block boundaries need to be copied - thrust::detail::temporary_array input_copy(exec, first, last); - - *result = *first; - thrust::transform(exec, input_copy.begin() + 1, input_copy.end(), input_copy.begin(), result + 1, binary_op); - } - - return result + (last - first); -} - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/advance.h b/compat/thrust/system/detail/generic/advance.h deleted file mode 100644 index 249aac7..0000000 --- a/compat/thrust/system/detail/generic/advance.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -void advance(InputIterator& i, Distance n); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/advance.inl b/compat/thrust/system/detail/generic/advance.inl deleted file mode 100644 index b95737a..0000000 --- a/compat/thrust/system/detail/generic/advance.inl +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template -void advance(InputIterator& i, Distance n, thrust::incrementable_traversal_tag) -{ - while(n) - { - ++i; - --n; - } // end while -} // end advance() - -template -void advance(InputIterator& i, Distance n, thrust::random_access_traversal_tag) -{ - i += n; -} // end advance() - -} // end detail - -template -void advance(InputIterator& i, Distance n) -{ - // dispatch on iterator traversal - thrust::system::detail::generic::detail::advance(i, n, - typename thrust::iterator_traversal::type()); -} // end advance() - -} // end namespace detail -} // end namespace generic -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/binary_search.h b/compat/thrust/system/detail/generic/binary_search.h deleted file mode 100644 index 7fd6c50..0000000 --- a/compat/thrust/system/detail/generic/binary_search.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file binary_search.h - * \brief Generic implementations of binary search functions. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template -ForwardIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value); - -template -ForwardIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp); - - -template -ForwardIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value); - -template -ForwardIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp); - - -template -bool binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value); - -template -bool binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp); - - -template -OutputIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output); - -template -OutputIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp); - - -template -OutputIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output); - -template -OutputIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp); - - -template -OutputIterator binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output); - -template -OutputIterator binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp); - - -template -thrust::pair -equal_range(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value); - -template -thrust::pair -equal_range(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value, - StrictWeakOrdering comp); - - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/binary_search.inl b/compat/thrust/system/detail/generic/binary_search.inl deleted file mode 100644 index 151ac0e..0000000 --- a/compat/thrust/system/detail/generic/binary_search.inl +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file binary_search.inl - * \brief Inline file for binary_search.h - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -namespace thrust -{ -namespace detail -{ - -// XXX WAR circular #inclusion with this forward declaration -template class temporary_array; - -} // end detail -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - - -// short names to avoid nvcc bug -struct lbf -{ - template - __host__ __device__ - typename thrust::iterator_traits::difference_type - operator()(RandomAccessIterator begin, RandomAccessIterator end, const T& value, StrictWeakOrdering comp) - { - return thrust::system::detail::generic::scalar::lower_bound(begin, end, value, comp) - begin; - } -}; - -struct ubf -{ - template - __host__ __device__ - typename thrust::iterator_traits::difference_type - operator()(RandomAccessIterator begin, RandomAccessIterator end, const T& value, StrictWeakOrdering comp){ - return thrust::system::detail::generic::scalar::upper_bound(begin, end, value, comp) - begin; - } -}; - -struct bsf -{ - template - __host__ __device__ - bool operator()(RandomAccessIterator begin, RandomAccessIterator end, const T& value, StrictWeakOrdering comp){ - RandomAccessIterator iter = thrust::system::detail::generic::scalar::lower_bound(begin, end, value, comp); - - thrust::detail::host_device_function wrapped_comp(comp); - - return iter != end && !wrapped_comp(value, *iter); - } -}; - - -template -struct binary_search_functor -{ - ForwardIterator begin; - ForwardIterator end; - StrictWeakOrdering comp; - BinarySearchFunction func; - - binary_search_functor(ForwardIterator begin, ForwardIterator end, StrictWeakOrdering comp, BinarySearchFunction func) - : begin(begin), end(end), comp(comp), func(func) {} - - template - __host__ __device__ - void operator()(Tuple t) - { - thrust::get<1>(t) = func(begin, end, thrust::get<0>(t), comp); - } -}; // binary_search_functor - - -// Vector Implementation -template -OutputIterator binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp, - BinarySearchFunction func) -{ - thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(values_begin, output)), - thrust::make_zip_iterator(thrust::make_tuple(values_end, output + thrust::distance(values_begin, values_end))), - detail::binary_search_functor(begin, end, comp, func)); - - return output + thrust::distance(values_begin, values_end); -} - - - -// Scalar Implementation -template -OutputType binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp, - BinarySearchFunction func) -{ - // use the vectorized path to implement the scalar version - - // allocate device buffers for value and output - thrust::detail::temporary_array d_value(exec,1); - thrust::detail::temporary_array d_output(exec,1); - - // copy value to device - d_value[0] = value; - - // perform the query - thrust::system::detail::generic::detail::binary_search(exec, begin, end, d_value.begin(), d_value.end(), d_output.begin(), comp, func); - - // copy result to host and return - return d_output[0]; -} - -} // end namespace detail - - -////////////////////// -// Scalar Functions // -////////////////////// - -template -ForwardIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value) -{ - return thrust::lower_bound(exec, begin, end, value, thrust::less()); -} - -template -ForwardIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_traits::difference_type difference_type; - - return begin + detail::binary_search(exec, begin, end, value, comp, detail::lbf()); -} - - -template -ForwardIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value) -{ - return thrust::upper_bound(exec, begin, end, value, thrust::less()); -} - -template -ForwardIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_traits::difference_type difference_type; - - return begin + detail::binary_search(exec, begin, end, value, comp, detail::ubf()); -} - - -template -bool binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value) -{ - return thrust::binary_search(exec, begin, end, value, thrust::less()); -} - -template -bool binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp) -{ - return detail::binary_search(exec, begin, end, value, comp, detail::bsf()); -} - - -////////////////////// -// Vector Functions // -////////////////////// - -template -OutputIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output) -{ - typedef typename thrust::iterator_value::type ValueType; - - return thrust::lower_bound(exec, begin, end, values_begin, values_end, output, thrust::less()); -} - -template -OutputIterator lower_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp) -{ - return detail::binary_search(exec, begin, end, values_begin, values_end, output, comp, detail::lbf()); -} - - -template -OutputIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output) -{ - typedef typename thrust::iterator_value::type ValueType; - - return thrust::upper_bound(exec, begin, end, values_begin, values_end, output, thrust::less()); -} - -template -OutputIterator upper_bound(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp) -{ - return detail::binary_search(exec, begin, end, values_begin, values_end, output, comp, detail::ubf()); -} - - -template -OutputIterator binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output) -{ - typedef typename thrust::iterator_value::type ValueType; - - return thrust::binary_search(exec, begin, end, values_begin, values_end, output, thrust::less()); -} - -template -OutputIterator binary_search(thrust::execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - InputIterator values_begin, - InputIterator values_end, - OutputIterator output, - StrictWeakOrdering comp) -{ - return detail::binary_search(exec, begin, end, values_begin, values_end, output, comp, detail::bsf()); -} - - -template -thrust::pair -equal_range(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const LessThanComparable &value) -{ - return thrust::equal_range(exec, first, last, value, thrust::less()); -} - - -template -thrust::pair -equal_range(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &value, - StrictWeakOrdering comp) -{ - ForwardIterator lb = thrust::lower_bound(exec, first, last, value, comp); - ForwardIterator ub = thrust::upper_bound(exec, first, last, value, comp); - return thrust::make_pair(lb, ub); -} - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/copy.h b/compat/thrust/system/detail/generic/copy.h deleted file mode 100644 index 8df98fe..0000000 --- a/compat/thrust/system/detail/generic/copy.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template - OutputIterator copy_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result); - - -} // end generic -} // end detail -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/generic/copy.inl b/compat/thrust/system/detail/generic/copy.inl deleted file mode 100644 index e081015..0000000 --- a/compat/thrust/system/detail/generic/copy.inl +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type T; - return thrust::transform(exec, first, last, result, thrust::identity()); -} // end copy() - - -template - OutputIterator copy_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type value_type; - typedef thrust::identity xfrm_type; - - // XXX why do we need to do this? figure out why, and then see if we can do without - typedef typename thrust::detail::unary_transform_functor::type functor_type; - - typedef thrust::tuple iterator_tuple; - typedef thrust::zip_iterator zip_iter; - - zip_iter zipped = thrust::make_zip_iterator(thrust::make_tuple(first,result)); - - return thrust::get<1>(thrust::for_each_n(exec, zipped, n, functor_type(xfrm_type())).get_iterator_tuple()); -} // end copy_n() - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/copy_if.h b/compat/thrust/system/detail/generic/copy_if.h deleted file mode 100644 index 183f012..0000000 --- a/compat/thrust/system/detail/generic/copy_if.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator copy_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - -template - OutputIterator copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/copy_if.inl b/compat/thrust/system/detail/generic/copy_if.inl deleted file mode 100644 index 145561c..0000000 --- a/compat/thrust/system/detail/generic/copy_if.inl +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template -OutputIterator copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - __THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING(IndexType n = thrust::distance(first, last)); - - // compute {0,1} predicates - thrust::detail::temporary_array predicates(exec, n); - thrust::transform(exec, - stencil, - stencil + n, - predicates.begin(), - thrust::detail::predicate_to_integral(pred)); - - // scan {0,1} predicates - thrust::detail::temporary_array scatter_indices(exec, n); - thrust::exclusive_scan(exec, - predicates.begin(), - predicates.end(), - scatter_indices.begin(), - static_cast(0), - thrust::plus()); - - // scatter the true elements - thrust::scatter_if(exec, - first, - last, - scatter_indices.begin(), - predicates.begin(), - result, - thrust::identity()); - - // find the end of the new sequence - IndexType output_size = scatter_indices[n - 1] + predicates[n - 1]; - - return result + output_size; -} - -} // end namespace detail - - -template - OutputIterator copy_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - // XXX it's potentially expensive to send [first,last) twice - // we should probably specialize this case for POD - // since we can safely keep the input in a temporary instead - // of doing two loads - return thrust::copy_if(exec, first, last, first, result, pred); -} // end copy_if() - - -template - OutputIterator copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - typedef typename thrust::iterator_traits::difference_type difference_type; - - // empty sequence - if(first == last) - return result; - - difference_type n = thrust::distance(first, last); - - // create an unsigned version of n (we know n is positive from the comparison above) - // to avoid a warning in the compare below - typename thrust::detail::make_unsigned::type unsigned_n(n); - - // use 32-bit indices when possible (almost always) - if(sizeof(difference_type) > sizeof(unsigned int) && unsigned_n > (std::numeric_limits::max)()) - { - result = detail::copy_if(exec, first, last, stencil, result, pred); - } // end if - else - { - result = detail::copy_if(exec, first, last, stencil, result, pred); - } // end else - - return result; -} // end copy_if() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/count.h b/compat/thrust/system/detail/generic/count.h deleted file mode 100644 index bc4899e..0000000 --- a/compat/thrust/system/detail/generic/count.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -typename thrust::iterator_traits::difference_type -count(thrust::execution_policy &exec, InputIterator first, InputIterator last, const EqualityComparable& value); - -template -typename thrust::iterator_traits::difference_type -count_if(thrust::execution_policy &exec, InputIterator first, InputIterator last, Predicate pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/count.inl b/compat/thrust/system/detail/generic/count.inl deleted file mode 100644 index e3ab871..0000000 --- a/compat/thrust/system/detail/generic/count.inl +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -struct count_if_transform -{ - __host__ __device__ - count_if_transform(Predicate _pred) : pred(_pred){} - - __host__ __device__ - CountType operator()(const InputType& val) - { - if(pred(val)) - return 1; - else - return 0; - } // end operator() - - Predicate pred; -}; // end count_if_transform - -template -typename thrust::iterator_traits::difference_type -count(thrust::execution_policy &exec, InputIterator first, InputIterator last, const EqualityComparable& value) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - // XXX use placeholder expression here - return thrust::count_if(exec, first, last, thrust::detail::equal_to_value(value)); -} // end count() - -template -typename thrust::iterator_traits::difference_type -count_if(thrust::execution_policy &exec, InputIterator first, InputIterator last, Predicate pred) -{ - typedef typename thrust::iterator_traits::value_type InputType; - typedef typename thrust::iterator_traits::difference_type CountType; - - thrust::system::detail::generic::count_if_transform unary_op(pred); - thrust::plus binary_op; - return thrust::transform_reduce(exec, first, last, unary_op, CountType(0), binary_op); -} // end count_if() - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/distance.h b/compat/thrust/system/detail/generic/distance.h deleted file mode 100644 index 80f051c..0000000 --- a/compat/thrust/system/detail/generic/distance.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - inline typename thrust::iterator_traits::difference_type - distance(InputIterator first, InputIterator last); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/distance.inl b/compat/thrust/system/detail/generic/distance.inl deleted file mode 100644 index a1fdf14..0000000 --- a/compat/thrust/system/detail/generic/distance.inl +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template - inline typename thrust::iterator_traits::difference_type - distance(InputIterator first, InputIterator last, thrust::incrementable_traversal_tag) -{ - typename thrust::iterator_traits::difference_type result(0); - - while(first != last) - { - ++first; - ++result; - } // end while - - return result; -} // end advance() - -template - inline typename thrust::iterator_traits::difference_type - distance(InputIterator first, InputIterator last, thrust::random_access_traversal_tag) -{ - return last - first; -} // end distance() - -} // end detail - -template - inline typename thrust::iterator_traits::difference_type - distance(InputIterator first, InputIterator last) -{ - // dispatch on iterator traversal - return thrust::system::detail::generic::detail::distance(first, last, - typename thrust::iterator_traversal::type()); -} // end advance() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/equal.h b/compat/thrust/system/detail/generic/equal.h deleted file mode 100644 index da7d105..0000000 --- a/compat/thrust/system/detail/generic/equal.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -bool equal(thrust::execution_policy &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); - -template -bool equal(thrust::execution_policy &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/equal.inl b/compat/thrust/system/detail/generic/equal.inl deleted file mode 100644 index 12b8005..0000000 --- a/compat/thrust/system/detail/generic/equal.inl +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -bool equal(thrust::execution_policy &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) -{ - typedef typename thrust::iterator_traits::value_type InputType1; - - return thrust::equal(exec, first1, last1, first2, thrust::detail::equal_to()); -} - -template -bool equal(thrust::execution_policy &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred) -{ - return thrust::mismatch(exec, first1, last1, first2, binary_pred).first == last1; -} - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/extrema.h b/compat/thrust/system/detail/generic/extrema.h deleted file mode 100644 index abb4ddc..0000000 --- a/compat/thrust/system/detail/generic/extrema.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file extrema.h - * \brief Generic device implementations of extrema functions. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -ForwardIterator max_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - -template -ForwardIterator max_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp); - -template -ForwardIterator min_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - -template -ForwardIterator min_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp); - -template -thrust::pair minmax_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - -template -thrust::pair minmax_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/extrema.inl b/compat/thrust/system/detail/generic/extrema.inl deleted file mode 100644 index b5f92c3..0000000 --- a/compat/thrust/system/detail/generic/extrema.inl +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file distance.h - * \brief Device implementations for distance. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -////////////// -// Functors // -////////////// - -// return the smaller/larger element making sure to prefer the -// first occurance of the minimum/maximum element -template -struct min_element_reduction -{ - BinaryPredicate comp; - - __host__ __device__ - min_element_reduction(BinaryPredicate comp) : comp(comp){} - - __host__ __device__ - thrust::tuple - operator()(const thrust::tuple& lhs, - const thrust::tuple& rhs ) - { - if(comp(thrust::get<0>(lhs), thrust::get<0>(rhs))) - return lhs; - if(comp(thrust::get<0>(rhs), thrust::get<0>(lhs))) - return rhs; - - // values are equivalent, prefer value with smaller index - if(thrust::get<1>(lhs) < thrust::get<1>(rhs)) - return lhs; - else - return rhs; - } // end operator()() - -}; // end min_element_reduction - - -template -struct max_element_reduction -{ - BinaryPredicate comp; - - __host__ __device__ - max_element_reduction(BinaryPredicate comp) : comp(comp){} - - __host__ __device__ - thrust::tuple - operator()(const thrust::tuple& lhs, - const thrust::tuple& rhs ) - { - if(comp(thrust::get<0>(lhs), thrust::get<0>(rhs))) - return rhs; - if(comp(thrust::get<0>(rhs), thrust::get<0>(lhs))) - return lhs; - - // values are equivalent, prefer value with smaller index - if(thrust::get<1>(lhs) < thrust::get<1>(rhs)) - return lhs; - else - return rhs; - } // end operator()() - -}; // end max_element_reduction - -// return the smaller & larger element making sure to prefer the -// first occurance of the minimum/maximum element -template -struct minmax_element_reduction -{ - BinaryPredicate comp; - - minmax_element_reduction(BinaryPredicate comp) : comp(comp){} - - __host__ __device__ - thrust::tuple< thrust::tuple, thrust::tuple > - operator()(const thrust::tuple< thrust::tuple, thrust::tuple >& lhs, - const thrust::tuple< thrust::tuple, thrust::tuple >& rhs ) - { - - return thrust::make_tuple(min_element_reduction(comp)(thrust::get<0>(lhs), thrust::get<0>(rhs)), - max_element_reduction(comp)(thrust::get<1>(lhs), thrust::get<1>(rhs))); - } // end operator()() -}; // end minmax_element_reduction - -template -struct duplicate_tuple -{ - __host__ __device__ - thrust::tuple< thrust::tuple, thrust::tuple > - operator()(const thrust::tuple& t) - { - return thrust::make_tuple(t, t); - } -}; // end duplicate_tuple - -} // end namespace detail - -template -ForwardIterator min_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - typedef typename thrust::iterator_value::type value_type; - - return thrust::min_element(exec, first, last, thrust::less()); -} // end min_element() - -template -ForwardIterator min_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - if (first == last) - return last; - - typedef typename thrust::iterator_traits::value_type InputType; - typedef typename thrust::iterator_traits::difference_type IndexType; - - thrust::tuple result = - thrust::reduce - (exec, - thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))), - thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))) + (last - first), - thrust::tuple(*first, 0), - detail::min_element_reduction(comp)); - - return first + thrust::get<1>(result); -} // end min_element() - -template -ForwardIterator max_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - typedef typename thrust::iterator_value::type value_type; - - return thrust::max_element(exec, first, last, thrust::less()); -} // end max_element() - -template -ForwardIterator max_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - if (first == last) - return last; - - typedef typename thrust::iterator_traits::value_type InputType; - typedef typename thrust::iterator_traits::difference_type IndexType; - - thrust::tuple result = - thrust::reduce - (exec, - thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))), - thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))) + (last - first), - thrust::tuple(*first, 0), - detail::max_element_reduction(comp)); - - return first + thrust::get<1>(result); -} // end max_element() - -template -thrust::pair minmax_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - typedef typename thrust::iterator_value::type value_type; - - return thrust::minmax_element(exec, first, last, thrust::less()); -} // end minmax_element() - -template -thrust::pair minmax_element(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - if (first == last) - return thrust::make_pair(last, last); - - typedef typename thrust::iterator_traits::value_type InputType; - typedef typename thrust::iterator_traits::difference_type IndexType; - - thrust::tuple< thrust::tuple, thrust::tuple > result = - thrust::transform_reduce - (exec, - thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))), - thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))) + (last - first), - detail::duplicate_tuple(), - detail::duplicate_tuple()(thrust::tuple(*first, 0)), - detail::minmax_element_reduction(comp)); - - return thrust::make_pair(first + thrust::get<1>(thrust::get<0>(result)), first + thrust::get<1>(thrust::get<1>(result))); -} // end minmax_element() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/fill.h b/compat/thrust/system/detail/generic/fill.h deleted file mode 100644 index 9745b1c..0000000 --- a/compat/thrust/system/detail/generic/fill.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file fill.h - * \brief Device implementation of fill. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator fill_n(thrust::execution_policy &exec, - OutputIterator first, - Size n, - const T &value) -{ - // XXX consider using the placeholder expression _1 = value - return thrust::generate_n(exec, first, n, thrust::detail::fill_functor(value)); -} - -template - void fill(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &value) -{ - // XXX consider using the placeholder expression _1 = value - thrust::generate(exec, first, last, thrust::detail::fill_functor(value)); -} - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/find.h b/compat/thrust/system/detail/generic/find.h deleted file mode 100644 index 08888c5..0000000 --- a/compat/thrust/system/detail/generic/find.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -InputIterator find(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - const T& value); - -template -InputIterator find_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred); - -template -InputIterator find_if_not(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/find.inl b/compat/thrust/system/detail/generic/find.inl deleted file mode 100644 index a3414e1..0000000 --- a/compat/thrust/system/detail/generic/find.inl +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - - -// Contributed by Erich Elsen - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template -InputIterator find(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - const T& value) -{ - // XXX consider a placeholder expression here - return thrust::find_if(exec, first, last, thrust::detail::equal_to_value(value)); -} // end find() - - -template -struct find_if_functor -{ - __host__ __device__ - TupleType operator()(const TupleType& lhs, const TupleType& rhs) const - { - // select the smallest index among true results - if (thrust::get<0>(lhs) && thrust::get<0>(rhs)) - return TupleType(true, (thrust::min)(thrust::get<1>(lhs), thrust::get<1>(rhs))); - else if (thrust::get<0>(lhs)) - return lhs; - else - return rhs; - } -}; - - -template -InputIterator find_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - typedef typename thrust::iterator_traits::difference_type difference_type; - typedef typename thrust::tuple result_type; - - // empty sequence - if (first == last) - return last; - - const difference_type n = thrust::distance(first, last); - - // this implementation breaks up the sequence into separate intervals - // in an attempt to early-out as soon as a value is found - - // TODO incorporate sizeof(InputType) into interval_threshold and round to multiple of 32 - const difference_type interval_threshold = 1 << 20; - const difference_type interval_size = (std::min)(interval_threshold, n); - - // force transform_iterator output to bool - typedef thrust::transform_iterator XfrmIterator; - typedef thrust::tuple > IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - IteratorTuple iter_tuple = thrust::make_tuple(XfrmIterator(first, pred), - thrust::counting_iterator(0)); - - ZipIterator begin = thrust::make_zip_iterator(iter_tuple); - ZipIterator end = begin + n; - - for(ZipIterator interval_begin = begin; interval_begin < end; interval_begin += interval_size) - { - ZipIterator interval_end = interval_begin + interval_size; - if(end < interval_end) - { - interval_end = end; - } // end if - - result_type result = thrust::reduce(exec, - interval_begin, interval_end, - result_type(false,interval_end - begin), - find_if_functor()); - - // see if we found something - if (thrust::get<0>(result)) - { - return first + thrust::get<1>(result); - } - } - - //nothing was found if we reach here... - return first + n; -} - - -template -InputIterator find_if_not(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - return thrust::find_if(exec, first, last, thrust::detail::not1(pred)); -} // end find() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/for_each.h b/compat/thrust/system/detail/generic/for_each.h deleted file mode 100644 index 61abe20..0000000 --- a/compat/thrust/system/detail/generic/for_each.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file for_each.h - * \brief Generic implementation of for_each & for_each_n. - * It is an error to call these functions; they have no implementation. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template -InputIterator for_each(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - UnaryFunction f) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return first; -} // end for_each() - - -template -InputIterator for_each_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - UnaryFunction f) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return first; -} // end for_each_n() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/gather.h b/compat/thrust/system/detail/generic/gather.h deleted file mode 100644 index cfb6f85..0000000 --- a/compat/thrust/system/detail/generic/gather.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator gather(thrust::execution_policy &exec, - InputIterator map_first, - InputIterator map_last, - RandomAccessIterator input_first, - OutputIterator result); - - -template - OutputIterator gather_if(thrust::execution_policy &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result); - - -template - OutputIterator gather_if(thrust::execution_policy &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result, - Predicate pred); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/gather.inl b/compat/thrust/system/detail/generic/gather.inl deleted file mode 100644 index ab2cdd8..0000000 --- a/compat/thrust/system/detail/generic/gather.inl +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputIterator gather(thrust::execution_policy &exec, - InputIterator map_first, - InputIterator map_last, - RandomAccessIterator input_first, - OutputIterator result) -{ - return thrust::transform(exec, - thrust::make_permutation_iterator(input_first, map_first), - thrust::make_permutation_iterator(input_first, map_last), - result, - thrust::identity::type>()); -} // end gather() - - -template - OutputIterator gather_if(thrust::execution_policy &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type StencilType; - return thrust::gather_if(exec, - map_first, - map_last, - stencil, - input_first, - result, - thrust::identity()); -} // end gather_if() - - -template - OutputIterator gather_if(thrust::execution_policy &exec, - InputIterator1 map_first, - InputIterator1 map_last, - InputIterator2 stencil, - RandomAccessIterator input_first, - OutputIterator result, - Predicate pred) -{ - typedef typename thrust::iterator_value::type InputType; - return thrust::transform_if(exec, - thrust::make_permutation_iterator(input_first, map_first), - thrust::make_permutation_iterator(input_first, map_last), - stencil, - result, - thrust::identity(), - pred); -} // end gather_if() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/generate.h b/compat/thrust/system/detail/generic/generate.h deleted file mode 100644 index e7a8e00..0000000 --- a/compat/thrust/system/detail/generic/generate.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void generate(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Generator gen); - -template - OutputIterator generate_n(thrust::execution_policy &exec, - OutputIterator first, - Size n, - Generator gen); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/generate.inl b/compat/thrust/system/detail/generic/generate.inl deleted file mode 100644 index 4da5763..0000000 --- a/compat/thrust/system/detail/generic/generate.inl +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void generate(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Generator gen) -{ - thrust::for_each(exec, first, last, typename thrust::detail::generate_functor::type(gen)); -} // end generate() - -template - OutputIterator generate_n(thrust::execution_policy &exec, - OutputIterator first, - Size n, - Generator gen) -{ - return thrust::for_each_n(exec, first, n, typename thrust::detail::generate_functor::type(gen)); -} // end generate() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/inner_product.h b/compat/thrust/system/detail/generic/inner_product.h deleted file mode 100644 index 9ac5c69..0000000 --- a/compat/thrust/system/detail/generic/inner_product.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputType inner_product(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init); - -template -OutputType inner_product(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init, - BinaryFunction1 binary_op1, - BinaryFunction2 binary_op2); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/inner_product.inl b/compat/thrust/system/detail/generic/inner_product.inl deleted file mode 100644 index b6a339e..0000000 --- a/compat/thrust/system/detail/generic/inner_product.inl +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template -OutputType inner_product(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init) -{ - thrust::plus binary_op1; - thrust::multiplies binary_op2; - return thrust::inner_product(exec, first1, last1, first2, init, binary_op1, binary_op2); -} // end inner_product() - - -template -OutputType inner_product(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputType init, - BinaryFunction1 binary_op1, - BinaryFunction2 binary_op2) -{ - typedef thrust::zip_iterator > ZipIter; - - ZipIter first = thrust::make_zip_iterator(thrust::make_tuple(first1,first2)); - - // only the first iterator in the tuple is relevant for the purposes of last - ZipIter last = thrust::make_zip_iterator(thrust::make_tuple(last1, first2)); - - return thrust::transform_reduce(exec, first, last, thrust::detail::zipped_binary_op(binary_op2), init, binary_op1); -} // end inner_product() - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/logical.h b/compat/thrust/system/detail/generic/logical.h deleted file mode 100644 index e0d01e3..0000000 --- a/compat/thrust/system/detail/generic/logical.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template -bool all_of(thrust::execution_policy &exec, InputIterator first, InputIterator last, Predicate pred) -{ - return thrust::find_if(exec, first, last, thrust::detail::not1(pred)) == last; -} - -template -bool any_of(thrust::execution_policy &exec, InputIterator first, InputIterator last, Predicate pred) -{ - return thrust::find_if(exec, first, last, pred) != last; -} - -template -bool none_of(thrust::execution_policy &exec, InputIterator first, InputIterator last, Predicate pred) -{ - return !thrust::any_of(exec, first, last, pred); -} - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/memory.h b/compat/thrust/system/detail/generic/memory.h deleted file mode 100644 index c0fe623..0000000 --- a/compat/thrust/system/detail/generic/memory.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file generic/memory.h - * \brief Generic implementation of memory functions. - * Calling some of these is an error. They have no implementation. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template void malloc(thrust::execution_policy &, Size); - -template -thrust::pointer malloc(thrust::execution_policy &s, std::size_t n); - -template void free(thrust::execution_policy &, Pointer); - -template -__host__ __device__ -void assign_value(tag, Pointer1, Pointer2); - -template -__host__ __device__ -void get_value(thrust::execution_policy &, Pointer); - -template -__host__ __device__ -void iter_swap(tag, Pointer1, Pointer2); - -} // end generic -} // end detail -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/generic/memory.inl b/compat/thrust/system/detail/generic/memory.inl deleted file mode 100644 index f89a763..0000000 --- a/compat/thrust/system/detail/generic/memory.inl +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void malloc(thrust::execution_policy &, Size) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} - - -template - thrust::pointer - malloc(thrust::execution_policy &exec, std::size_t n) -{ - thrust::pointer void_ptr = thrust::malloc(exec, sizeof(T) * n); - - return pointer(static_cast(void_ptr.get())); -} // end malloc() - - -template - void free(thrust::execution_policy &, Pointer) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} - - -template -__host__ __device__ -void assign_value(thrust::execution_policy &, Pointer1, Pointer2) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} - - -template -__host__ __device__ -void get_value(thrust::execution_policy &, Pointer) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} - - -template -__host__ __device__ -void iter_swap(tag, Pointer1, Pointer2) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/merge.h b/compat/thrust/system/detail/generic/merge.h deleted file mode 100644 index 5f0b996..0000000 --- a/compat/thrust/system/detail/generic/merge.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -// XXX calling this function is an error; there is no implementation -template - OutputIterator merge(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - - -template - OutputIterator merge(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -template - thrust::pair - merge_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - Compare comp); - - -template - thrust::pair - merge_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/merge.inl b/compat/thrust/system/detail/generic/merge.inl deleted file mode 100644 index b913611..0000000 --- a/compat/thrust/system/detail/generic/merge.inl +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator merge(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end merge() - - -template - OutputIterator merge(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::merge(exec,first1,last1,first2,last2,result,thrust::less()); -} // end merge() - - -template - thrust::pair - merge_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - Compare comp) -{ - typedef thrust::tuple iterator_tuple1; - typedef thrust::tuple iterator_tuple2; - typedef thrust::tuple iterator_tuple3; - - typedef thrust::zip_iterator zip_iterator1; - typedef thrust::zip_iterator zip_iterator2; - typedef thrust::zip_iterator zip_iterator3; - - zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); - zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); - - zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); - zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); - - zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); - - thrust::detail::compare_first comp_first(comp); - - iterator_tuple3 result = thrust::merge(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first).get_iterator_tuple(); - - return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); -} // end merge_by_key() - - -template - thrust::pair - merge_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::merge_by_key(exec, keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, thrust::less()); -} // end merge_by_key() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/mismatch.h b/compat/thrust/system/detail/generic/mismatch.h deleted file mode 100644 index dc581ff..0000000 --- a/compat/thrust/system/detail/generic/mismatch.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - thrust::pair - mismatch(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2); - - -template - thrust::pair - mismatch(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - BinaryPredicate pred); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/mismatch.inl b/compat/thrust/system/detail/generic/mismatch.inl deleted file mode 100644 index 923c27f..0000000 --- a/compat/thrust/system/detail/generic/mismatch.inl +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - thrust::pair - mismatch(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2) -{ - typedef typename thrust::iterator_value::type InputType1; - - // XXX use a placeholder expression here - return thrust::mismatch(exec, first1, last1, first2, thrust::detail::equal_to()); -} // end mismatch() - -template - thrust::pair - mismatch(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - BinaryPredicate pred) -{ - // Contributed by Erich Elsen - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_first = thrust::make_zip_iterator(thrust::make_tuple(first1,first2)); - ZipIterator zipped_last = thrust::make_zip_iterator(thrust::make_tuple(last1, first2)); - - ZipIterator result = thrust::find_if_not(exec, zipped_first, zipped_last, thrust::detail::tuple_binary_predicate(pred)); - - return thrust::make_pair(thrust::get<0>(result.get_iterator_tuple()), - thrust::get<1>(result.get_iterator_tuple())); -} // end mismatch() - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/partition.h b/compat/thrust/system/detail/generic/partition.h deleted file mode 100644 index 63daa1d..0000000 --- a/compat/thrust/system/detail/generic/partition.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file partition.h - * \brief Generic implementations of partition functions. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - ForwardIterator stable_partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - -template - ForwardIterator stable_partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - -template - thrust::pair - stable_partition_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - -template - thrust::pair - stable_partition_copy(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - -template - ForwardIterator partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - -template - ForwardIterator partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - -template - thrust::pair - partition_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - -template - thrust::pair - partition_copy(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - -template - ForwardIterator partition_point(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - -template - bool is_partitioned(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/partition.inl b/compat/thrust/system/detail/generic/partition.inl deleted file mode 100644 index 3298afc..0000000 --- a/compat/thrust/system/detail/generic/partition.inl +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - ForwardIterator stable_partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - // copy input to temp buffer - thrust::detail::temporary_array temp(exec, first, last); - - // count the size of the true partition - typename thrust::iterator_difference::type num_true = thrust::count_if(exec, first,last,pred); - - // point to the beginning of the false partition - ForwardIterator out_false = first; - thrust::advance(out_false, num_true); - - return thrust::stable_partition_copy(exec, temp.begin(), temp.end(), first, out_false, pred).first; -} // end stable_partition() - - -template - ForwardIterator stable_partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - // copy input to temp buffer - thrust::detail::temporary_array temp(exec, first, last); - - // count the size of the true partition - InputIterator stencil_last = stencil; - thrust::advance(stencil_last, temp.size()); - typename thrust::iterator_difference::type num_true = thrust::count_if(exec, stencil, stencil_last, pred); - - // point to the beginning of the false partition - ForwardIterator out_false = first; - thrust::advance(out_false, num_true); - - return thrust::stable_partition_copy(exec, temp.begin(), temp.end(), stencil, first, out_false, pred).first; -} // end stable_partition() - - -template - thrust::pair - stable_partition_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - thrust::detail::unary_negate not_pred(pred); - - // remove_copy_if the true partition to out_true - OutputIterator1 end_of_true_partition = thrust::remove_copy_if(exec, first, last, out_true, not_pred); - - // remove_copy_if the false partition to out_false - OutputIterator2 end_of_false_partition = thrust::remove_copy_if(exec, first, last, out_false, pred); - - return thrust::make_pair(end_of_true_partition, end_of_false_partition); -} // end stable_partition_copy() - - -template - thrust::pair - stable_partition_copy(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - thrust::detail::unary_negate not_pred(pred); - - // remove_copy_if the true partition to out_true - OutputIterator1 end_of_true_partition = thrust::remove_copy_if(exec, first, last, stencil, out_true, not_pred); - - // remove_copy_if the false partition to out_false - OutputIterator2 end_of_false_partition = thrust::remove_copy_if(exec, first, last, stencil, out_false, pred); - - return thrust::make_pair(end_of_true_partition, end_of_false_partition); -} // end stable_partition_copy() - - -template - ForwardIterator partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - return thrust::stable_partition(exec, first, last, pred); -} // end partition() - - -template - ForwardIterator partition(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - return thrust::stable_partition(exec, first, last, stencil, pred); -} // end partition() - - -template - thrust::pair - partition_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - return thrust::stable_partition_copy(exec,first,last,out_true,out_false,pred); -} // end partition_copy() - - -template - thrust::pair - partition_copy(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - return thrust::stable_partition_copy(exec,first,last,stencil,out_true,out_false,pred); -} // end partition_copy() - - -template - ForwardIterator partition_point(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - return thrust::find_if_not(exec, first, last, pred); -} // end partition_point() - - -template - bool is_partitioned(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - return thrust::is_sorted(exec, - thrust::make_transform_iterator(first, thrust::detail::not1(pred)), - thrust::make_transform_iterator(last, thrust::detail::not1(pred))); -} // end is_partitioned() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/reduce.h b/compat/thrust/system/detail/generic/reduce.h deleted file mode 100644 index 2811df1..0000000 --- a/compat/thrust/system/detail/generic/reduce.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - typename thrust::iterator_traits::value_type - reduce(thrust::execution_policy &exec, InputIterator first, InputIterator last); - -template - T reduce(thrust::execution_policy &exec, InputIterator first, InputIterator last, T init); - -template - T reduce(thrust::execution_policy &exec, InputIterator first, InputIterator last, T init, BinaryFunction binary_op); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/reduce.inl b/compat/thrust/system/detail/generic/reduce.inl deleted file mode 100644 index 8f52385..0000000 --- a/compat/thrust/system/detail/generic/reduce.inl +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - typename thrust::iterator_traits::value_type - reduce(thrust::execution_policy &exec, InputIterator first, InputIterator last) -{ - typedef typename thrust::iterator_value::type InputType; - - // use InputType(0) as init by default - return thrust::reduce(exec, first, last, InputType(0)); -} // end reduce() - - -template - T reduce(thrust::execution_policy &exec, InputIterator first, InputIterator last, T init) -{ - // use plus by default - return thrust::reduce(exec, first, last, init, thrust::plus()); -} // end reduce() - - -template - OutputType reduce(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - OutputType init, - BinaryFunction binary_op) -{ - // unimplemented - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return OutputType(); -} // end reduce() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/reduce_by_key.h b/compat/thrust/system/detail/generic/reduce_by_key.h deleted file mode 100644 index c6064ab..0000000 --- a/compat/thrust/system/detail/generic/reduce_by_key.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - thrust::pair - reduce_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output); - -template - thrust::pair - reduce_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred); - -template - thrust::pair - reduce_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/reduce_by_key.inl b/compat/thrust/system/detail/generic/reduce_by_key.inl deleted file mode 100644 index 2ca21a5..0000000 --- a/compat/thrust/system/detail/generic/reduce_by_key.inl +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce_by_key.inl - * \brief Inline file for reduce_by_key.h. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template -struct reduce_by_key_functor -{ - AssociativeOperator binary_op; - - typedef typename thrust::tuple result_type; - - __host__ __device__ - reduce_by_key_functor(AssociativeOperator _binary_op) : binary_op(_binary_op) {} - - __host__ __device__ - result_type operator()(result_type a, result_type b) - { - return result_type(thrust::get<1>(b) ? thrust::get<0>(b) : binary_op(thrust::get<0>(a), thrust::get<0>(b)), - thrust::get<1>(a) | thrust::get<1>(b)); - } -}; - -} // end namespace detail - - -template - thrust::pair - reduce_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_traits::difference_type difference_type; - typedef typename thrust::iterator_traits::value_type KeyType; - - typedef unsigned int FlagType; // TODO use difference_type - - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator2 is a "pure" output iterator - // TemporaryType = InputIterator2::value_type - // else - // TemporaryType = OutputIterator2::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - typedef typename thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - if (keys_first == keys_last) - return thrust::make_pair(keys_output, values_output); - - // input size - difference_type n = keys_last - keys_first; - - InputIterator2 values_last = values_first + n; - - // compute head flags - thrust::detail::temporary_array head_flags(exec, n); - thrust::transform(exec, keys_first, keys_last - 1, keys_first + 1, head_flags.begin() + 1, thrust::detail::not2(binary_pred)); - head_flags[0] = 1; - - // compute tail flags - thrust::detail::temporary_array tail_flags(exec, n); //COPY INSTEAD OF TRANSFORM - thrust::transform(exec, keys_first, keys_last - 1, keys_first + 1, tail_flags.begin(), thrust::detail::not2(binary_pred)); - tail_flags[n-1] = 1; - - // scan the values by flag - thrust::detail::temporary_array scanned_values(exec, n); - thrust::detail::temporary_array scanned_tail_flags(exec, n); - - thrust::inclusive_scan - (exec, - thrust::make_zip_iterator(thrust::make_tuple(values_first, head_flags.begin())), - thrust::make_zip_iterator(thrust::make_tuple(values_last, head_flags.end())), - thrust::make_zip_iterator(thrust::make_tuple(scanned_values.begin(), scanned_tail_flags.begin())), - detail::reduce_by_key_functor(binary_op)); - - thrust::exclusive_scan(exec, tail_flags.begin(), tail_flags.end(), scanned_tail_flags.begin(), FlagType(0), thrust::plus()); - - // number of unique keys - FlagType N = scanned_tail_flags[n - 1] + 1; - - // scatter the keys and accumulated values - thrust::scatter_if(exec, keys_first, keys_last, scanned_tail_flags.begin(), head_flags.begin(), keys_output); - thrust::scatter_if(exec, scanned_values.begin(), scanned_values.end(), scanned_tail_flags.begin(), tail_flags.begin(), values_output); - - return thrust::make_pair(keys_output + N, values_output + N); -} // end reduce_by_key() - - -template - thrust::pair - reduce_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output) -{ - typedef typename thrust::iterator_value::type KeyType; - - // use equal_to as default BinaryPredicate - return thrust::reduce_by_key(exec, keys_first, keys_last, values_first, keys_output, values_output, thrust::equal_to()); -} // end reduce_by_key() - - -template - thrust::pair - reduce_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - typedef typename thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - >::type T; - - // use plus as default BinaryFunction - return thrust::reduce_by_key(exec, - keys_first, keys_last, - values_first, - keys_output, - values_output, - binary_pred, - thrust::plus()); -} // end reduce_by_key() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/remove.h b/compat/thrust/system/detail/generic/remove.h deleted file mode 100644 index e236735..0000000 --- a/compat/thrust/system/detail/generic/remove.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file remove.h - * \brief Generic implementations of remove functions. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - ForwardIterator remove(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &value); - -template - OutputIterator remove_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - const T &value); - -template - ForwardIterator remove_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - -template - ForwardIterator remove_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - -template - OutputIterator remove_copy_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - -template - OutputIterator remove_copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/remove.inl b/compat/thrust/system/detail/generic/remove.inl deleted file mode 100644 index 8a533e0..0000000 --- a/compat/thrust/system/detail/generic/remove.inl +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file remove.inl - * \brief Inline file for remove.h - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - ForwardIterator remove(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &value) -{ - thrust::detail::equal_to_value pred(value); - - // XXX consider using a placeholder here - return thrust::remove_if(exec, first, last, pred); -} // end remove() - - -template - OutputIterator remove_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - const T &value) -{ - thrust::detail::equal_to_value pred(value); - - // XXX consider using a placeholder here - return thrust::remove_copy_if(exec, first, last, result, pred); -} // end remove_copy() - - -template - ForwardIterator remove_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - // create temporary storage for an intermediate result - thrust::detail::temporary_array temp(exec, first, last); - - // remove into temp - return thrust::remove_copy_if(exec, temp.begin(), temp.end(), temp.begin(), first, pred); -} // end remove_if() - - -template - ForwardIterator remove_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - // create temporary storage for an intermediate result - thrust::detail::temporary_array temp(exec, first, last); - - // remove into temp - return thrust::remove_copy_if(exec, temp.begin(), temp.end(), stencil, first, pred); -} // end remove_if() - - -template - OutputIterator remove_copy_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - return thrust::remove_copy_if(exec, first, last, first, result, pred); -} // end remove_copy_if() - - -template - OutputIterator remove_copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - return thrust::copy_if(exec, first, last, stencil, result, thrust::detail::not1(pred)); -} // end remove_copy_if() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/replace.h b/compat/thrust/system/detail/generic/replace.h deleted file mode 100644 index deb2e55..0000000 --- a/compat/thrust/system/detail/generic/replace.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator replace_copy_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred, - const T &new_value); - - -template - OutputIterator replace_copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred, - const T &new_value); - - -template - OutputIterator replace_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - const T &old_value, - const T &new_value); - - -template - void replace_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred, - const T &new_value); - - -template - void replace_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred, - const T &new_value); - - -template - void replace(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &old_value, - const T &new_value); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/replace.inl b/compat/thrust/system/detail/generic/replace.inl deleted file mode 100644 index 52e7118..0000000 --- a/compat/thrust/system/detail/generic/replace.inl +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -// this functor receives x, and returns a new_value if predicate(x) is true; otherwise, -// it returns x -template - struct new_value_if -{ - new_value_if(Predicate p, NewType nv):pred(p),new_value(nv){} - - template - __host__ __device__ - OutputType operator()(const InputType x) const - { - return pred(x) ? new_value : x; - } // end operator()() - - // this version of operator()() works like the previous but - // feeds its second argument to pred - template - __host__ __device__ - OutputType operator()(const InputType x, const PredicateArgumentType y) - { - return pred(y) ? new_value : x; - } // end operator()() - - Predicate pred; - NewType new_value; -}; // end new_value_if - -// this unary functor ignores its argument and returns a constant -template - struct constant_unary -{ - constant_unary(T _c):c(_c){} - - template - __host__ __device__ - T operator()(U &x) - { - return c; - } // end operator()() - - T c; -}; // end constant_unary - -} // end detail - -template - OutputIterator replace_copy_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred, - const T &new_value) -{ - typedef typename thrust::iterator_traits::value_type InputType; - typedef typename thrust::iterator_traits::value_type OutputType; - - detail::new_value_if op(pred,new_value); - return thrust::transform(exec, first, last, result, op); -} // end replace_copy_if() - -template - OutputIterator replace_copy_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred, - const T &new_value) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - - detail::new_value_if op(pred,new_value); - return thrust::transform(exec, first, last, stencil, result, op); -} // end replace_copy_if() - - -template - OutputIterator replace_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - const T &old_value, - const T &new_value) -{ - thrust::detail::equal_to_value pred(old_value); - return thrust::replace_copy_if(exec, first, last, result, pred, new_value); -} // end replace_copy() - -template - void replace_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred, - const T &new_value) -{ - detail::constant_unary f(new_value); - - // XXX replace this with generate_if: - // constant_nullary f(new_value); - // generate_if(first, last, first, f, pred); - thrust::transform_if(exec, first, last, first, first, f, pred); -} // end replace_if() - -template - void replace_if(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred, - const T &new_value) -{ - detail::constant_unary f(new_value); - - // XXX replace this with generate_if: - // constant_nullary f(new_value); - // generate_if(stencil, stencil + n, first, f, pred); - thrust::transform_if(exec, first, last, stencil, first, f, pred); -} // end replace_if() - -template - void replace(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &old_value, - const T &new_value) -{ - thrust::detail::equal_to_value pred(old_value); - return thrust::replace_if(exec, first, last, pred, new_value); -} // end replace() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/reverse.h b/compat/thrust/system/detail/generic/reverse.h deleted file mode 100644 index 327bf22..0000000 --- a/compat/thrust/system/detail/generic/reverse.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void reverse(thrust::execution_policy &exec, - BidirectionalIterator first, - BidirectionalIterator last); - -template - OutputIterator reverse_copy(thrust::execution_policy &exec, - BidirectionalIterator first, - BidirectionalIterator last, - OutputIterator result); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/reverse.inl b/compat/thrust/system/detail/generic/reverse.inl deleted file mode 100644 index 27c1bbf..0000000 --- a/compat/thrust/system/detail/generic/reverse.inl +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void reverse(thrust::execution_policy &exec, - BidirectionalIterator first, - BidirectionalIterator last) -{ - typedef typename thrust::iterator_difference::type difference_type; - - // find the midpoint of [first,last) - difference_type N = thrust::distance(first, last); - BidirectionalIterator mid(first); - thrust::advance(mid, N / 2); - - // swap elements of [first,mid) with [last - 1, mid) - thrust::swap_ranges(exec, first, mid, thrust::make_reverse_iterator(last)); -} // end reverse() - -template - OutputIterator reverse_copy(thrust::execution_policy &exec, - BidirectionalIterator first, - BidirectionalIterator last, - OutputIterator result) -{ - return thrust::copy(exec, - thrust::make_reverse_iterator(last), - thrust::make_reverse_iterator(first), - result); -} // end reverse_copy() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - - diff --git a/compat/thrust/system/detail/generic/scalar/binary_search.h b/compat/thrust/system/detail/generic/scalar/binary_search.h deleted file mode 100644 index 6ed9e8d..0000000 --- a/compat/thrust/system/detail/generic/scalar/binary_search.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ - -namespace system -{ - -namespace detail -{ - -namespace generic -{ - -namespace scalar -{ - -template -__host__ __device__ -RandomAccessIterator lower_bound_n(RandomAccessIterator first, - Size n, - const T &val, - BinaryPredicate comp); - -template -__host__ __device__ -RandomAccessIterator lower_bound(RandomAccessIterator first, RandomAccessIterator last, - const T &val, - BinaryPredicate comp); - -template -__host__ __device__ -RandomAccessIterator upper_bound_n(RandomAccessIterator first, - Size n, - const T &val, - BinaryPredicate comp); - -template -__host__ __device__ -RandomAccessIterator upper_bound(RandomAccessIterator first, RandomAccessIterator last, - const T &val, - BinaryPredicate comp); - -template -__host__ __device__ - pair - equal_range(RandomAccessIterator first, RandomAccessIterator last, - const T &val, - BinaryPredicate comp); - -template -__host__ __device__ -bool binary_search(RandomAccessIterator first, RandomAccessIterator last, const T &value, Compare comp); - -} // end scalar - -} // end generic - -} // end detail - -} // end system - -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/generic/scalar/binary_search.inl b/compat/thrust/system/detail/generic/scalar/binary_search.inl deleted file mode 100644 index 5a9d379..0000000 --- a/compat/thrust/system/detail/generic/scalar/binary_search.inl +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace system -{ - -namespace detail -{ - -namespace generic -{ - -namespace scalar -{ - -template -__host__ __device__ -RandomAccessIterator lower_bound_n(RandomAccessIterator first, - Size n, - const T &val, - BinaryPredicate comp) -{ - // wrap comp - thrust::detail::host_device_function< - BinaryPredicate, - bool - > wrapped_comp(comp); - - Size start = 0, i; - while(start < n) - { - i = (start + n) / 2; - if(wrapped_comp(first[i], val)) - { - start = i + 1; - } - else - { - n = i; - } - } // end while - - return first + start; -} - -// XXX generalize these upon implementation of scalar::distance & scalar::advance - -template -__host__ __device__ -RandomAccessIterator lower_bound(RandomAccessIterator first, RandomAccessIterator last, - const T &val, - BinaryPredicate comp) -{ - typename thrust::iterator_difference::type n = last - first; - return lower_bound_n(first, n, val, comp); -} - -template -__host__ __device__ -RandomAccessIterator upper_bound_n(RandomAccessIterator first, - Size n, - const T &val, - BinaryPredicate comp) -{ - // wrap comp - thrust::detail::host_device_function< - BinaryPredicate, - bool - > wrapped_comp(comp); - - Size start = 0, i; - while(start < n) - { - i = (start + n) / 2; - if(wrapped_comp(val, first[i])) - { - n = i; - } - else - { - start = i + 1; - } - } // end while - - return first + start; -} - -template -__host__ __device__ -RandomAccessIterator upper_bound(RandomAccessIterator first, RandomAccessIterator last, - const T &val, - BinaryPredicate comp) -{ - typename thrust::iterator_difference::type n = last - first; - return upper_bound_n(first, n, val, comp); -} - -template -__host__ __device__ - pair - equal_range(RandomAccessIterator first, RandomAccessIterator last, - const T &val, - BinaryPredicate comp) -{ - RandomAccessIterator lb = thrust::system::detail::generic::scalar::lower_bound(first, last, val, comp); - return thrust::make_pair(lb, thrust::system::detail::generic::scalar::upper_bound(lb, last, val, comp)); -} - - -template -__host__ __device__ -bool binary_search(RandomAccessIterator first, RandomAccessIterator last, const T &value, Compare comp) -{ - RandomAccessIterator iter = thrust::system::detail::generic::scalar::lower_bound(first, last, value, comp); - - // wrap comp - thrust::detail::host_device_function< - Compare, - bool - > wrapped_comp(comp); - - return iter != last && !wrapped_comp(value,*iter); -} - -} // end scalar - -} // end generic - -} // end detail - -} // end system - -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/generic/scan.h b/compat/thrust/system/detail/generic/scan.h deleted file mode 100644 index 205f87f..0000000 --- a/compat/thrust/system/detail/generic/scan.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator inclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -// XXX it is an error to call this function; it has no implementation -template - OutputIterator inclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op); - - -template - OutputIterator exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template - OutputIterator exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init); - - -// XXX it is an error to call this function; it has no implementation -template - OutputIterator exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/scan.inl b/compat/thrust/system/detail/generic/scan.inl deleted file mode 100644 index 33e0803..0000000 --- a/compat/thrust/system/detail/generic/scan.inl +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator inclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - - typedef typename thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - >::type ValueType; - - // assume plus as the associative operator - return thrust::inclusive_scan(exec, first, last, result, thrust::plus()); -} // end inclusive_scan() - - -template - OutputIterator exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - - typedef typename thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - >::type ValueType; - - // assume 0 as the initialization value - return thrust::exclusive_scan(exec, first, last, result, ValueType(0)); -} // end exclusive_scan() - - -template - OutputIterator exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init) -{ - // assume plus as the associative operator - return thrust::exclusive_scan(exec, first, last, result, init, thrust::plus()); -} // end exclusive_scan() - - -template - OutputIterator inclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end inclusive_scan - - -template - OutputIterator exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end exclusive_scan() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/scan_by_key.h b/compat/thrust/system/detail/generic/scan_by_key.h deleted file mode 100644 index 160121b..0000000 --- a/compat/thrust/system/detail/generic/scan_by_key.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan_by_key.h - * \brief Generic implementations of key-value scans. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator inclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result); - - -template - OutputIterator inclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred); - - -template - OutputIterator inclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - AssociativeOperator binary_op); - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result); - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init); - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred); - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - AssociativeOperator binary_op); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/scan_by_key.inl b/compat/thrust/system/detail/generic/scan_by_key.inl deleted file mode 100644 index d866dde..0000000 --- a/compat/thrust/system/detail/generic/scan_by_key.inl +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template -struct segmented_scan_functor -{ - AssociativeOperator binary_op; - - typedef typename thrust::tuple result_type; - - __host__ __device__ - segmented_scan_functor(AssociativeOperator _binary_op) : binary_op(_binary_op) {} - - __host__ __device__ - result_type operator()(result_type a, result_type b) - { - return result_type(thrust::get<1>(b) ? thrust::get<0>(b) : binary_op(thrust::get<0>(a), thrust::get<0>(b)), - thrust::get<1>(a) | thrust::get<1>(b)); - } -}; - -} // end namespace detail - - -template - OutputIterator inclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result) -{ - typedef typename thrust::iterator_traits::value_type InputType1; - return thrust::inclusive_scan_by_key(exec, first1, last1, first2, result, thrust::equal_to()); -} - - -template - OutputIterator inclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - return thrust::inclusive_scan_by_key(exec, first1, last1, first2, result, binary_pred, thrust::plus()); -} - - -template - OutputIterator inclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - AssociativeOperator binary_op) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - typedef unsigned int HeadFlagType; - - const size_t n = last1 - first1; - - if(n != 0) - { - // compute head flags - thrust::detail::temporary_array flags(exec, n); - flags[0] = 1; thrust::transform(exec, first1, last1 - 1, first1 + 1, flags.begin() + 1, thrust::detail::not2(binary_pred)); - - // scan key-flag tuples, - // For additional details refer to Section 2 of the following paper - // S. Sengupta, M. Harris, and M. Garland. "Efficient parallel scan algorithms for GPUs" - // NVIDIA Technical Report NVR-2008-003, December 2008 - // http://mgarland.org/files/papers/nvr-2008-003.pdf - thrust::inclusive_scan - (exec, - thrust::make_zip_iterator(thrust::make_tuple(first2, flags.begin())), - thrust::make_zip_iterator(thrust::make_tuple(first2, flags.begin())) + n, - thrust::make_zip_iterator(thrust::make_tuple(result, flags.begin())), - detail::segmented_scan_functor(binary_op)); - } - - return result + n; -} - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - return thrust::exclusive_scan_by_key(exec, first1, last1, first2, result, OutputType(0)); -} - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init) -{ - typedef typename thrust::iterator_traits::value_type InputType1; - return thrust::exclusive_scan_by_key(exec, first1, last1, first2, result, init, thrust::equal_to()); -} - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - return thrust::exclusive_scan_by_key(exec, first1, last1, first2, result, init, binary_pred, thrust::plus()); -} - - -template - OutputIterator exclusive_scan_by_key(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - AssociativeOperator binary_op) -{ - typedef typename thrust::iterator_traits::value_type OutputType; - typedef unsigned int HeadFlagType; - - const size_t n = last1 - first1; - - if(n != 0) - { - InputIterator2 last2 = first2 + n; - - // compute head flags - thrust::detail::temporary_array flags(exec, n); - flags[0] = 1; thrust::transform(exec, first1, last1 - 1, first1 + 1, flags.begin() + 1, thrust::detail::not2(binary_pred)); - - // shift input one to the right and initialize segments with init - thrust::detail::temporary_array temp(exec, n); - thrust::replace_copy_if(exec, first2, last2 - 1, flags.begin() + 1, temp.begin() + 1, thrust::negate(), init); - temp[0] = init; - - // scan key-flag tuples, - // For additional details refer to Section 2 of the following paper - // S. Sengupta, M. Harris, and M. Garland. "Efficient parallel scan algorithms for GPUs" - // NVIDIA Technical Report NVR-2008-003, December 2008 - // http://mgarland.org/files/papers/nvr-2008-003.pdf - thrust::inclusive_scan(exec, - thrust::make_zip_iterator(thrust::make_tuple(temp.begin(), flags.begin())), - thrust::make_zip_iterator(thrust::make_tuple(temp.begin(), flags.begin())) + n, - thrust::make_zip_iterator(thrust::make_tuple(result, flags.begin())), - detail::segmented_scan_functor(binary_op)); - } - - return result + n; -} - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/scatter.h b/compat/thrust/system/detail/generic/scatter.h deleted file mode 100644 index 858d11a..0000000 --- a/compat/thrust/system/detail/generic/scatter.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void scatter(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - RandomAccessIterator output); - - -template - void scatter_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output); - - -template - void scatter_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output, - Predicate pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/scatter.inl b/compat/thrust/system/detail/generic/scatter.inl deleted file mode 100644 index 8c40359..0000000 --- a/compat/thrust/system/detail/generic/scatter.inl +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void scatter(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - RandomAccessIterator output) -{ - thrust::transform(exec, - first, - last, - thrust::make_permutation_iterator(output, map), - thrust::identity::type>()); -} // end scatter() - - -template - void scatter_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output) -{ - // default predicate is identity - typedef typename thrust::iterator_value::type StencilType; - thrust::scatter_if(exec, first, last, map, stencil, output, thrust::identity()); -} // end scatter_if() - - -template - void scatter_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 map, - InputIterator3 stencil, - RandomAccessIterator output, - Predicate pred) -{ - typedef typename thrust::iterator_value::type InputType; - thrust::transform_if(exec, first, last, stencil, thrust::make_permutation_iterator(output, map), thrust::identity(), pred); -} // end scatter_if() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/select_system.h b/compat/thrust/system/detail/generic/select_system.h deleted file mode 100644 index 250a0bc..0000000 --- a/compat/thrust/system/detail/generic/select_system.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace select_system_detail -{ - - -// min_system case 1: both systems have the same type, just return the first one -template -__host__ __device__ -System &min_system(thrust::execution_policy &system1, - thrust::execution_policy &) -{ - return thrust::detail::derived_cast(system1); -} // end min_system() - - -// min_system case 2: systems have differing type and the first type is considered the minimum -template -__host__ __device__ - typename thrust::detail::enable_if< - thrust::detail::is_same< - System1, - typename thrust::detail::minimum_system::type - >::value, - System1 & - >::type - min_system(thrust::execution_policy &system1, thrust::execution_policy &) -{ - return thrust::detail::derived_cast(system1); -} // end min_system() - - -// min_system case 3: systems have differing type and the second type is considered the minimum -template -__host__ __device__ - typename thrust::detail::enable_if< - thrust::detail::is_same< - System2, - typename thrust::detail::minimum_system::type - >::value, - System2 & - >::type - min_system(thrust::execution_policy &, thrust::execution_policy &system2) -{ - return thrust::detail::derived_cast(system2); -} // end min_system() - - -} // end select_system_detail - - -template -__host__ __device__ - typename thrust::detail::disable_if< - select_system1_exists::value, - System & - >::type - select_system(thrust::execution_policy &system) -{ - return thrust::detail::derived_cast(system); -} // end select_system() - - -template -__host__ __device__ - typename thrust::detail::enable_if_defined< - thrust::detail::minimum_system - >::type - &select_system(thrust::execution_policy &system1, - thrust::execution_policy &system2) -{ - return select_system_detail::min_system(system1,system2); -} // end select_system() - - -template -__host__ __device__ - typename thrust::detail::lazy_disable_if< - select_system3_exists::value, - thrust::detail::minimum_system - >::type - &select_system(thrust::execution_policy &system1, - thrust::execution_policy &system2, - thrust::execution_policy &system3) -{ - return select_system(select_system(system1,system2), system3); -} // end select_system() - - -template -__host__ __device__ - typename thrust::detail::lazy_disable_if< - select_system4_exists::value, - thrust::detail::minimum_system - >::type - &select_system(thrust::execution_policy &system1, - thrust::execution_policy &system2, - thrust::execution_policy &system3, - thrust::execution_policy &system4) -{ - return select_system(select_system(system1,system2,system3), system4); -} // end select_system() - - -template -__host__ __device__ - typename thrust::detail::lazy_disable_if< - select_system5_exists::value, - thrust::detail::minimum_system - >::type - &select_system(thrust::execution_policy &system1, - thrust::execution_policy &system2, - thrust::execution_policy &system3, - thrust::execution_policy &system4, - thrust::execution_policy &system5) -{ - return select_system(select_system(system1,system2,system3,system4), system5); -} // end select_system() - - -template -__host__ __device__ - typename thrust::detail::lazy_disable_if< - select_system6_exists::value, - thrust::detail::minimum_system - >::type - &select_system(thrust::execution_policy &system1, - thrust::execution_policy &system2, - thrust::execution_policy &system3, - thrust::execution_policy &system4, - thrust::execution_policy &system5, - thrust::execution_policy &system6) -{ - return select_system(select_system(system1,system2,system3,system4,system5), system6); -} // end select_system() - - -// map a single any_system_tag to device_system_tag -inline __host__ __device__ -thrust::device_system_tag select_system(thrust::any_system_tag) -{ - return thrust::device_system_tag(); -} // end select_system() - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/sequence.h b/compat/thrust/system/detail/generic/sequence.h deleted file mode 100644 index b23a7b5..0000000 --- a/compat/thrust/system/detail/generic/sequence.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void sequence(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - - -template - void sequence(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - T init); - - -template - void sequence(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - T init, - T step); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/sequence.inl b/compat/thrust/system/detail/generic/sequence.inl deleted file mode 100644 index 45aec69..0000000 --- a/compat/thrust/system/detail/generic/sequence.inl +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void sequence(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - typedef typename thrust::iterator_traits::value_type T; - - thrust::sequence(exec, first, last, T(0)); -} // end sequence() - - -template - void sequence(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - T init) -{ - thrust::sequence(exec, first, last, init, T(1)); -} // end sequence() - - -template - void sequence(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - T init, - T step) -{ - thrust::tabulate(exec, first, last, init + step * thrust::placeholders::_1); -} // end sequence() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/set_operations.h b/compat/thrust/system/detail/generic/set_operations.h deleted file mode 100644 index 1ca8d39..0000000 --- a/compat/thrust/system/detail/generic/set_operations.h +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator set_difference(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -// XXX it is an error to call this function; it has no implementation -template - OutputIterator set_difference(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - - -template - thrust::pair - set_difference_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -template - thrust::pair - set_difference_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp); - - -template - OutputIterator set_intersection(thrust::execution_policy &system, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -// XXX it is an error to call this function; it has no implementation -template - OutputIterator set_intersection(thrust::execution_policy &system, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - - -template - thrust::pair - set_intersection_by_key(thrust::execution_policy &system, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -template - thrust::pair - set_intersection_by_key(thrust::execution_policy &system, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp); - - -template - OutputIterator set_symmetric_difference(thrust::execution_policy &system, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -// XXX it is an error to call this function; it has no implementation -template - OutputIterator set_symmetric_difference(thrust::execution_policy &system, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - - -template - thrust::pair - set_symmetric_difference_by_key(thrust::execution_policy &system, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -template - thrust::pair - set_symmetric_difference_by_key(thrust::execution_policy &system, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp); - - -template - OutputIterator set_union(thrust::execution_policy &system, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result); - - -// XXX it is an error to call this function; it has no implementation -template - OutputIterator set_union(thrust::execution_policy &system, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - - -template - thrust::pair - set_union_by_key(thrust::execution_policy &system, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -template - thrust::pair - set_union_by_key(thrust::execution_policy &system, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/set_operations.inl b/compat/thrust/system/detail/generic/set_operations.inl deleted file mode 100644 index bac9ccd..0000000 --- a/compat/thrust/system/detail/generic/set_operations.inl +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator set_difference(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_difference(exec, first1, last1, first2, last2, result, thrust::less()); -} // end set_difference() - - -template - thrust::pair - set_difference_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_difference_by_key(exec, keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, thrust::less()); -} // end set_difference_by_key() - - -template - thrust::pair - set_difference_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - typedef thrust::tuple iterator_tuple1; - typedef thrust::tuple iterator_tuple2; - typedef thrust::tuple iterator_tuple3; - - typedef thrust::zip_iterator zip_iterator1; - typedef thrust::zip_iterator zip_iterator2; - typedef thrust::zip_iterator zip_iterator3; - - zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); - zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); - - zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); - zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); - - zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); - - thrust::detail::compare_first comp_first(comp); - - iterator_tuple3 result = thrust::set_difference(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first).get_iterator_tuple(); - - return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); -} // end set_difference_by_key() - - -template - OutputIterator set_intersection(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_intersection(exec, first1, last1, first2, last2, result, thrust::less()); -} // end set_intersection() - - -template - thrust::pair - set_intersection_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_intersection_by_key(exec, keys_first1, keys_last1, keys_first2, keys_last2, values_first1, keys_result, values_result, thrust::less()); -} // end set_intersection_by_key() - - -template - thrust::pair - set_intersection_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - typedef thrust::tuple iterator_tuple1; - typedef thrust::tuple iterator_tuple2; - typedef thrust::tuple iterator_tuple3; - - typedef thrust::zip_iterator zip_iterator1; - typedef thrust::zip_iterator zip_iterator2; - typedef thrust::zip_iterator zip_iterator3; - - // fabricate a values_first2 by "sending" keys twice - // it should never be dereferenced by set_intersection - InputIterator2 values_first2 = keys_first2; - - zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); - zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); - - zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); - zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); - - zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); - - thrust::detail::compare_first comp_first(comp); - - iterator_tuple3 result = thrust::set_intersection(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first).get_iterator_tuple(); - - return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); -} // end set_intersection_by_key() - - -template - OutputIterator set_symmetric_difference(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_symmetric_difference(exec, first1, last1, first2, last2, result, thrust::less()); -} // end set_symmetric_difference() - - -template - thrust::pair - set_symmetric_difference_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_symmetric_difference_by_key(exec, keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, thrust::less()); -} // end set_symmetric_difference_by_key() - - -template - thrust::pair - set_symmetric_difference_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - typedef thrust::tuple iterator_tuple1; - typedef thrust::tuple iterator_tuple2; - typedef thrust::tuple iterator_tuple3; - - typedef thrust::zip_iterator zip_iterator1; - typedef thrust::zip_iterator zip_iterator2; - typedef thrust::zip_iterator zip_iterator3; - - zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); - zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); - - zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); - zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); - - zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); - - thrust::detail::compare_first comp_first(comp); - - iterator_tuple3 result = thrust::set_symmetric_difference(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first).get_iterator_tuple(); - - return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); -} // end set_symmetric_difference_by_key() - - -template - OutputIterator set_union(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_union(exec, first1, last1, first2, last2, result, thrust::less()); -} // end set_union() - - -template - thrust::pair - set_union_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::set_union_by_key(exec, keys_first1, keys_last1, keys_first2, keys_last2, values_first1, values_first2, keys_result, values_result, thrust::less()); -} // end set_union_by_key() - - -template - thrust::pair - set_union_by_key(thrust::execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - typedef thrust::tuple iterator_tuple1; - typedef thrust::tuple iterator_tuple2; - typedef thrust::tuple iterator_tuple3; - - typedef thrust::zip_iterator zip_iterator1; - typedef thrust::zip_iterator zip_iterator2; - typedef thrust::zip_iterator zip_iterator3; - - zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); - zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); - - zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); - zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); - - zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); - - thrust::detail::compare_first comp_first(comp); - - iterator_tuple3 result = thrust::set_union(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first).get_iterator_tuple(); - - return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); -} // end set_union_by_key() - - -template - OutputIterator set_difference(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end set_difference() - - -template - OutputIterator set_intersection(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end set_intersection() - - -template - OutputIterator set_symmetric_difference(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end set_symmetric_difference() - - -template - OutputIterator set_union(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - return result; -} // end set_union() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/sort.h b/compat/thrust/system/detail/generic/sort.h deleted file mode 100644 index 5498708..0000000 --- a/compat/thrust/system/detail/generic/sort.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last); - - -template - void sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - - -template - void sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - - -template - void sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - - -template - void stable_sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last); - - -// XXX it is an error to call this function; it has no implementation -template - void stable_sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - - -template - void stable_sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - - -// XXX it is an error to call this function; it has no implementation -template - void stable_sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - - -template - bool is_sorted(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - - -template - bool is_sorted(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp); - - -template - ForwardIterator is_sorted_until(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - - -template - ForwardIterator is_sorted_until(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp); - - -} // end generic -} // end detail -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/generic/sort.inl b/compat/thrust/system/detail/generic/sort.inl deleted file mode 100644 index aabb2ee..0000000 --- a/compat/thrust/system/detail/generic/sort.inl +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - typedef typename thrust::iterator_value::type value_type; - thrust::sort(exec, first, last, thrust::less()); -} // end sort() - - -template - void sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // implement with stable_sort - thrust::stable_sort(exec, first, last, comp); -} // end sort() - - -template - void sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - typedef typename thrust::iterator_value::type value_type; - thrust::sort_by_key(exec, keys_first, keys_last, values_first, thrust::less()); -} // end sort_by_key() - - -template - void sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - // implement with stable_sort_by_key - thrust::stable_sort_by_key(exec, keys_first, keys_last, values_first, comp); -} // end sort_by_key() - - -template - void stable_sort(thrust::execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last) -{ - typedef typename thrust::iterator_value::type value_type; - thrust::stable_sort(exec, first, last, thrust::less()); -} // end stable_sort() - - -template - void stable_sort_by_key(thrust::execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - typedef typename iterator_value::type value_type; - thrust::stable_sort_by_key(exec, keys_first, keys_last, values_first, thrust::less()); -} // end stable_sort_by_key() - - -template - bool is_sorted(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - return thrust::is_sorted_until(exec, first, last) == last; -} // end is_sorted() - - -template - bool is_sorted(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp) -{ - return thrust::is_sorted_until(exec, first, last, comp) == last; -} // end is_sorted() - - -template - ForwardIterator is_sorted_until(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - typedef typename thrust::iterator_value::type InputType; - - return thrust::is_sorted_until(exec, first, last, thrust::less()); -} // end is_sorted_until() - - -template - ForwardIterator is_sorted_until(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Compare comp) -{ - if(thrust::distance(first,last) < 2) return last; - - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ForwardIterator first_plus_one = first; - thrust::advance(first_plus_one, 1); - - ZipIterator zipped_first = thrust::make_zip_iterator(thrust::make_tuple(first_plus_one, first)); - ZipIterator zipped_last = thrust::make_zip_iterator(thrust::make_tuple(last, first)); - - return thrust::get<0>(thrust::find_if(exec, zipped_first, zipped_last, thrust::detail::tuple_binary_predicate(comp)).get_iterator_tuple()); -} // end is_sorted_until() - - -template - void stable_sort(tag, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} // end stable_sort() - - -template - void stable_sort_by_key(tag, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - // unimplemented primitive - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); -} // end stable_sort_by_key() - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/swap_ranges.h b/compat/thrust/system/detail/generic/swap_ranges.h deleted file mode 100644 index 5d640d3..0000000 --- a/compat/thrust/system/detail/generic/swap_ranges.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - ForwardIterator2 swap_ranges(thrust::execution_policy &exec, - ForwardIterator1 first1, - ForwardIterator1 last1, - ForwardIterator2 first2); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/swap_ranges.inl b/compat/thrust/system/detail/generic/swap_ranges.inl deleted file mode 100644 index 0e12d07..0000000 --- a/compat/thrust/system/detail/generic/swap_ranges.inl +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -// XXX define this here rather than in internal_functional.h -// to avoid circular dependence between swap.h & internal_functional.h -struct swap_pair_elements -{ - template - __host__ __device__ - void operator()(Tuple t) - { - // use unqualified swap to allow ADL to catch any user-defined swap - using thrust::swap; - swap(thrust::get<0>(t), thrust::get<1>(t)); - } -}; // end swap_pair_elements - -} // end detail - -template - ForwardIterator2 swap_ranges(thrust::execution_policy &exec, - ForwardIterator1 first1, - ForwardIterator1 last1, - ForwardIterator2 first2) -{ - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator result = thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(first1, first2)), - thrust::make_zip_iterator(thrust::make_tuple(last1, first2)), - detail::swap_pair_elements()); - return thrust::get<1>(result.get_iterator_tuple()); -} // end swap_ranges() - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/tabulate.h b/compat/thrust/system/detail/generic/tabulate.h deleted file mode 100644 index e5911b1..0000000 --- a/compat/thrust/system/detail/generic/tabulate.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void tabulate(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - UnaryOperation unary_op); - -template - OutputIterator tabulate_n(thrust::execution_policy &exec, - OutputIterator first, - Size n, - UnaryOperation unary_op); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/tabulate.inl b/compat/thrust/system/detail/generic/tabulate.inl deleted file mode 100644 index d2ffc26..0000000 --- a/compat/thrust/system/detail/generic/tabulate.inl +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - void tabulate(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - UnaryOperation unary_op) -{ - typedef typename iterator_difference::type difference_type; - - // by default, counting_iterator uses a 64b difference_type on 32b platforms to avoid overflowing its counter. - // this causes problems when a zip_iterator is created in transform's implementation -- ForwardIterator is - // incremented by a 64b difference_type and some compilers warn - // to avoid this, specify the counting_iterator's difference_type to be the same as ForwardIterator's. - thrust::counting_iterator iter(0); - - thrust::transform(exec, iter, iter + thrust::distance(first, last), first, unary_op); -} // end tabulate() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - - diff --git a/compat/thrust/system/detail/generic/tag.h b/compat/thrust/system/detail/generic/tag.h deleted file mode 100644 index 577d6a3..0000000 --- a/compat/thrust/system/detail/generic/tag.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file generic/tag.h - * \brief Implementation of the generic backend's tag. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -// tag exists only to make the generic entry points the least priority match -// during ADL. tag should not be derived from and is constructible from anything -struct tag -{ - template - __host__ __device__ inline - tag(const T &) {} -}; - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/temporary_buffer.h b/compat/thrust/system/detail/generic/temporary_buffer.h deleted file mode 100644 index 8cb08b0..0000000 --- a/compat/thrust/system/detail/generic/temporary_buffer.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - thrust::pair, typename thrust::pointer::difference_type> - get_temporary_buffer(thrust::execution_policy &exec, typename thrust::pointer::difference_type n); - - -template - void return_temporary_buffer(thrust::execution_policy &exec, Pointer p); - - -} // end generic -} // end detail -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/detail/generic/temporary_buffer.inl b/compat/thrust/system/detail/generic/temporary_buffer.inl deleted file mode 100644 index 0a6be7e..0000000 --- a/compat/thrust/system/detail/generic/temporary_buffer.inl +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - thrust::pair, typename thrust::pointer::difference_type> - get_temporary_buffer(thrust::execution_policy &exec, typename thrust::pointer::difference_type n) -{ - thrust::pointer ptr = thrust::malloc(exec, n); - - // check for a failed malloc - if(!ptr.get()) - { - n = 0; - } // end if - - return thrust::make_pair(ptr, n); -} // end get_temporary_buffer() - - -template - void return_temporary_buffer(thrust::execution_policy &exec, Pointer p) -{ - thrust::free(exec, p); -} // end return_temporary_buffer() - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/transform.h b/compat/thrust/system/detail/generic/transform.h deleted file mode 100644 index e98d402..0000000 --- a/compat/thrust/system/detail/generic/transform.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputIterator transform(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction op); - -template - OutputIterator transform(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryFunction op); - -template - ForwardIterator transform_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - ForwardIterator result, - UnaryFunction unary_op, - Predicate pred); - -template - ForwardIterator transform_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - ForwardIterator result, - UnaryFunction unary_op, - Predicate pred); - -template - ForwardIterator transform_if(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator3 stencil, - ForwardIterator result, - BinaryFunction binary_op, - Predicate pred); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/transform.inl b/compat/thrust/system/detail/generic/transform.inl deleted file mode 100644 index 8f09953..0000000 --- a/compat/thrust/system/detail/generic/transform.inl +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - OutputIterator transform(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction op) -{ - // XXX WAR the problem of a generic __host__ __device__ functor's inability to invoke - // a function which is only __host__ or __device__ by selecting a generic functor - // which is one or the other - // when nvcc is able to deal with this, remove this WAR - - // given the minimal system, determine the unary transform functor we need - typedef typename thrust::detail::unary_transform_functor::type UnaryTransformFunctor; - - // make an iterator tuple - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_result = - thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(first,result)), - thrust::make_zip_iterator(thrust::make_tuple(last,result)), - UnaryTransformFunctor(op)); - - return thrust::get<1>(zipped_result.get_iterator_tuple()); -} // end transform() - - -template - OutputIterator transform(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryFunction op) -{ - // XXX WAR the problem of a generic __host__ __device__ functor's inability to invoke - // a function which is only __host__ or __device__ by selecting a generic functor - // which is one or the other - // when nvcc is able to deal with this, remove this WAR - - // given the minimal system, determine the binary transform functor we need - typedef typename thrust::detail::binary_transform_functor::type BinaryTransformFunctor; - - // make an iterator tuple - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_result = - thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(first1,first2,result)), - thrust::make_zip_iterator(thrust::make_tuple(last1,first2,result)), - BinaryTransformFunctor(op)); - - return thrust::get<2>(zipped_result.get_iterator_tuple()); -} // end transform() - - -template - ForwardIterator transform_if(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - ForwardIterator result, - UnaryFunction unary_op, - Predicate pred) -{ - // XXX WAR the problem of a generic __host__ __device__ functor's inability to invoke - // a function which is only __host__ or __device__ by selecting a generic functor - // which is one or the other - // when nvcc is able to deal with this, remove this WAR - - // given the minimal system, determine the unary transform_if functor we need - typedef typename thrust::detail::unary_transform_if_functor::type UnaryTransformIfFunctor; - - // make an iterator tuple - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_result = - thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(first,result)), - thrust::make_zip_iterator(thrust::make_tuple(last,result)), - UnaryTransformIfFunctor(unary_op,pred)); - - return thrust::get<1>(zipped_result.get_iterator_tuple()); -} // end transform_if() - - -template - ForwardIterator transform_if(thrust::execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - ForwardIterator result, - UnaryFunction unary_op, - Predicate pred) -{ - // XXX WAR the problem of a generic __host__ __device__ functor's inability to invoke - // a function which is only __host__ or __device__ by selecting a generic functor - // which is one or the other - // when nvcc is able to deal with this, remove this WAR - - // given the minimal system, determine the unary transform_if functor we need - typedef typename thrust::detail::unary_transform_if_with_stencil_functor::type UnaryTransformIfFunctor; - - // make an iterator tuple - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_result = - thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(first,stencil,result)), - thrust::make_zip_iterator(thrust::make_tuple(last,stencil,result)), - UnaryTransformIfFunctor(unary_op,pred)); - - return thrust::get<2>(zipped_result.get_iterator_tuple()); -} // end transform_if() - - -template - ForwardIterator transform_if(thrust::execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator3 stencil, - ForwardIterator result, - BinaryFunction binary_op, - Predicate pred) -{ - // XXX WAR the problem of a generic __host__ __device__ functor's inability to invoke - // a function which is only __host__ or __device__ by selecting a generic functor - // which is one or the other - // when nvcc is able to deal with this, remove this WAR - - // given the minimal system, determine the binary transform_if functor we need - typedef typename thrust::detail::binary_transform_if_functor::type BinaryTransformIfFunctor; - - // make an iterator tuple - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_result = - thrust::for_each(exec, - thrust::make_zip_iterator(thrust::make_tuple(first1,first2,stencil,result)), - thrust::make_zip_iterator(thrust::make_tuple(last1,first2,stencil,result)), - BinaryTransformIfFunctor(binary_op,pred)); - - return thrust::get<3>(zipped_result.get_iterator_tuple()); -} // end transform_if() - - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/transform_reduce.h b/compat/thrust/system/detail/generic/transform_reduce.h deleted file mode 100644 index c1f098f..0000000 --- a/compat/thrust/system/detail/generic/transform_reduce.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputType transform_reduce(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/transform_reduce.inl b/compat/thrust/system/detail/generic/transform_reduce.inl deleted file mode 100644 index ce8b6a1..0000000 --- a/compat/thrust/system/detail/generic/transform_reduce.inl +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputType transform_reduce(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op) -{ - thrust::transform_iterator xfrm_first(first, unary_op); - thrust::transform_iterator xfrm_last(last, unary_op); - - return thrust::reduce(exec, xfrm_first, xfrm_last, init, binary_op); -} // end transform_reduce() - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/transform_scan.h b/compat/thrust/system/detail/generic/transform_scan.h deleted file mode 100644 index 99db86e..0000000 --- a/compat/thrust/system/detail/generic/transform_scan.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputIterator transform_inclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - BinaryFunction binary_op); - -template - OutputIterator transform_exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - T init, - AssociativeOperator binary_op); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/transform_scan.inl b/compat/thrust/system/detail/generic/transform_scan.inl deleted file mode 100644 index a95ec20..0000000 --- a/compat/thrust/system/detail/generic/transform_scan.inl +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - OutputIterator transform_inclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - BinaryFunction binary_op) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if UnaryFunction is AdaptableUnaryFunction - // TemporaryType = AdaptableUnaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - typedef typename thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - thrust::transform_iterator _first(first, unary_op); - thrust::transform_iterator _last(last, unary_op); - - return thrust::inclusive_scan(exec, _first, _last, result, binary_op); -} // end transform_inclusive_scan() - -template - OutputIterator transform_exclusive_scan(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - T init, - AssociativeOperator binary_op) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if UnaryFunction is AdaptableUnaryFunction - // TemporaryType = AdaptableUnaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - typedef typename thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - thrust::transform_iterator _first(first, unary_op); - thrust::transform_iterator _last(last, unary_op); - - return thrust::exclusive_scan(exec, _first, _last, result, init, binary_op); -} // end transform_exclusive_scan() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - - diff --git a/compat/thrust/system/detail/generic/type_traits.h b/compat/thrust/system/detail/generic/type_traits.h deleted file mode 100644 index 4011352..0000000 --- a/compat/thrust/system/detail/generic/type_traits.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file generic/type_traits.h - * \brief Introspection for free functions defined in generic. - */ - -#pragma once - -#include - -namespace thrust -{ - -// forward declaration of any_system_tag for any_conversion below -struct any_system_tag; - -namespace system -{ -namespace detail -{ - -// we must define these traits outside of generic's namespace -namespace generic_type_traits_ns -{ - -typedef char yes; -typedef char (&no)[2]; - -struct any_conversion -{ - template any_conversion(const T &); - - // add this extra constructor to disambiguate conversion from any_system_tag - any_conversion(const any_system_tag &); -}; - -namespace select_system_exists_ns -{ - no select_system(const any_conversion &); - no select_system(const any_conversion &, const any_conversion &); - no select_system(const any_conversion &, const any_conversion &, const any_conversion &); - no select_system(const any_conversion &, const any_conversion &, const any_conversion &, const any_conversion &); - no select_system(const any_conversion &, const any_conversion &, const any_conversion &, const any_conversion &, const any_conversion &); - no select_system(const any_conversion &, const any_conversion &, const any_conversion &, const any_conversion &, const any_conversion &, const any_conversion &); - - template yes check(const T &); - - no check(no); - - template - struct select_system1_exists - { - static Tag &tag; - - static const bool value = sizeof(check(select_system(tag))) == sizeof(yes); - }; - - template - struct select_system2_exists - { - static Tag1 &tag1; - static Tag2 &tag2; - - static const bool value = sizeof(check(select_system(tag1,tag2))) == sizeof(yes); - }; - - template - struct select_system3_exists - { - static Tag1 &tag1; - static Tag2 &tag2; - static Tag3 &tag3; - - static const bool value = sizeof(check(select_system(tag1,tag2,tag3))) == sizeof(yes); - }; - - template - struct select_system4_exists - { - static Tag1 &tag1; - static Tag2 &tag2; - static Tag3 &tag3; - static Tag4 &tag4; - - static const bool value = sizeof(check(select_system(tag1,tag2,tag3,tag4))) == sizeof(yes); - }; - - template - struct select_system5_exists - { - static Tag1 &tag1; - static Tag2 &tag2; - static Tag3 &tag3; - static Tag4 &tag4; - static Tag5 &tag5; - - static const bool value = sizeof(check(select_system(tag1,tag2,tag3,tag4,tag5))) == sizeof(yes); - }; - - template - struct select_system6_exists - { - static Tag1 &tag1; - static Tag2 &tag2; - static Tag3 &tag3; - static Tag4 &tag4; - static Tag5 &tag5; - static Tag6 &tag6; - - static const bool value = sizeof(check(select_system(tag1,tag2,tag3,tag4,tag5,tag6))) == sizeof(yes); - }; -} // end select_system_exists_ns - -} // end generic_type_traits_ns - -namespace generic -{ - -template - struct select_system1_exists - : generic_type_traits_ns::select_system_exists_ns::select_system1_exists -{}; - -template - struct select_system2_exists - : generic_type_traits_ns::select_system_exists_ns::select_system2_exists -{}; - -template - struct select_system3_exists - : generic_type_traits_ns::select_system_exists_ns::select_system3_exists -{}; - -template - struct select_system4_exists - : generic_type_traits_ns::select_system_exists_ns::select_system4_exists -{}; - -template - struct select_system5_exists - : generic_type_traits_ns::select_system_exists_ns::select_system5_exists -{}; - -template - struct select_system6_exists - : generic_type_traits_ns::select_system_exists_ns::select_system6_exists -{}; - -} // end generic -} // end detail -} // end system -} // end thrust - diff --git a/compat/thrust/system/detail/generic/uninitialized_copy.h b/compat/thrust/system/detail/generic/uninitialized_copy.h deleted file mode 100644 index 67e3e68..0000000 --- a/compat/thrust/system/detail/generic/uninitialized_copy.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - ForwardIterator uninitialized_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - ForwardIterator result); - -template - ForwardIterator uninitialized_copy_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - ForwardIterator result); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/uninitialized_copy.inl b/compat/thrust/system/detail/generic/uninitialized_copy.inl deleted file mode 100644 index 414e6e4..0000000 --- a/compat/thrust/system/detail/generic/uninitialized_copy.inl +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template - struct uninitialized_copy_functor -{ - template - __host__ __device__ - void operator()(Tuple t) - { - const InputType &in = thrust::get<0>(t); - OutputType &out = thrust::get<1>(t); - - ::new(static_cast(&out)) OutputType(in); - } // end operator()() -}; // end uninitialized_copy_functor - - -// non-trivial copy constructor path -template - ForwardIterator uninitialized_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - ForwardIterator result, - thrust::detail::false_type) // has_trivial_copy_constructor -{ - // zip up the iterators - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first,result)); - ZipIterator end = begin; - - // get a zip_iterator pointing to the end - const typename thrust::iterator_difference::type n = thrust::distance(first,last); - thrust::advance(end, n); - - // create a functor - typedef typename iterator_traits::value_type InputType; - typedef typename iterator_traits::value_type OutputType; - - detail::uninitialized_copy_functor f; - - // do the for_each - thrust::for_each(exec, begin, end, f); - - // return the end of the output range - return thrust::get<1>(end.get_iterator_tuple()); -} // end uninitialized_copy() - - -// trivial copy constructor path -template - ForwardIterator uninitialized_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - ForwardIterator result, - thrust::detail::true_type) // has_trivial_copy_constructor -{ - return thrust::copy(exec, first, last, result); -} // end uninitialized_copy() - - -// non-trivial copy constructor path -template - ForwardIterator uninitialized_copy_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - ForwardIterator result, - thrust::detail::false_type) // has_trivial_copy_constructor -{ - // zip up the iterators - typedef thrust::tuple IteratorTuple; - typedef thrust::zip_iterator ZipIterator; - - ZipIterator zipped_first = thrust::make_zip_iterator(thrust::make_tuple(first,result)); - - // create a functor - typedef typename iterator_traits::value_type InputType; - typedef typename iterator_traits::value_type OutputType; - - detail::uninitialized_copy_functor f; - - // do the for_each_n - ZipIterator zipped_last = thrust::for_each_n(exec, zipped_first, n, f); - - // return the end of the output range - return thrust::get<1>(zipped_last.get_iterator_tuple()); -} // end uninitialized_copy_n() - - -// trivial copy constructor path -template - ForwardIterator uninitialized_copy_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - ForwardIterator result, - thrust::detail::true_type) // has_trivial_copy_constructor -{ - return thrust::copy_n(exec, first, n, result); -} // end uninitialized_copy_n() - - -} // end detail - - -template - ForwardIterator uninitialized_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - ForwardIterator result) -{ - typedef typename iterator_traits::value_type ResultType; - - typedef typename thrust::detail::has_trivial_copy_constructor::type ResultTypeHasTrivialCopyConstructor; - - return thrust::system::detail::generic::detail::uninitialized_copy(exec, first, last, result, ResultTypeHasTrivialCopyConstructor()); -} // end uninitialized_copy() - - -template - ForwardIterator uninitialized_copy_n(thrust::execution_policy &exec, - InputIterator first, - Size n, - ForwardIterator result) -{ - typedef typename iterator_traits::value_type ResultType; - - typedef typename thrust::detail::has_trivial_copy_constructor::type ResultTypeHasTrivialCopyConstructor; - - return thrust::system::detail::generic::detail::uninitialized_copy_n(exec, first, n, result, ResultTypeHasTrivialCopyConstructor()); -} // end uninitialized_copy_n() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/uninitialized_fill.h b/compat/thrust/system/detail/generic/uninitialized_fill.h deleted file mode 100644 index c1df694..0000000 --- a/compat/thrust/system/detail/generic/uninitialized_fill.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - -template - void uninitialized_fill(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &x); - -template - ForwardIterator uninitialized_fill_n(thrust::execution_policy &exec, - ForwardIterator first, - Size n, - const T &x); - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/uninitialized_fill.inl b/compat/thrust/system/detail/generic/uninitialized_fill.inl deleted file mode 100644 index bb30b24..0000000 --- a/compat/thrust/system/detail/generic/uninitialized_fill.inl +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ -namespace detail -{ - -template - void uninitialized_fill(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &x, - thrust::detail::true_type) // has_trivial_copy_constructor -{ - thrust::fill(exec, first, last, x); -} // end uninitialized_fill() - -template - void uninitialized_fill(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &x, - thrust::detail::false_type) // has_trivial_copy_constructor -{ - typedef typename iterator_traits::value_type ValueType; - - thrust::for_each(exec, first, last, thrust::detail::uninitialized_fill_functor(x)); -} // end uninitialized_fill() - -template - ForwardIterator uninitialized_fill_n(thrust::execution_policy &exec, - ForwardIterator first, - Size n, - const T &x, - thrust::detail::true_type) // has_trivial_copy_constructor -{ - return thrust::fill_n(exec, first, n, x); -} // end uninitialized_fill() - -template - ForwardIterator uninitialized_fill_n(thrust::execution_policy &exec, - ForwardIterator first, - Size n, - const T &x, - thrust::detail::false_type) // has_trivial_copy_constructor -{ - typedef typename iterator_traits::value_type ValueType; - - return thrust::for_each_n(exec, first, n, thrust::detail::uninitialized_fill_functor(x)); -} // end uninitialized_fill() - -} // end detail - -template - void uninitialized_fill(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - const T &x) -{ - typedef typename iterator_traits::value_type ValueType; - - typedef thrust::detail::has_trivial_copy_constructor ValueTypeHasTrivialCopyConstructor; - - thrust::system::detail::generic::detail::uninitialized_fill(exec, first, last, x, - ValueTypeHasTrivialCopyConstructor()); -} // end uninitialized_fill() - -template - ForwardIterator uninitialized_fill_n(thrust::execution_policy &exec, - ForwardIterator first, - Size n, - const T &x) -{ - typedef typename iterator_traits::value_type ValueType; - - typedef thrust::detail::has_trivial_copy_constructor ValueTypeHasTrivialCopyConstructor; - - return thrust::system::detail::generic::detail::uninitialized_fill_n(exec, first, n, x, - ValueTypeHasTrivialCopyConstructor()); -} // end uninitialized_fill() - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/unique.h b/compat/thrust/system/detail/generic/unique.h deleted file mode 100644 index 57e17ca..0000000 --- a/compat/thrust/system/detail/generic/unique.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template -ForwardIterator unique(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last); - - -template -ForwardIterator unique(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred); - - -template -OutputIterator unique_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output); - - -template -OutputIterator unique_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/unique.inl b/compat/thrust/system/detail/generic/unique.inl deleted file mode 100644 index 42d6b15..0000000 --- a/compat/thrust/system/detail/generic/unique.inl +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file unique.inl - * \brief Inline file for unique.h. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - ForwardIterator unique(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - return thrust::unique(exec, first, last, thrust::equal_to()); -} // end unique() - - -template - ForwardIterator unique(thrust::execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - thrust::detail::temporary_array input(exec, first, last); - - return thrust::unique_copy(exec, input.begin(), input.end(), first, binary_pred); -} // end unique() - - -template - OutputIterator unique_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output) -{ - typedef typename thrust::iterator_value::type value_type; - return thrust::unique_copy(exec, first,last,output,thrust::equal_to()); -} // end unique_copy() - - -template - OutputIterator unique_copy(thrust::execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - // empty sequence - if(first == last) - return output; - - thrust::detail::temporary_array stencil(exec, thrust::distance(first, last)); - - // mark first element in each group - stencil[0] = 1; - thrust::transform(exec, first, last - 1, first + 1, stencil.begin() + 1, thrust::detail::not2(binary_pred)); - - return thrust::copy_if(exec, first, last, stencil.begin(), output, thrust::identity()); -} // end unique_copy() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/generic/unique_by_key.h b/compat/thrust/system/detail/generic/unique_by_key.h deleted file mode 100644 index aa62f73..0000000 --- a/compat/thrust/system/detail/generic/unique_by_key.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - thrust::pair - unique_by_key(thrust::execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first); - - -template - thrust::pair - unique_by_key(thrust::execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred); - - -template - thrust::pair - unique_by_key_copy(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output); - - -template - thrust::pair - unique_by_key_copy(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred); - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/generic/unique_by_key.inl b/compat/thrust/system/detail/generic/unique_by_key.inl deleted file mode 100644 index c780fa7..0000000 --- a/compat/thrust/system/detail/generic/unique_by_key.inl +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace generic -{ - - -template - thrust::pair - unique_by_key(thrust::execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first) -{ - typedef typename thrust::iterator_traits::value_type KeyType; - return thrust::unique_by_key(exec, keys_first, keys_last, values_first, thrust::equal_to()); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key(thrust::execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::value_type InputType1; - typedef typename thrust::iterator_traits::value_type InputType2; - - ForwardIterator2 values_last = values_first + (keys_last - keys_first); - - thrust::detail::temporary_array keys(exec, keys_first, keys_last); - thrust::detail::temporary_array vals(exec, values_first, values_last); - - return thrust::unique_by_key_copy(exec, keys.begin(), keys.end(), vals.begin(), keys_first, values_first, binary_pred); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key_copy(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output) -{ - typedef typename thrust::iterator_traits::value_type KeyType; - return thrust::unique_by_key_copy(exec, keys_first, keys_last, values_first, keys_output, values_output, thrust::equal_to()); -} // end unique_by_key_copy() - - -template - thrust::pair - unique_by_key_copy(thrust::execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::difference_type difference_type; - - // empty sequence - if(keys_first == keys_last) - return thrust::make_pair(keys_output, values_output); - - difference_type n = thrust::distance(keys_first, keys_last); - - thrust::detail::temporary_array stencil(exec,n); - - // mark first element in each group - stencil[0] = 1; - thrust::transform(exec, keys_first, keys_last - 1, keys_first + 1, stencil.begin() + 1, thrust::detail::not2(binary_pred)); - - thrust::zip_iterator< thrust::tuple > result = - thrust::copy_if(exec, - thrust::make_zip_iterator(thrust::make_tuple(keys_first, values_first)), - thrust::make_zip_iterator(thrust::make_tuple(keys_first, values_first)) + n, - stencil.begin(), - thrust::make_zip_iterator(thrust::make_tuple(keys_output, values_output)), - thrust::identity()); - - difference_type output_size = result - thrust::make_zip_iterator(thrust::make_tuple(keys_output, values_output)); - - return thrust::make_pair(keys_output + output_size, values_output + output_size); -} // end unique_by_key_copy() - - -} // end namespace generic -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/decompose.h b/compat/thrust/system/detail/internal/decompose.h deleted file mode 100644 index dea806d..0000000 --- a/compat/thrust/system/detail/internal/decompose.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ - - template - class index_range - { - public: - typedef IndexType index_type; - - __host__ __device__ - index_range(index_type begin, index_type end) : m_begin(begin), m_end(end) {} - - __host__ __device__ - index_type begin(void) const { return m_begin; } - - __host__ __device__ - index_type end(void) const { return m_end; } - - __host__ __device__ - index_type size(void) const { return m_end - m_begin; } - - private: - index_type m_begin; - index_type m_end; - }; - - template - class uniform_decomposition - { - public: - typedef IndexType index_type; - typedef index_range range_type; - - uniform_decomposition(index_type N, index_type granularity, index_type max_intervals) - : m_N(N), - m_intervals((N + granularity - 1) / granularity), - m_threshold(0), - m_small_interval(granularity), - m_large_interval(0) - { - if(m_intervals > max_intervals) - { - m_small_interval = granularity * (m_intervals / max_intervals); - m_large_interval = m_small_interval + granularity; - m_threshold = m_intervals % max_intervals; - m_intervals = max_intervals; - } - } - - __host__ __device__ - index_range operator[](const index_type& i) const - { - if (i < m_threshold) - { - index_type begin = m_large_interval * i; - index_type end = begin + m_large_interval; - return range_type(begin, end); - } - else - { - index_type begin = m_large_interval * m_threshold + m_small_interval * (i - m_threshold); - index_type end = (begin + m_small_interval < m_N) ? begin + m_small_interval : m_N; - return range_type(begin, end); - } - } - - __host__ __device__ - index_type size(void) const - { - return m_intervals; - } - - private: - - index_type m_N; - index_type m_intervals; - index_type m_threshold; - index_type m_small_interval; - index_type m_large_interval; - }; - - -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/adjacent_difference.h b/compat/thrust/system/detail/internal/scalar/adjacent_difference.h deleted file mode 100644 index d1a95ae..0000000 --- a/compat/thrust/system/detail/internal/scalar/adjacent_difference.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file adjacent_difference.h - * \brief Sequential implementation of adjacent_difference. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -OutputIterator adjacent_difference(InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_traits::value_type InputType; - - if (first == last) - return result; - - InputType curr = *first; - - *result = curr; - - while (++first != last) - { - InputType next = *first; - *(++result) = binary_op(next, curr); - curr = next; - } - - return ++result; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/binary_search.h b/compat/thrust/system/detail/internal/scalar/binary_search.h deleted file mode 100644 index c3ac49f..0000000 --- a/compat/thrust/system/detail/internal/scalar/binary_search.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file binary_search.h - * \brief Sequential implementation of binary search algorithms. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -ForwardIterator lower_bound(ForwardIterator first, - ForwardIterator last, - const T& val, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - typedef typename thrust::iterator_difference::type difference_type; - - difference_type len = thrust::distance(first, last); - - while(len > 0) - { - difference_type half = len >> 1; - ForwardIterator middle = first; - - thrust::advance(middle, half); - - if(wrapped_comp(*middle, val)) - { - first = middle; - ++first; - len = len - half - 1; - } - else - { - len = half; - } - } - - return first; -} - - -template -ForwardIterator upper_bound(ForwardIterator first, - ForwardIterator last, - const T& val, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - typedef typename thrust::iterator_difference::type difference_type; - - difference_type len = thrust::distance(first, last); - - while(len > 0) - { - difference_type half = len >> 1; - ForwardIterator middle = first; - - thrust::advance(middle, half); - - if(wrapped_comp(val, *middle)) - { - len = half; - } - else - { - first = middle; - ++first; - len = len - half - 1; - } - } - - return first; -} - -template -bool binary_search(ForwardIterator first, - ForwardIterator last, - const T& val, - StrictWeakOrdering comp) -{ - ForwardIterator iter = thrust::system::detail::internal::scalar::lower_bound(first, last, val, comp); - - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - return iter != last && !wrapped_comp(val,*iter); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/copy.h b/compat/thrust/system/detail/internal/scalar/copy.h deleted file mode 100644 index 42cb385..0000000 --- a/compat/thrust/system/detail/internal/scalar/copy.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file copy.h - * \brief Sequential implementations of copy algorithms. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result); - -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result); - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/copy.inl b/compat/thrust/system/detail/internal/scalar/copy.inl deleted file mode 100644 index 8c9f5c2..0000000 --- a/compat/thrust/system/detail/internal/scalar/copy.inl +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ -namespace copy_detail -{ - - -// returns the raw pointer associated with a Pointer-like thing -template - typename thrust::detail::pointer_traits::raw_pointer - get(Pointer ptr) -{ - return thrust::detail::pointer_traits::get(ptr); -} - - -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result, - thrust::detail::true_type) // is_trivial_copy -{ - typedef typename thrust::iterator_difference::type Size; - - const Size n = last - first; - thrust::system::detail::internal::scalar::trivial_copy_n(get(&*first), n, get(&*result)); - return result + n; -} // end copy() - - -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result, - thrust::detail::false_type) // is_trivial_copy -{ - return thrust::system::detail::internal::scalar::general_copy(first,last,result); -} // end copy() - - -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result, - thrust::detail::true_type) // is_trivial_copy -{ - thrust::system::detail::internal::scalar::trivial_copy_n(get(&*first), n, get(&*result)); - return result + n; -} // end copy_n() - - -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result, - thrust::detail::false_type) // is_trivial_copy -{ - return thrust::system::detail::internal::scalar::general_copy_n(first,n,result); -} // end copy_n() - -} // end namespace copy_detail - - -template - OutputIterator copy(InputIterator first, - InputIterator last, - OutputIterator result) -{ - return thrust::system::detail::internal::scalar::copy_detail::copy(first, last, result, - typename thrust::detail::dispatch::is_trivial_copy::type()); -} // end copy() - - -template - OutputIterator copy_n(InputIterator first, - Size n, - OutputIterator result) -{ - return thrust::system::detail::internal::scalar::copy_detail::copy_n(first, n, result, - typename thrust::detail::dispatch::is_trivial_copy::type()); -} // end copy_n() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/copy_backward.h b/compat/thrust/system/detail/internal/scalar/copy_backward.h deleted file mode 100644 index 36f8f66..0000000 --- a/compat/thrust/system/detail/internal/scalar/copy_backward.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, - BidirectionalIterator1 last, - BidirectionalIterator2 result) -{ - while (first != last) - { - --last; - --result; - *result = *last; - } - - return result; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/copy_if.h b/compat/thrust/system/detail/internal/scalar/copy_if.h deleted file mode 100644 index 67f9402..0000000 --- a/compat/thrust/system/detail/internal/scalar/copy_if.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file copy_if.h - * \brief Sequential implementation of copy_if. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - thrust::detail::host_function wrapped_pred(pred); - - while(first != last) - { - if(wrapped_pred(*stencil)) - { - *result = *first; - ++result; - } // end if - - ++first; - ++stencil; - } // end while - - return result; -} // end copy_if() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/extrema.h b/compat/thrust/system/detail/internal/scalar/extrema.h deleted file mode 100644 index ebea756..0000000 --- a/compat/thrust/system/detail/internal/scalar/extrema.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file extrema.h - * \brief Sequential implementations of extrema functions. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -ForwardIterator min_element(ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // wrap comp - thrust::detail::host_function< - BinaryPredicate, - bool - > wrapped_comp(comp); - - ForwardIterator imin = first; - - for (; first != last; first++) - { - if (wrapped_comp(*first, *imin)) - { - imin = first; - } - } - - return imin; -} - - -template -ForwardIterator max_element(ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // wrap comp - thrust::detail::host_function< - BinaryPredicate, - bool - > wrapped_comp(comp); - - ForwardIterator imax = first; - - for (; first != last; first++) - { - if (wrapped_comp(*imax, *first)) - { - imax = first; - } - } - - return imax; -} - - -template -thrust::pair minmax_element(ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // wrap comp - thrust::detail::host_function< - BinaryPredicate, - bool - > wrapped_comp(comp); - - ForwardIterator imin = first; - ForwardIterator imax = first; - - for (; first != last; first++) - { - if (wrapped_comp(*first, *imin)) - { - imin = first; - } - - if (wrapped_comp(*imax, *first)) - { - imax = first; - } - } - - return thrust::make_pair(imin, imax); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/find.h b/compat/thrust/system/detail/internal/scalar/find.h deleted file mode 100644 index 6b25021..0000000 --- a/compat/thrust/system/detail/internal/scalar/find.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file find.h - * \brief Sequential implementation of find_if. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -InputIterator find_if(InputIterator first, - InputIterator last, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - while(first != last) - { - if (wrapped_pred(*first)) - return first; - - ++first; - } - - // return first so zip_iterator works correctly - return first; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/for_each.h b/compat/thrust/system/detail/internal/scalar/for_each.h deleted file mode 100644 index 4e31d91..0000000 --- a/compat/thrust/system/detail/internal/scalar/for_each.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.h - * \brief Sequential implementations of for_each functions. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -InputIterator for_each(InputIterator first, - InputIterator last, - UnaryFunction f) -{ - // wrap f - thrust::detail::host_function< - UnaryFunction, - void - > wrapped_f(f); - - for(; first != last; ++first) - { - wrapped_f(*first); - } - - return first; -} // end for_each() - -template -InputIterator for_each_n(InputIterator first, - Size n, - UnaryFunction f) -{ - // wrap f - thrust::detail::host_function< - UnaryFunction, - void - > wrapped_f(f); - - for(Size i = 0; i != n; i++) - { - // we can dereference an OutputIterator if f does not - // try to use the reference for anything besides assignment - wrapped_f(*first); - ++first; - } - - return first; -} // end for_each_n() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/general_copy.h b/compat/thrust/system/detail/internal/scalar/general_copy.h deleted file mode 100644 index aae061d..0000000 --- a/compat/thrust/system/detail/internal/scalar/general_copy.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file general_copy.h - * \brief Sequential copy algorithms for general iterators. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator general_copy(InputIterator first, - InputIterator last, - OutputIterator result) -{ - for(; first != last; ++first, ++result) - *result = *first; - return result; -} // end general_copy() - - -template - OutputIterator general_copy_n(InputIterator first, - Size n, - OutputIterator result) -{ - for(; n > Size(0); ++first, ++result, --n) - *result = *first; - return result; -} // end general_copy_n() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/insertion_sort.h b/compat/thrust/system/detail/internal/scalar/insertion_sort.h deleted file mode 100644 index 5949ce7..0000000 --- a/compat/thrust/system/detail/internal/scalar/insertion_sort.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -void insertion_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_value::type value_type; - - if (first == last) return; - - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - for(RandomAccessIterator i = first + 1; i != last; ++i) - { - value_type tmp = *i; - - if (wrapped_comp(tmp, *first)) - { - // tmp is the smallest value encountered so far - thrust::system::detail::internal::scalar::copy_backward(first, i, i + 1); - - *first = tmp; - } - else - { - // tmp is not the smallest value, can avoid checking for j == first - RandomAccessIterator j = i; - RandomAccessIterator k = i - 1; - - while(wrapped_comp(tmp, *k)) - { - *j = *k; - j = k; - --k; - } - - *j = tmp; - } - } -} - -template -void insertion_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_value::type value_type1; - typedef typename thrust::iterator_value::type value_type2; - - if (first1 == last1) return; - - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - RandomAccessIterator1 i1 = first1 + 1; - RandomAccessIterator2 i2 = first2 + 1; - - for(; i1 != last1; ++i1, ++i2) - { - value_type1 tmp1 = *i1; - value_type2 tmp2 = *i2; - - if (wrapped_comp(tmp1, *first1)) - { - // tmp is the smallest value encountered so far - thrust::system::detail::internal::scalar::copy_backward(first1, i1, i1 + 1); - thrust::system::detail::internal::scalar::copy_backward(first2, i2, i2 + 1); - - *first1 = tmp1; - *first2 = tmp2; - } - else - { - // tmp is not the smallest value, can avoid checking for j == first - RandomAccessIterator1 j1 = i1; - RandomAccessIterator1 k1 = i1 - 1; - - RandomAccessIterator2 j2 = i2; - RandomAccessIterator2 k2 = i2 - 1; - - while(wrapped_comp(tmp1, *k1)) - { - *j1 = *k1; - *j2 = *k2; - - j1 = k1; - j2 = k2; - - --k1; - --k2; - } - - *j1 = tmp1; - *j2 = tmp2; - } - } -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/merge.h b/compat/thrust/system/detail/internal/scalar/merge.h deleted file mode 100644 index c02fca4..0000000 --- a/compat/thrust/system/detail/internal/scalar/merge.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file merge.h - * \brief Sequential implementation of merge algorithms. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -OutputIterator merge(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - -template -thrust::pair - merge_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp); - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/merge.inl b/compat/thrust/system/detail/internal/scalar/merge.inl deleted file mode 100644 index a7c2a39..0000000 --- a/compat/thrust/system/detail/internal/scalar/merge.inl +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -OutputIterator merge(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - while(first1 != last1 && first2 != last2) - { - if(wrapped_comp(*first2, *first1)) - { - *result = *first2; - ++first2; - } // end if - else - { - *result = *first1; - ++first1; - } // end else - - ++result; - } // end while - - return thrust::system::detail::internal::scalar::copy(first2, last2, thrust::system::detail::internal::scalar::copy(first1, last1, result)); -} // end merge() - - -template -thrust::pair - merge_by_key(InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - while(keys_first1 != keys_last1 && keys_first2 != keys_last2) - { - if(!wrapped_comp(*keys_first2, *keys_first1)) - { - // *keys_first1 <= *keys_first2 - *keys_result = *keys_first1; - *values_result = *values_first1; - ++keys_first1; - ++values_first1; - } - else - { - // *keys_first1 > keys_first2 - *keys_result = *keys_first2; - *values_result = *values_first2; - ++keys_first2; - ++values_first2; - } - - ++keys_result; - ++values_result; - } - - while(keys_first1 != keys_last1) - { - *keys_result = *keys_first1; - *values_result = *values_first1; - ++keys_first1; - ++values_first1; - ++keys_result; - ++values_result; - } - - while(keys_first2 != keys_last2) - { - *keys_result = *keys_first2; - *values_result = *values_first2; - ++keys_first2; - ++values_first2; - ++keys_result; - ++values_result; - } - - return thrust::make_pair(keys_result, values_result); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/partition.h b/compat/thrust/system/detail/internal/scalar/partition.h deleted file mode 100644 index 7ba677e..0000000 --- a/compat/thrust/system/detail/internal/scalar/partition.h +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file partition.h - * \brief Sequential implementations of partition functions. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -void iter_swap(ForwardIterator1 iter1, ForwardIterator2 iter2) -{ - // XXX this isn't correct because it doesn't use thrust::swap - using namespace thrust::detail; - - typedef typename thrust::iterator_value::type T; - - T temp = *iter1; - *iter1 = *iter2; - *iter2 = temp; -} - -template - ForwardIterator partition(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - if (first == last) - return first; - - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - while (wrapped_pred(*first)) - { - if (++first == last) - return first; - } - - ForwardIterator next = first; - - while (++next != last) - { - if (wrapped_pred(*next)) - { - iter_swap(first, next); - ++first; - } - } - - return first; -} - -template - ForwardIterator stable_partition(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - // XXX the type of exec should be: - // typedef decltype(select_system(first, last)) system; - typedef typename thrust::iterator_system::type ExecutionPolicy; - typedef typename thrust::iterator_value::type T; - - typedef thrust::detail::temporary_array TempRange; - typedef typename TempRange::iterator TempIterator; - - // XXX presumes ExecutionPolicy is default constructible - ExecutionPolicy exec; - TempRange temp(exec, first, last); - - for(TempIterator iter = temp.begin(); iter != temp.end(); ++iter) - { - if (wrapped_pred(*iter)) - { - *first = *iter; - ++first; - } - } - - ForwardIterator middle = first; - - for(TempIterator iter = temp.begin(); iter != temp.end(); ++iter) - { - if (!wrapped_pred(*iter)) - { - *first = *iter; - ++first; - } - } - - return middle; -} - -template - ForwardIterator stable_partition(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - // XXX the type of exec should be: - // typedef decltype(select_system(first, stencil)) system; - typedef typename thrust::iterator_system::type ExecutionPolicy; - typedef typename thrust::iterator_value::type T; - - typedef thrust::detail::temporary_array TempRange; - typedef typename TempRange::iterator TempIterator; - - // XXX presumes ExecutionPolicy is default constructible - ExecutionPolicy exec; - TempRange temp(exec, first, last); - - InputIterator stencil_iter = stencil; - for(TempIterator iter = temp.begin(); iter != temp.end(); ++iter, ++stencil_iter) - { - if (wrapped_pred(*stencil_iter)) - { - *first = *iter; - ++first; - } - } - - ForwardIterator middle = first; - stencil_iter = stencil; - - for(TempIterator iter = temp.begin(); iter != temp.end(); ++iter, ++stencil_iter) - { - if (!wrapped_pred(*stencil_iter)) - { - *first = *iter; - ++first; - } - } - - return middle; -} - -template - thrust::pair - stable_partition_copy(InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - for(; first != last; ++first) - { - if(wrapped_pred(*first)) - { - *out_true = *first; - ++out_true; - } // end if - else - { - *out_false = *first; - ++out_false; - } // end else - } - - return thrust::make_pair(out_true, out_false); -} - -template - thrust::pair - stable_partition_copy(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - for(; first != last; ++first, ++stencil) - { - if(wrapped_pred(*stencil)) - { - *out_true = *first; - ++out_true; - } // end if - else - { - *out_false = *first; - ++out_false; - } // end else - } - - return thrust::make_pair(out_true, out_false); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/reduce.h b/compat/thrust/system/detail/internal/scalar/reduce.h deleted file mode 100644 index 7ad430e..0000000 --- a/compat/thrust/system/detail/internal/scalar/reduce.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief Sequential implementation of reduce algorithm. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputType reduce(InputIterator begin, - InputIterator end, - OutputType init, - BinaryFunction binary_op) -{ - // wrap binary_op - thrust::detail::host_function< - BinaryFunction, - OutputType - > wrapped_binary_op(binary_op); - - // initialize the result - OutputType result = init; - - while(begin != end) - { - result = wrapped_binary_op(result, *begin); - ++begin; - } // end while - - return result; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/reduce_by_key.h b/compat/thrust/system/detail/internal/scalar/reduce_by_key.h deleted file mode 100644 index eeacb9d..0000000 --- a/compat/thrust/system/detail/internal/scalar/reduce_by_key.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - thrust::pair - reduce_by_key(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_traits::value_type InputKeyType; - typedef typename thrust::iterator_traits::value_type InputValueType; - - typedef typename thrust::detail::intermediate_type_from_function_and_iterators< - InputIterator2, - OutputIterator2, - BinaryFunction - >::type TemporaryType; - - if(keys_first != keys_last) - { - InputKeyType temp_key = *keys_first; - TemporaryType temp_value = *values_first; - - for(++keys_first, ++values_first; - keys_first != keys_last; - ++keys_first, ++values_first) - { - InputKeyType key = *keys_first; - InputValueType value = *values_first; - - if (binary_pred(temp_key, key)) - { - temp_value = binary_op(temp_value, value); - } - else - { - *keys_output = temp_key; - *values_output = temp_value; - - ++keys_output; - ++values_output; - - temp_key = key; - temp_value = value; - } - } - - *keys_output = temp_key; - *values_output = temp_value; - - ++keys_output; - ++values_output; - } - - return thrust::make_pair(keys_output, values_output); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/remove.h b/compat/thrust/system/detail/internal/scalar/remove.h deleted file mode 100644 index 2360019..0000000 --- a/compat/thrust/system/detail/internal/scalar/remove.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file remove.h - * \brief Sequential implementations of remove functions. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - ForwardIterator remove_if(ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - // advance iterators until wrapped_pred(*first) is true or we reach the end of input - while(first != last && !wrapped_pred(*first)) - ++first; - - if(first == last) - return first; - - // result always trails first - ForwardIterator result = first; - - ++first; - - while(first != last) - { - if(!wrapped_pred(*first)) - { - *result = *first; - ++result; - } - ++first; - } - - return result; -} - - -template - ForwardIterator remove_if(ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - // advance iterators until wrapped_pred(*stencil) is true or we reach the end of input - while(first != last && !wrapped_pred(*stencil)) - { - ++first; - ++stencil; - } - - if(first == last) - return first; - - // result always trails first - ForwardIterator result = first; - - ++first; - ++stencil; - - while(first != last) - { - if(!wrapped_pred(*stencil)) - { - *result = *first; - ++result; - } - ++first; - ++stencil; - } - - return result; -} - - -template - OutputIterator remove_copy_if(InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - while (first != last) - { - if (!wrapped_pred(*first)) - { - *result = *first; - ++result; - } - - ++first; - } - - return result; -} - -template - OutputIterator remove_copy_if(InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - // wrap pred - thrust::detail::host_function< - Predicate, - bool - > wrapped_pred(pred); - - while (first != last) - { - if (!wrapped_pred(*stencil)) - { - *result = *first; - ++result; - } - - ++first; - ++stencil; - } - - return result; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/scan.h b/compat/thrust/system/detail/internal/scalar/scan.h deleted file mode 100644 index 8f41150..0000000 --- a/compat/thrust/system/detail/internal/scalar/scan.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.h - * \brief Sequential implementations of scan functions. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - using namespace thrust::detail; - - typedef typename eval_if< - has_result_type::value, - result_type, - eval_if< - is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - // wrap binary_op - thrust::detail::host_function< - BinaryFunction, - ValueType - > wrapped_binary_op(binary_op); - - if(first != last) - { - ValueType sum = *first; - - *result = sum; - - for(++first, ++result; first != last; ++first, ++result) - *result = sum = wrapped_binary_op(sum,*first); - } - - return result; -} - - -template - OutputIterator exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - using namespace thrust::detail; - - typedef typename eval_if< - has_result_type::value, - result_type, - eval_if< - is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - if(first != last) - { - ValueType tmp = *first; // temporary value allows in-situ scan - ValueType sum = init; - - *result = sum; - sum = binary_op(sum, tmp); - - for(++first, ++result; first != last; ++first, ++result) - { - tmp = *first; - *result = sum; - sum = binary_op(sum, tmp); - } - } - - return result; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/scan_by_key.h b/compat/thrust/system/detail/internal/scalar/scan_by_key.h deleted file mode 100644 index a31fc60..0000000 --- a/compat/thrust/system/detail/internal/scalar/scan_by_key.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan_by_key.h - * \brief Sequential implementation of scan_by_key functions. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator inclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - using namespace thrust::detail; - - typedef typename thrust::iterator_traits::value_type KeyType; - typedef typename thrust::iterator_traits::value_type ValueType; - - // wrap binary_op - thrust::detail::host_function< - BinaryFunction, - ValueType - > wrapped_binary_op(binary_op); - - if(first1 != last1) - { - KeyType prev_key = *first1; - ValueType prev_value = *first2; - - *result = prev_value; - - for(++first1, ++first2, ++result; - first1 != last1; - ++first1, ++first2, ++result) - { - KeyType key = *first1; - - if (binary_pred(prev_key, key)) - *result = prev_value = wrapped_binary_op(prev_value,*first2); - else - *result = prev_value = *first2; - - prev_key = key; - } - } - - return result; -} - - -template - OutputIterator exclusive_scan_by_key(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - T init, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - using namespace thrust::detail; - - typedef typename thrust::iterator_traits::value_type KeyType; - typedef typename thrust::iterator_traits::value_type ValueType; - - if(first1 != last1) - { - KeyType temp_key = *first1; - ValueType temp_value = *first2; - - ValueType next = init; - - // first one is init - *result = next; - - next = binary_op(next, temp_value); - - for(++first1, ++first2, ++result; - first1 != last1; - ++first1, ++first2, ++result) - { - KeyType key = *first1; - - // use temp to permit in-place scans - temp_value = *first2; - - if (!binary_pred(temp_key, key)) - next = init; // reset sum - - *result = next; - next = binary_op(next, temp_value); - - temp_key = key; - } - } - - return result; -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/set_operations.h b/compat/thrust/system/detail/internal/scalar/set_operations.h deleted file mode 100644 index f85b510..0000000 --- a/compat/thrust/system/detail/internal/scalar/set_operations.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file set_operations.h - * \brief Sequential implementation of set operation functions. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator set_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - while(first1 != last1 && first2 != last2) - { - if(wrapped_comp(*first1,*first2)) - { - *result = *first1; - ++first1; - ++result; - } // end if - else if(wrapped_comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - ++first1; - ++first2; - } // end else - } // end while - - return scalar::copy(first1, last1, result); -} // end set_difference() - - -template - OutputIterator set_intersection(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - while(first1 != last1 && first2 != last2) - { - if(wrapped_comp(*first1,*first2)) - { - ++first1; - } // end if - else if(wrapped_comp(*first2,*first1)) - { - ++first2; - } // end else if - else - { - *result = *first1; - ++first1; - ++first2; - ++result; - } // end else - } // end while - - return result; -} // end set_intersection() - - -template - OutputIterator set_symmetric_difference(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - while(first1 != last1 && first2 != last2) - { - if(wrapped_comp(*first1,*first2)) - { - *result = *first1; - ++first1; - ++result; - } // end if - else if(wrapped_comp(*first2,*first1)) - { - *result = *first2; - ++first2; - ++result; - } // end else if - else - { - ++first1; - ++first2; - } // end else - } // end while - - return scalar::copy(first2, last2, scalar::copy(first1, last1, result)); -} // end set_symmetric_difference() - - -template - OutputIterator set_union(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - // wrap comp - thrust::detail::host_function< - StrictWeakOrdering, - bool - > wrapped_comp(comp); - - while(first1 != last1 && first2 != last2) - { - if(wrapped_comp(*first1,*first2)) - { - *result = *first1; - ++first1; - } // end if - else if(wrapped_comp(*first2,*first1)) - { - *result = *first2; - ++first2; - } // end else if - else - { - *result = *first1; - ++first1; - ++first2; - } // end else - - ++result; - } // end while - - return scalar::copy(first2, last2, scalar::copy(first1, last1, result)); -} // end set_union() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/sort.h b/compat/thrust/system/detail/internal/scalar/sort.h deleted file mode 100644 index 9e465c8..0000000 --- a/compat/thrust/system/detail/internal/scalar/sort.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file sort.h - * \brief Sequential implementations of sort algorithms. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - -template -void stable_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp); - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/sort.inl b/compat/thrust/system/detail/internal/scalar/sort.inl deleted file mode 100644 index c6ed273..0000000 --- a/compat/thrust/system/detail/internal/scalar/sort.inl +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ -namespace sort_detail -{ - -//////////////////// -// Primitive Sort // -//////////////////// - -template -void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp, - thrust::detail::true_type) -{ - thrust::system::detail::internal::scalar::stable_primitive_sort(first, last); - - // if comp is greater then reverse the keys - typedef typename thrust::iterator_traits::value_type KeyType; - const static bool reverse = thrust::detail::is_same >::value; - - if (reverse) - thrust::reverse(first, last); -} - -template -void stable_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp, - thrust::detail::true_type) -{ - // if comp is greater then reverse the keys and values - typedef typename thrust::iterator_traits::value_type KeyType; - const static bool reverse = thrust::detail::is_same >::value; - - // note, we also have to reverse the (unordered) input to preserve stability - if (reverse) - { - thrust::reverse(first1, last1); - thrust::reverse(first2, first2 + (last1 - first1)); - } - - thrust::system::detail::internal::scalar::stable_primitive_sort_by_key(first1, last1, first2); - - if (reverse) - { - thrust::reverse(first1, last1); - thrust::reverse(first2, first2 + (last1 - first1)); - } -} - -//////////////// -// Merge Sort // -//////////////// - -template -void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp, - thrust::detail::false_type) -{ - thrust::system::detail::internal::scalar::stable_merge_sort(first, last, comp); -} - -template -void stable_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp, - thrust::detail::false_type) -{ - thrust::system::detail::internal::scalar::stable_merge_sort_by_key(first1, last1, first2, comp); -} - - -} // end namespace sort_detail - -template -void stable_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_traits::value_type KeyType; - static const bool use_primitive_sort = thrust::detail::is_arithmetic::value && - (thrust::detail::is_same >::value || - thrust::detail::is_same >::value); - - // supress unused variable warning - (void) use_primitive_sort; - - thrust::system::detail::internal::scalar::sort_detail::stable_sort - (first, last, comp, - thrust::detail::integral_constant()); -} - -template -void stable_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_traits::value_type KeyType; - static const bool use_primitive_sort = thrust::detail::is_arithmetic::value && - (thrust::detail::is_same >::value || - thrust::detail::is_same >::value); - - // supress unused variable warning - (void) use_primitive_sort; - - thrust::system::detail::internal::scalar::sort_detail::stable_sort_by_key - (first1, last1, first2, comp, - thrust::detail::integral_constant()); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/stable_merge_sort.h b/compat/thrust/system/detail/internal/scalar/stable_merge_sort.h deleted file mode 100644 index f68242c..0000000 --- a/compat/thrust/system/detail/internal/scalar/stable_merge_sort.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file stable_merge_sort.h - * \brief Sequential implementation of merge sort. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace cpp -{ -namespace detail -{ - -template -void stable_merge_sort(RandomAccessIterator begin, - RandomAccessIterator end, - StrictWeakOrdering comp); - -template -void stable_merge_sort_by_key(RandomAccessIterator1 keys_begin, - RandomAccessIterator1 keys_end, - RandomAccessIterator2 values_begin, - StrictWeakOrdering comp); - -} // end namespace detail -} // end namespace cpp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/stable_merge_sort.inl b/compat/thrust/system/detail/internal/scalar/stable_merge_sort.inl deleted file mode 100644 index 41d320c..0000000 --- a/compat/thrust/system/detail/internal/scalar/stable_merge_sort.inl +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ -namespace detail -{ - -template -void inplace_merge(RandomAccessIterator first, - RandomAccessIterator middle, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // XXX the type of exec should be: - // typedef decltype(select_system(first, middle, last)) DerivedPolicy; - typedef typename thrust::iterator_system::type DerivedPolicy; - typedef typename thrust::iterator_value::type value_type; - - // XXX assumes DerivedPolicy is default constructible - // XXX find a way to get a stateful execution policy into this function - // or simply pass scratch space - DerivedPolicy exec; - thrust::detail::temporary_array a(exec, first, middle); - thrust::detail::temporary_array b(exec, middle, last); - - thrust::system::detail::internal::scalar::merge(a.begin(), a.end(), b.begin(), b.end(), first, comp); -} - -template -void inplace_merge_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 middle1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp) -{ - // XXX the type of exec should be: - // typedef decltype(select_system(first1, middle1, last1, first2)) DerivedPolicy; - typedef typename thrust::iterator_system::type DerivedPolicy; - typedef typename thrust::iterator_value::type value_type1; - typedef typename thrust::iterator_value::type value_type2; - - RandomAccessIterator2 middle2 = first2 + (middle1 - first1); - RandomAccessIterator2 last2 = first2 + (last1 - first1); - - // XXX assumes DerivedPolicy is default constructible - // XXX find a way to get a stateful exec into this function - // or simply pass scratch space - DerivedPolicy exec; - thrust::detail::temporary_array lhs1(exec, first1, middle1); - thrust::detail::temporary_array rhs1(exec, middle1, last1); - thrust::detail::temporary_array lhs2(exec, first2, middle2); - thrust::detail::temporary_array rhs2(exec, middle2, last2); - - thrust::system::detail::internal::scalar::merge_by_key - (lhs1.begin(), lhs1.end(), rhs1.begin(), rhs1.end(), - lhs2.begin(), rhs2.begin(), - first1, first2, comp); -} - -} // end namespace detail - -////////////// -// Key Sort // -////////////// - -template -void stable_merge_sort(RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - if (last - first < 32) - { - thrust::system::detail::internal::scalar::insertion_sort(first, last, comp); - } - else - { - RandomAccessIterator middle = first + (last - first) / 2; - - thrust::system::detail::internal::scalar::stable_merge_sort(first, middle, comp); - thrust::system::detail::internal::scalar::stable_merge_sort(middle, last, comp); - detail::inplace_merge(first, middle, last, comp); - } -} - - -//////////////////// -// Key-Value Sort // -//////////////////// - -template -void stable_merge_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp) -{ - if (last1 - first1 <= 32) - { - thrust::system::detail::internal::scalar::insertion_sort_by_key(first1, last1, first2, comp); - } - else - { - RandomAccessIterator1 middle1 = first1 + (last1 - first1) / 2; - RandomAccessIterator2 middle2 = first2 + (last1 - first1) / 2; - - thrust::system::detail::internal::scalar::stable_merge_sort_by_key(first1, middle1, first2, comp); - thrust::system::detail::internal::scalar::stable_merge_sort_by_key(middle1, last1, middle2, comp); - detail::inplace_merge_by_key(first1, middle1, last1, first2, comp); - } -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/stable_primitive_sort.h b/compat/thrust/system/detail/internal/scalar/stable_primitive_sort.h deleted file mode 100644 index f37bf27..0000000 --- a/compat/thrust/system/detail/internal/scalar/stable_primitive_sort.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -void stable_primitive_sort(RandomAccessIterator first, - RandomAccessIterator last); - -template -void stable_primitive_sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first); - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/stable_primitive_sort.inl b/compat/thrust/system/detail/internal/scalar/stable_primitive_sort.inl deleted file mode 100644 index c22b15c..0000000 --- a/compat/thrust/system/detail/internal/scalar/stable_primitive_sort.inl +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ -namespace stable_primitive_sort_detail -{ - - -template - struct enable_if_bool_sort - : thrust::detail::enable_if< - thrust::detail::is_same< - bool, - typename thrust::iterator_value::type - >::value - > -{}; - - -template - struct disable_if_bool_sort - : thrust::detail::disable_if< - thrust::detail::is_same< - bool, - typename thrust::iterator_value::type - >::value - > -{}; - - - -template - typename enable_if_bool_sort::type - stable_primitive_sort(RandomAccessIterator first, RandomAccessIterator last) -{ - // use stable_partition if we're sorting bool - // stable_partition puts true values first, so we need to logical_not - scalar::stable_partition(first, last, thrust::logical_not()); -} - - -template - typename disable_if_bool_sort::type - stable_primitive_sort(RandomAccessIterator first, RandomAccessIterator last) -{ - // call stable_radix_sort - scalar::stable_radix_sort(first,last); -} - - -struct logical_not_first -{ - template - __host__ __device__ - bool operator()(Tuple t) - { - return !thrust::get<0>(t); - } -}; - - -template - typename enable_if_bool_sort::type - stable_primitive_sort_by_key(RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - // use stable_partition if we're sorting bool - // stable_partition puts true values first, so we need to logical_not - scalar::stable_partition(thrust::make_zip_iterator(thrust::make_tuple(keys_first, values_first)), - thrust::make_zip_iterator(thrust::make_tuple(keys_last, values_first)), - logical_not_first()); -} - - -template - typename disable_if_bool_sort::type - stable_primitive_sort_by_key(RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - // call stable_radix_sort_by_key - scalar::stable_radix_sort_by_key(keys_first, keys_last, values_first); -} - - -} - -template -void stable_primitive_sort(RandomAccessIterator first, - RandomAccessIterator last) -{ - scalar::stable_primitive_sort_detail::stable_primitive_sort(first,last); -} - -template -void stable_primitive_sort_by_key(RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first) -{ - scalar::stable_primitive_sort_detail::stable_primitive_sort_by_key(keys_first, keys_last, values_first); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/stable_radix_sort.h b/compat/thrust/system/detail/internal/scalar/stable_radix_sort.h deleted file mode 100644 index f2af222..0000000 --- a/compat/thrust/system/detail/internal/scalar/stable_radix_sort.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file stable_radix_sort.h - * \brief Sequential implementation of radix sort. - */ - -#pragma once - -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template -void stable_radix_sort(RandomAccessIterator begin, - RandomAccessIterator end); - -template -void stable_radix_sort_by_key(RandomAccessIterator1 keys_begin, - RandomAccessIterator1 keys_end, - RandomAccessIterator2 values_begin); - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/detail/internal/scalar/stable_radix_sort.inl b/compat/thrust/system/detail/internal/scalar/stable_radix_sort.inl deleted file mode 100644 index 98846ab..0000000 --- a/compat/thrust/system/detail/internal/scalar/stable_radix_sort.inl +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ -namespace detail -{ - -template -struct RadixEncoder : public thrust::identity -{}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - unsigned char operator()(char x) const - { - if(std::numeric_limits::is_signed) - return x ^ static_cast(1) << (8 * sizeof(unsigned char) - 1); - else - return x; - } -}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - unsigned char operator()(signed char x) const - { - return x ^ static_cast(1) << (8 * sizeof(unsigned char) - 1); - } -}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - unsigned short operator()(short x) const - { - return x ^ static_cast(1) << (8 * sizeof(unsigned short) - 1); - } -}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - unsigned long operator()(long x) const - { - return x ^ static_cast(1) << (8 * sizeof(unsigned int) - 1); - } -}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - unsigned long operator()(long x) const - { - return x ^ static_cast(1) << (8 * sizeof(unsigned long) - 1); - } -}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - unsigned long long operator()(long long x) const - { - return x ^ static_cast(1) << (8 * sizeof(unsigned long long) - 1); - } -}; - -// ideally we'd use uint32 here and uint64 below -template <> -struct RadixEncoder : public thrust::unary_function -{ - thrust::detail::uint32_t operator()(float x) const - { - union { float f; thrust::detail::uint32_t i; } u; - u.f = x; - thrust::detail::uint32_t mask = -static_cast(u.i >> 31) | (static_cast(1) << 31); - return u.i ^ mask; - } -}; - -template <> -struct RadixEncoder : public thrust::unary_function -{ - thrust::detail::uint64_t operator()(double x) const - { - union { double f; thrust::detail::uint64_t i; } u; - u.f = x; - thrust::detail::uint64_t mask = -static_cast(u.i >> 63) | (static_cast(1) << 63); - return u.i ^ mask; - } -}; - - -template -void radix_sort(RandomAccessIterator1 keys1, - RandomAccessIterator2 keys2, - RandomAccessIterator3 vals1, - RandomAccessIterator4 vals2, - const size_t N) -{ - typedef typename thrust::iterator_value::type KeyType; - - typedef RadixEncoder Encoder; - typedef typename Encoder::result_type EncodedType; - - static const unsigned int NumHistograms = (8 * sizeof(EncodedType) + (RadixBits - 1)) / RadixBits; - static const unsigned int HistogramSize = 1 << RadixBits; - - static const EncodedType BitMask = static_cast((1 << RadixBits) - 1); - - Encoder encode; - - // storage for histograms - size_t histograms[NumHistograms][HistogramSize] = {{0}}; - - // see which passes can be eliminated - bool skip_shuffle[NumHistograms] = {false}; - - // false if most recent data is stored in (keys1,vals1) - bool flip = false; - - // compute histograms - for (size_t i = 0; i < N; i++) - { - const EncodedType x = encode(keys1[i]); - - for (unsigned int j = 0; j < NumHistograms; j++) - { - const EncodedType BitShift = RadixBits * j; - histograms[j][(x >> BitShift) & BitMask]++; - } - } - - // scan histograms - for (unsigned int i = 0; i < NumHistograms; i++) - { - size_t sum = 0; - - for (unsigned int j = 0; j < HistogramSize; j++) - { - size_t bin = histograms[i][j]; - - if (bin == N) - skip_shuffle[i] = true; - - histograms[i][j] = sum; - - sum = sum + bin; - } - } - - // shuffle keys and (optionally) values - for (unsigned int i = 0; i < NumHistograms; i++) - { - const EncodedType BitShift = static_cast(RadixBits * i); - - if (!skip_shuffle[i]) - { - if (flip) - { - for (size_t j = 0; j < N; j++) - { - const EncodedType x = encode(keys2[j]); - size_t position = histograms[i][(x >> BitShift) & BitMask]++; - - RandomAccessIterator1 temp_keys1 = keys1; - temp_keys1 += position; - - RandomAccessIterator2 temp_keys2 = keys2; - temp_keys2 += j; - - // keys1[position] = keys2[j] - *temp_keys1 = *temp_keys2; - - if (HasValues) - { - RandomAccessIterator3 temp_vals1 = vals1; - temp_vals1 += position; - - RandomAccessIterator4 temp_vals2 = vals2; - temp_vals2 += j; - - // vals1[position] = vals2[j] - *temp_vals1 = *temp_vals2; - } - } - } - else - { - for (size_t j = 0; j < N; j++) - { - const EncodedType x = encode(keys1[j]); - size_t position = histograms[i][(x >> BitShift) & BitMask]++; - - RandomAccessIterator1 temp_keys1 = keys1; - temp_keys1 += j; - - RandomAccessIterator2 temp_keys2 = keys2; - temp_keys2 += position; - - // keys2[position] = keys1[j]; - *temp_keys2 = *temp_keys1; - - if (HasValues) - { - RandomAccessIterator3 temp_vals1 = vals1; - temp_vals1 += j; - - RandomAccessIterator4 temp_vals2 = vals2; - temp_vals2 += position; - - // vals2[position] = vals1[j] - *temp_vals2 = *temp_vals1; - } - } - } - - flip = (flip) ? false : true; - } - } - - // ensure final values are in (keys1,vals1) - if (flip) - { - thrust::copy(keys2, keys2 + N, keys1); - if (HasValues) - thrust::copy(vals2, vals2 + N, vals1); - } -} - - -// Select best radix sort parameters based on sizeof(T) and input size -// These particular values were determined through empirical testing on a Core i7 950 CPU -template -struct radix_sort_dispatcher -{ -}; - -template <> -struct radix_sort_dispatcher<1> -{ - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, const size_t N) - { - detail::radix_sort<8,false>(keys1, keys2, static_cast(0), static_cast(0), N); - } - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, RandomAccessIterator3 vals1, RandomAccessIterator4 vals2, const size_t N) - { - detail::radix_sort<8,true>(keys1, keys2, vals1, vals2, N); - } -}; - -template <> -struct radix_sort_dispatcher<2> -{ - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, const size_t N) - { - if (N < (1 << 16)) - detail::radix_sort<8,false>(keys1, keys2, static_cast(0), static_cast(0), N); - else - detail::radix_sort<16,false>(keys1, keys2, static_cast(0), static_cast(0), N); - } - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, RandomAccessIterator3 vals1, RandomAccessIterator4 vals2, const size_t N) - { - if (N < (1 << 15)) - detail::radix_sort<8,true>(keys1, keys2, vals1, vals2, N); - else - detail::radix_sort<16,true>(keys1, keys2, vals1, vals2, N); - } -}; - -template <> -struct radix_sort_dispatcher<4> -{ - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, const size_t N) - { - if (N < (1 << 22)) - detail::radix_sort<8,false>(keys1, keys2, static_cast(0), static_cast(0), N); - else - detail::radix_sort<4,false>(keys1, keys2, static_cast(0), static_cast(0), N); - } - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, RandomAccessIterator3 vals1, RandomAccessIterator4 vals2, const size_t N) - { - if (N < (1 << 22)) - detail::radix_sort<8,true>(keys1, keys2, vals1, vals2, N); - else - detail::radix_sort<3,true>(keys1, keys2, vals1, vals2, N); - } -}; - -template <> -struct radix_sort_dispatcher<8> -{ - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, const size_t N) - { - if (N < (1 << 21)) - detail::radix_sort<8,false>(keys1, keys2, static_cast(0), static_cast(0), N); - else - detail::radix_sort<4,false>(keys1, keys2, static_cast(0), static_cast(0), N); - } - template - void operator()(RandomAccessIterator1 keys1, RandomAccessIterator2 keys2, RandomAccessIterator3 vals1, RandomAccessIterator4 vals2, const size_t N) - { - if (N < (1 << 21)) - detail::radix_sort<8,true>(keys1, keys2, vals1, vals2, N); - else - detail::radix_sort<3,true>(keys1, keys2, vals1, vals2, N); - } -}; - -template -void radix_sort(RandomAccessIterator1 keys1, - RandomAccessIterator2 keys2, - const size_t N) -{ - typedef typename thrust::iterator_value::type KeyType; - radix_sort_dispatcher()(keys1, keys2, N); -} - -template -void radix_sort(RandomAccessIterator1 keys1, - RandomAccessIterator2 keys2, - RandomAccessIterator3 vals1, - RandomAccessIterator4 vals2, - const size_t N) -{ - typedef typename thrust::iterator_value::type KeyType; - radix_sort_dispatcher()(keys1, keys2, vals1, vals2, N); -} - -} // namespace detail - -////////////// -// Key Sort // -////////////// - -template -void stable_radix_sort(RandomAccessIterator first, - RandomAccessIterator last) -{ - typedef typename thrust::iterator_system::type ExecutionPolicy; - typedef typename thrust::iterator_value::type KeyType; - - size_t N = last - first; - - // XXX assumes ExecutionPolicy is default constructible - // XXX consider how to get stateful systems into this function - ExecutionPolicy exec; - thrust::detail::temporary_array temp(exec, N); - - detail::radix_sort(first, temp.begin(), N); -} - - -//////////////////// -// Key-Value Sort // -//////////////////// - -template -void stable_radix_sort_by_key(RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2) -{ - // XXX the type of exec should be - // typedef decltype(select_system(first1,last1,first2)) system; - typedef typename thrust::iterator_system::type ExecutionPolicy; - typedef typename thrust::iterator_value::type KeyType; - typedef typename thrust::iterator_value::type ValueType; - - size_t N = last1 - first1; - - // XXX assumes ExecutionPolicy is default constructible - // XXX consider how to get stateful systems into this function - ExecutionPolicy exec; - thrust::detail::temporary_array temp1(exec, N); - thrust::detail::temporary_array temp2(exec, N); - - detail::radix_sort(first1, temp1.begin(), first2, temp2.begin(), N); -} - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/trivial_copy.h b/compat/thrust/system/detail/internal/scalar/trivial_copy.h deleted file mode 100644 index 8f008b5..0000000 --- a/compat/thrust/system/detail/internal/scalar/trivial_copy.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file trivial_copy.h - * \brief Sequential copy algorithms for plain-old-data. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - T *trivial_copy_n(const T *first, - std::ptrdiff_t n, - T *result) -{ - std::memmove(result, first, n * sizeof(T)); - return result + n; -} // end trivial_copy_n() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/unique.h b/compat/thrust/system/detail/internal/scalar/unique.h deleted file mode 100644 index cfc60c9..0000000 --- a/compat/thrust/system/detail/internal/scalar/unique.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file unique.h - * \brief Sequential implementations of unique algorithms. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - OutputIterator unique_copy(InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::value_type T; - - if(first != last) - { - T prev = *first; - - for(++first; first != last; ++first) - { - T temp = *first; - - if (!binary_pred(prev, temp)) - { - *output = prev; - - ++output; - - prev = temp; - } - } - - *output = prev; - ++output; - } - - return output; -} // end unique_copy() - - -template - ForwardIterator unique(ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - // unique_copy() permits in-situ operation - return thrust::system::detail::internal::scalar::unique_copy(first, last, first, binary_pred); -} // end unique() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/internal/scalar/unique_by_key.h b/compat/thrust/system/detail/internal/scalar/unique_by_key.h deleted file mode 100644 index b0be266..0000000 --- a/compat/thrust/system/detail/internal/scalar/unique_by_key.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file unique_by_key.h - * \brief Sequential implementations of unique_by_key algorithms. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace detail -{ -namespace internal -{ -namespace scalar -{ - -template - thrust::pair - unique_by_key_copy(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - typedef typename thrust::iterator_traits::value_type InputKeyType; - typedef typename thrust::iterator_traits::value_type OutputValueType; - - if(keys_first != keys_last) - { - InputKeyType temp_key = *keys_first; - OutputValueType temp_value = *values_first; - - for(++keys_first, ++values_first; - keys_first != keys_last; - ++keys_first, ++values_first) - { - InputKeyType key = *keys_first; - OutputValueType value = *values_first; - - if(!binary_pred(temp_key, key)) - { - *keys_output = temp_key; - *values_output = temp_value; - - ++keys_output; - ++values_output; - - temp_key = key; - temp_value = value; - } - } - - *keys_output = temp_key; - *values_output = temp_value; - - ++keys_output; - ++values_output; - } - - return thrust::make_pair(keys_output, values_output); -} // end unique_by_key_copy() - - -template - thrust::pair - unique_by_key(ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - // unique_by_key_copy() permits in-situ operation - return thrust::system::detail::internal::scalar::unique_by_key_copy(keys_first, keys_last, values_first, keys_first, values_first, binary_pred); -} // end unique_by_key() - -} // end namespace scalar -} // end namespace internal -} // end namespace detail -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/detail/system_error.inl b/compat/thrust/system/detail/system_error.inl deleted file mode 100644 index 74909be..0000000 --- a/compat/thrust/system/detail/system_error.inl +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include - -namespace thrust -{ - -namespace system -{ - - -system_error - ::system_error(error_code ec, const std::string &what_arg) - : std::runtime_error(what_arg), m_error_code(ec) -{ - -} // end system_error::system_error() - - -system_error - ::system_error(error_code ec, const char *what_arg) - : std::runtime_error(what_arg), m_error_code(ec) -{ - ; -} // end system_error::system_error() - - -system_error - ::system_error(error_code ec) - : std::runtime_error(""), m_error_code(ec) -{ - ; -} // end system_error::system_error() - - -system_error - ::system_error(int ev, const error_category &ecat, const std::string &what_arg) - : std::runtime_error(what_arg), m_error_code(ev,ecat) -{ - ; -} // end system_error::system_error() - - -system_error - ::system_error(int ev, const error_category &ecat, const char *what_arg) - : std::runtime_error(what_arg), m_error_code(ev,ecat) -{ - ; -} // end system_error::system_error() - - -system_error - ::system_error(int ev, const error_category &ecat) - : std::runtime_error(""), m_error_code(ev,ecat) -{ - ; -} // end system_error::system_error() - - -const error_code &system_error - ::code(void) const throw() -{ - return m_error_code; -} // end system_error::code() - - -const char *system_error - ::what(void) const throw() -{ - if(m_what.empty()) - { - try - { - m_what = this->std::runtime_error::what(); - if(m_error_code) - { - if(!m_what.empty()) m_what += ": "; - m_what += m_error_code.message(); - } - } - catch(...) - { - return std::runtime_error::what(); - } - } - - return m_what.c_str(); -} // end system_error::what() - - -} // end system - -} // end thrust - diff --git a/compat/thrust/system/error_code.h b/compat/thrust/system/error_code.h deleted file mode 100644 index 2b6582c..0000000 --- a/compat/thrust/system/error_code.h +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file error_code.h - * \brief An object used to hold error values, such as those originating from the - * operating system or other low-level application program interfaces. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -namespace system -{ - - -/*! \addtogroup system_diagnostics - * \{ - */ - -class error_condition; -class error_code; - -/*! A metafunction returning whether or not the parameter is an \p error_code enum. - */ -template struct is_error_code_enum : public thrust::detail::false_type {}; - -/*! A metafunction returning whether or not the parameter is an \p error_condition enum. - */ -template struct is_error_condition_enum : public thrust::detail::false_type {}; - - -// XXX N3092 prefers enum class errc { ... } -namespace errc -{ - -enum errc_t -{ - address_family_not_supported = detail::eafnosupport, - address_in_use = detail::eaddrinuse, - address_not_available = detail::eaddrnotavail, - already_connected = detail::eisconn, - argument_list_too_long = detail::e2big, - argument_out_of_domain = detail::edom, - bad_address = detail::efault, - bad_file_descriptor = detail::ebadf, - bad_message = detail::ebadmsg, - broken_pipe = detail::epipe, - connection_aborted = detail::econnaborted, - connection_already_in_progress = detail::ealready, - connection_refused = detail::econnrefused, - connection_reset = detail::econnreset, - cross_device_link = detail::exdev, - destination_address_required = detail::edestaddrreq, - device_or_resource_busy = detail::ebusy, - directory_not_empty = detail::enotempty, - executable_format_error = detail::enoexec, - file_exists = detail::eexist, - file_too_large = detail::efbig, - filename_too_long = detail::enametoolong, - function_not_supported = detail::enosys, - host_unreachable = detail::ehostunreach, - identifier_removed = detail::eidrm, - illegal_byte_sequence = detail::eilseq, - inappropriate_io_control_operation = detail::enotty, - interrupted = detail::eintr, - invalid_argument = detail::einval, - invalid_seek = detail::espipe, - io_error = detail::eio, - is_a_directory = detail::eisdir, - message_size = detail::emsgsize, - network_down = detail::enetdown, - network_reset = detail::enetreset, - network_unreachable = detail::enetunreach, - no_buffer_space = detail::enobufs, - no_child_process = detail::echild, - no_link = detail::enolink, - no_lock_available = detail::enolck, - no_message_available = detail::enodata, - no_message = detail::enomsg, - no_protocol_option = detail::enoprotoopt, - no_space_on_device = detail::enospc, - no_stream_resources = detail::enosr, - no_such_device_or_address = detail::enxio, - no_such_device = detail::enodev, - no_such_file_or_directory = detail::enoent, - no_such_process = detail::esrch, - not_a_directory = detail::enotdir, - not_a_socket = detail::enotsock, - not_a_stream = detail::enostr, - not_connected = detail::enotconn, - not_enough_memory = detail::enomem, - not_supported = detail::enotsup, - operation_canceled = detail::ecanceled, - operation_in_progress = detail::einprogress, - operation_not_permitted = detail::eperm, - operation_not_supported = detail::eopnotsupp, - operation_would_block = detail::ewouldblock, - owner_dead = detail::eownerdead, - permission_denied = detail::eacces, - protocol_error = detail::eproto, - protocol_not_supported = detail::eprotonosupport, - read_only_file_system = detail::erofs, - resource_deadlock_would_occur = detail::edeadlk, - resource_unavailable_try_again = detail::eagain, - result_out_of_range = detail::erange, - state_not_recoverable = detail::enotrecoverable, - stream_timeout = detail::etime, - text_file_busy = detail::etxtbsy, - timed_out = detail::etimedout, - too_many_files_open_in_system = detail::enfile, - too_many_files_open = detail::emfile, - too_many_links = detail::emlink, - too_many_symbolic_link_levels = detail::eloop, - value_too_large = detail::eoverflow, - wrong_protocol_type = detail::eprototype -}; // end errc_t - -} // end namespace errc - - -/*! Specialization of \p is_error_condition_enum for \p errc::errc_t - */ -template<> struct is_error_condition_enum : public thrust::detail::true_type {}; - - -// [19.5.1.1] class error_category - -/*! \brief The class \p error_category serves as a base class for types used to identify the - * source and encoding of a particular category of error code. Classes may be derived - * from \p error_category to support categories of errors in addition to those defined - * in the C++ International Standard. - */ -class error_category -{ - public: - /*! Destructor does nothing. - */ - inline virtual ~error_category(void); - - // XXX enable upon c++0x - // error_category(const error_category &) = delete; - // error_category &operator=(const error_category &) = delete; - - /*! \return A string naming the error category. - */ - inline virtual const char *name(void) const = 0; - - /*! \return \p error_condition(ev, *this). - */ - inline virtual error_condition default_error_condition(int ev) const; - - /*! \return default_error_condition(code) == condition - */ - inline virtual bool equivalent(int code, const error_condition &condition) const; - - /*! \return *this == code.category() && code.value() == condition - */ - inline virtual bool equivalent(const error_code &code, int condition) const; - - /*! \return A string that describes the error condition denoted by \p ev. - */ - virtual std::string message(int ev) const = 0; - - /*! \return *this == &rhs - */ - inline bool operator==(const error_category &rhs) const; - - /*! \return !(*this == rhs) - */ - inline bool operator!=(const error_category &rhs) const; - - /*! \return less()(this, &rhs) - * \note \c less provides a total ordering for pointers. - */ - inline bool operator<(const error_category &rhs) const; -}; // end error_category - - -// [19.5.1.5] error_category objects - - -/*! \return A reference to an object of a type derived from class \p error_category. - * \note The object's \p default_error_condition and \p equivalent virtual functions - * shall behave as specified for the class \p error_category. The object's - * \p name virtual function shall return a pointer to the string "generic". - */ -inline const error_category &generic_category(void); - - -/*! \return A reference to an object of a type derived from class \p error_category. - * \note The object's \p equivalent virtual functions shall behave as specified for - * class \p error_category. The object's \p name virtual function shall return - * a pointer to the string "system". The object's \p default_error_condition - * virtual function shall behave as follows: - * - * If the argument ev corresponds to a POSIX errno value - * \c posv, the function shall return error_condition(ev,generic_category()). - * Otherwise, the function shall return error_condition(ev,system_category()). - * What constitutes correspondence for any given operating system is unspecified. - */ -inline const error_category &system_category(void); - - -// [19.5.2] Class error_code - - -/*! \brief The class \p error_code describes an object used to hold error code values, such as - * those originating from the operating system or other low-level application program - * interfaces. - */ -class error_code -{ - public: - // [19.5.2.2] constructors: - - /*! Effects: Constructs an object of type \p error_code. - * \post value() == 0 and category() == &system_category(). - */ - inline error_code(void); - - /*! Effects: Constructs an object of type \p error_code. - * \post value() == val and category() == &cat. - */ - inline error_code(int val, const error_category &cat); - - /*! Effects: Constructs an object of type \p error_code. - * \post *this == make_error_code(e). - */ - template - error_code(ErrorCodeEnum e -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - , typename thrust::detail::enable_if::value>::type * = 0 -#endif // THRUST_HOST_COMPILER_MSVC - ); - - // [19.5.2.3] modifiers: - - /*! \post value() == val and category() == &cat. - */ - inline void assign(int val, const error_category &cat); - - /*! \post *this == make_error_code(e). - */ - template -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - typename thrust::detail::enable_if::value, error_code>::type & -#else - error_code & -#endif // THRUST_HOST_COMPILER_MSVC - operator=(ErrorCodeEnum e); - - /*! \post value() == 0 and category() == system_category(). - */ - inline void clear(void); - - // [19.5.2.4] observers: - - /*! \return An integral value of this \p error_code object. - */ - inline int value(void) const; - - /*! \return An \p error_category describing the category of this \p error_code object. - */ - inline const error_category &category(void) const; - - /*! \return category().default_error_condition(). - */ - inline error_condition default_error_condition(void) const; - - /*! \return category().message(value()). - */ - inline std::string message(void) const; - - // XXX replace the below upon c++0x - // inline explicit operator bool (void) const; - - /*! \return value() != 0. - */ - inline operator bool (void) const; - - /*! \cond - */ - private: - int m_val; - const error_category *m_cat; - /*! \endcond - */ -}; // end error_code - - -// [19.5.2.5] Class error_code non-member functions - - -// XXX replace errc::errc_t with errc upon c++0x -/*! \return error_code(static_cast(e), generic_category()) - */ -inline error_code make_error_code(errc::errc_t e); - - -/*! \return lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value(). - */ -inline bool operator<(const error_code &lhs, const error_code &rhs); - - -/*! Effects: os << ec.category().name() << ':' << ec.value(). - */ -template - std::basic_ostream& - operator<<(std::basic_ostream& os, const error_code &ec); - - -// [19.5.3] class error_condition - - -/*! \brief The class \p error_condition describes an object used to hold values identifying - * error conditions. - * - * \note \p error_condition values are portable abstractions, while \p error_code values - * are implementation specific. - */ -class error_condition -{ - public: - // [19.5.3.2] constructors - - /*! Constructs an object of type \p error_condition. - * \post value() == 0. - * \post category() == generic_category(). - */ - inline error_condition(void); - - /*! Constructs an object of type \p error_condition. - * \post value() == val. - * \post category() == cat. - */ - inline error_condition(int val, const error_category &cat); - - /*! Constructs an object of type \p error_condition. - * \post *this == make_error_condition(e). - * \note This constructor shall not participate in overload resolution unless - * is_error_condition_enum::value is true. - */ - template - error_condition(ErrorConditionEnum e -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - , typename thrust::detail::enable_if::value>::type * = 0 -#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - ); - - // [19.5.3.3] modifiers - - /*! Assigns to this \p error_code object from an error value and an \p error_category. - * \param val The new value to return from value(). - * \param cat The new \p error_category to return from category(). - * \post value() == val. - * \post category() == cat. - */ - inline void assign(int val, const error_category &cat); - - /*! Assigns to this \p error_code object from an error condition enumeration. - * \return *this - * \post *this == make_error_condition(e). - * \note This operator shall not participate in overload resolution unless - * is_error_condition_enum::value is true. - */ - template -// XXX WAR msvc's problem with enable_if -#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - typename thrust::detail::enable_if::value, error_condition>::type & -#else - error_condition & -#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC - operator=(ErrorConditionEnum e); - - /*! Clears this \p error_code object. - * \post value == 0 - * \post category() == generic_category(). - */ - inline void clear(void); - - // [19.5.3.4] observers - - /*! \return The value encoded by this \p error_condition. - */ - inline int value(void) const; - - /*! \return A const reference to the \p error_category encoded by this \p error_condition. - */ - inline const error_category &category(void) const; - - /*! \return category().message(value()). - */ - inline std::string message(void) const; - - // XXX replace below with this upon c++0x - //explicit operator bool (void) const; - - /*! \return value() != 0. - */ - inline operator bool (void) const; - - /*! \cond - */ - - private: - int m_val; - const error_category *m_cat; - - /*! \endcond - */ -}; // end error_condition - - - -// [19.5.3.5] Class error_condition non-member functions - -// XXX replace errc::errc_t with errc upon c++0x -/*! \return error_condition(static_cast(e), generic_category()). - */ -inline error_condition make_error_condition(errc::errc_t e); - - -/*! \return lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value(). - */ -inline bool operator<(const error_condition &lhs, const error_condition &rhs); - - -// [19.5.4] Comparison operators - - -/*! \return lhs.category() == rhs.category() && lhs.value() == rhs.value(). - */ -inline bool operator==(const error_code &lhs, const error_code &rhs); - - -/*! \return lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs,rhs.value()). - */ -inline bool operator==(const error_code &lhs, const error_condition &rhs); - - -/*! \return rhs.category().equivalent(lhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value()). - */ -inline bool operator==(const error_condition &lhs, const error_code &rhs); - - -/*! \return lhs.category() == rhs.category() && lhs.value() == rhs.value() - */ -inline bool operator==(const error_condition &lhs, const error_condition &rhs); - - -/*! \return !(lhs == rhs) - */ -inline bool operator!=(const error_code &lhs, const error_code &rhs); - - -/*! \return !(lhs == rhs) - */ -inline bool operator!=(const error_code &lhs, const error_condition &rhs); - - -/*! \return !(lhs == rhs) - */ -inline bool operator!=(const error_condition &lhs, const error_code &rhs); - - -/*! \return !(lhs == rhs) - */ -inline bool operator!=(const error_condition &lhs, const error_condition &rhs); - -/*! \} // end system_diagnostics - */ - - -} // end system - - -// import names into thrust:: -using system::error_category; -using system::error_code; -using system::error_condition; -using system::is_error_code_enum; -using system::is_error_condition_enum; -using system::make_error_code; -using system::make_error_condition; - -// XXX replace with using system::errc upon c++0x -namespace errc = system::errc; - -using system::generic_category; -using system::system_category; - -} // end thrust - -#include -#include -#include - diff --git a/compat/thrust/system/omp/detail/adjacent_difference.h b/compat/thrust/system/omp/detail/adjacent_difference.h deleted file mode 100644 index 0bbc188..0000000 --- a/compat/thrust/system/omp/detail/adjacent_difference.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template - OutputIterator adjacent_difference(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - // omp prefers generic::adjacent_difference to cpp::adjacent_difference - return thrust::system::detail::generic::adjacent_difference(exec, first, last, result, binary_op); -} // end adjacent_difference() - -} // end detail -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/detail/assign_value.h b/compat/thrust/system/omp/detail/assign_value.h deleted file mode 100644 index eda3b97..0000000 --- a/compat/thrust/system/omp/detail/assign_value.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits assign_value -#include - diff --git a/compat/thrust/system/omp/detail/binary_search.h b/compat/thrust/system/omp/detail/binary_search.h deleted file mode 100644 index 254e6fd..0000000 --- a/compat/thrust/system/omp/detail/binary_search.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template -ForwardIterator lower_bound(execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp) -{ - // omp prefers generic::lower_bound to cpp::lower_bound - return thrust::system::detail::generic::lower_bound(exec, begin, end, value, comp); -} - - -template -ForwardIterator upper_bound(execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp) -{ - // omp prefers generic::upper_bound to cpp::upper_bound - return thrust::system::detail::generic::upper_bound(exec, begin, end, value, comp); -} - - -template -bool binary_search(execution_policy &exec, - ForwardIterator begin, - ForwardIterator end, - const T& value, - StrictWeakOrdering comp) -{ - // omp prefers generic::binary_search to cpp::binary_search - return thrust::system::detail::generic::binary_search(exec, begin, end, value, comp); -} - - -} // end detail -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/detail/copy.h b/compat/thrust/system/omp/detail/copy.h deleted file mode 100644 index b23ac18..0000000 --- a/compat/thrust/system/omp/detail/copy.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template -OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template -OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/copy.inl b/compat/thrust/system/omp/detail/copy.inl deleted file mode 100644 index 915ff92..0000000 --- a/compat/thrust/system/omp/detail/copy.inl +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ -namespace dispatch -{ - -template - OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - thrust::incrementable_traversal_tag) -{ - return thrust::system::cpp::detail::copy(exec, first, last, result); -} // end copy() - - -template - OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - thrust::random_access_traversal_tag) -{ - // XXX WAR problems reconciling unrelated types such as omp & tbb - // reinterpret iterators as the policy we were passed - // this ensures that generic::copy's implementation, which eventually results in - // zip_iterator works correctly - thrust::detail::tagged_iterator retagged_result(result); - - return thrust::system::detail::generic::copy(exec, thrust::reinterpret_tag(first), thrust::reinterpret_tag(last), retagged_result).base(); -} // end copy() - - -template - OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result, - thrust::incrementable_traversal_tag) -{ - return thrust::system::cpp::detail::copy_n(exec, first, n, result); -} // end copy_n() - - -template - OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result, - thrust::random_access_traversal_tag) -{ - // XXX WAR problems reconciling unrelated types such as omp & tbb - // reinterpret iterators as the policy we were passed - // this ensures that generic::copy's implementation, which eventually results in - // zip_iterator works correctly - thrust::detail::tagged_iterator retagged_result(result); - - return thrust::system::detail::generic::copy_n(exec, thrust::reinterpret_tag(first), n, retagged_result).base(); -} // end copy_n() - -} // end dispatch - - -template -OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - typedef typename thrust::iterator_traversal::type traversal1; - typedef typename thrust::iterator_traversal::type traversal2; - - typedef typename thrust::detail::minimum_type::type traversal; - - // dispatch on minimum traversal - return thrust::system::omp::detail::dispatch::copy(exec, first,last,result,traversal()); -} // end copy() - - - -template -OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result) -{ - typedef typename thrust::iterator_traversal::type traversal1; - typedef typename thrust::iterator_traversal::type traversal2; - - typedef typename thrust::detail::minimum_type::type traversal; - - // dispatch on minimum traversal - return thrust::system::omp::detail::dispatch::copy_n(exec,first,n,result,traversal()); -} // end copy_n() - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/copy_if.h b/compat/thrust/system/omp/detail/copy_if.h deleted file mode 100644 index 46754a9..0000000 --- a/compat/thrust/system/omp/detail/copy_if.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - OutputIterator copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -} // end detail -} // end omp -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/omp/detail/copy_if.inl b/compat/thrust/system/omp/detail/copy_if.inl deleted file mode 100644 index 1af6a21..0000000 --- a/compat/thrust/system/omp/detail/copy_if.inl +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - OutputIterator copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - // omp prefers generic::copy_if to cpp::copy_if - return thrust::system::detail::generic::copy_if(exec, first, last, stencil, result, pred); -} // end copy_if() - - -} // end detail -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/detail/count.h b/compat/thrust/system/omp/detail/count.h deleted file mode 100644 index da31ee8..0000000 --- a/compat/thrust/system/omp/detail/count.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits count -#include - diff --git a/compat/thrust/system/omp/detail/default_decomposition.h b/compat/thrust/system/omp/detail/default_decomposition.h deleted file mode 100644 index f1904c2..0000000 --- a/compat/thrust/system/omp/detail/default_decomposition.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file default_decomposition.h - * \brief Return a decomposition that is appropriate for the OpenMP backend. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -thrust::system::detail::internal::uniform_decomposition default_decomposition(IndexType n); - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/default_decomposition.inl b/compat/thrust/system/omp/detail/default_decomposition.inl deleted file mode 100644 index 366b4f5..0000000 --- a/compat/thrust/system/omp/detail/default_decomposition.inl +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -// don't attempt to #include this file without omp support -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) -#include -#endif // omp support - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -thrust::system::detail::internal::uniform_decomposition default_decomposition(IndexType n) -{ - // we're attempting to launch an omp kernel, assert we're compiling with omp support - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to OpenMP support in your compiler. X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) - return thrust::system::detail::internal::uniform_decomposition(n, 1, omp_get_num_procs()); -#else - return thrust::system::detail::internal::uniform_decomposition(n, 1, 1); -#endif -} - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/equal.h b/compat/thrust/system/omp/detail/equal.h deleted file mode 100644 index 74e5518..0000000 --- a/compat/thrust/system/omp/detail/equal.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits equal -#include - diff --git a/compat/thrust/system/omp/detail/execution_policy.h b/compat/thrust/system/omp/detail/execution_policy.h deleted file mode 100644 index 1b06224..0000000 --- a/compat/thrust/system/omp/detail/execution_policy.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -// put the canonical tag in the same ns as the backend's entry points -namespace omp -{ -namespace detail -{ - -// this awkward sequence of definitions arise -// from the desire both for tag to derive -// from execution_policy and for execution_policy -// to convert to tag (when execution_policy is not -// an ancestor of tag) - -// forward declaration of tag -struct tag; - -// forward declaration of execution_policy -template struct execution_policy; - -// specialize execution_policy for tag -template<> - struct execution_policy - : thrust::system::cpp::detail::execution_policy -{}; - -// tag's definition comes before the -// generic definition of execution_policy -struct tag : execution_policy {}; - -// allow conversion to tag when it is not a successor -template - struct execution_policy - : thrust::system::cpp::detail::execution_policy -{ - // allow conversion to tag - inline operator tag () const - { - return tag(); - } -}; - - -// overloads of select_system - -// XXX select_system(tbb, omp) & select_system(omp, tbb) are ambiguous -// because both convert to cpp without these overloads, which we -// arbitrarily define in the omp backend - -template -inline __host__ __device__ - System1 select_system(execution_policy s, thrust::system::tbb::detail::execution_policy) -{ - return thrust::detail::derived_cast(s); -} // end select_system() - - -template -inline __host__ __device__ - System2 select_system(thrust::system::tbb::detail::execution_policy, execution_policy s) -{ - return thrust::detail::derived_cast(s); -} // end select_system() - - -} // end detail - -// alias execution_policy and tag here -using thrust::system::omp::detail::execution_policy; -using thrust::system::omp::detail::tag; - -} // end omp -} // end system - -// alias items at top-level -namespace omp -{ - -using thrust::system::omp::execution_policy; -using thrust::system::omp::tag; - -} // end omp -} // end thrust - diff --git a/compat/thrust/system/omp/detail/extrema.h b/compat/thrust/system/omp/detail/extrema.h deleted file mode 100644 index fb96770..0000000 --- a/compat/thrust/system/omp/detail/extrema.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -ForwardIterator max_element(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // omp prefers generic::max_element to cpp::max_element - return thrust::system::detail::generic::max_element(exec, first, last, comp); -} // end max_element() - -template -ForwardIterator min_element(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // omp prefers generic::min_element to cpp::min_element - return thrust::system::detail::generic::min_element(exec, first, last, comp); -} // end min_element() - -template -thrust::pair minmax_element(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // omp prefers generic::minmax_element to cpp::minmax_element - return thrust::system::detail::generic::minmax_element(exec, first, last, comp); -} // end minmax_element() - -} // end detail -} // end omp -} // end system -} // end thrust - - diff --git a/compat/thrust/system/omp/detail/fill.h b/compat/thrust/system/omp/detail/fill.h deleted file mode 100644 index 5219e1c..0000000 --- a/compat/thrust/system/omp/detail/fill.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits fill -#include - diff --git a/compat/thrust/system/omp/detail/find.h b/compat/thrust/system/omp/detail/find.h deleted file mode 100644 index a8dca5a..0000000 --- a/compat/thrust/system/omp/detail/find.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file find.h - * \brief OpenMP implementation of find_if. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -InputIterator find_if(execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - // omp prefers generic::find_if to cpp::find_if - return thrust::system::detail::generic::find_if(exec, first, last, pred); -} - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/for_each.h b/compat/thrust/system/omp/detail/for_each.h deleted file mode 100644 index 1030623..0000000 --- a/compat/thrust/system/omp/detail/for_each.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.h - * \brief Defines the interface for a function that executes a - * function or functional for each value in a given range. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template - RandomAccessIterator for_each(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - UnaryFunction f); - -template - RandomAccessIterator for_each_n(execution_policy &exec, - RandomAccessIterator first, - Size n, - UnaryFunction f); - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/for_each.inl b/compat/thrust/system/omp/detail/for_each.inl deleted file mode 100644 index c6ab827..0000000 --- a/compat/thrust/system/omp/detail/for_each.inl +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file for_each.inl - * \brief Inline file for for_each.h. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -RandomAccessIterator for_each_n(execution_policy &, - RandomAccessIterator first, - Size n, - UnaryFunction f) -{ - // we're attempting to launch an omp kernel, assert we're compiling with omp support - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to enable OpenMP support in your compiler. X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - - if (n <= 0) return first; //empty range - - // create a wrapped function for f - typedef typename thrust::iterator_reference::type reference; - thrust::detail::host_function wrapped_f(f); - -// do not attempt to compile the body of this function, which depends on #pragma omp, -// without support from the compiler -// XXX implement the body of this function in another file to eliminate this ugliness -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) - // use a signed type for the iteration variable or suffer the consequences of warnings - typedef typename thrust::iterator_difference::type DifferenceType; - DifferenceType signed_n = n; -#pragma omp parallel for - for(DifferenceType i = 0; - i < signed_n; - ++i) - { - RandomAccessIterator temp = first + i; - wrapped_f(*temp); - } -#endif // THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE - - return first + n; -} // end for_each_n() - -template - RandomAccessIterator for_each(execution_policy &s, - RandomAccessIterator first, - RandomAccessIterator last, - UnaryFunction f) -{ - return omp::detail::for_each_n(s, first, thrust::distance(first,last), f); -} // end for_each() - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/gather.h b/compat/thrust/system/omp/detail/gather.h deleted file mode 100644 index dfb7d7f..0000000 --- a/compat/thrust/system/omp/detail/gather.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits gather -#include - diff --git a/compat/thrust/system/omp/detail/generate.h b/compat/thrust/system/omp/detail/generate.h deleted file mode 100644 index 0cb33b9..0000000 --- a/compat/thrust/system/omp/detail/generate.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits generate -#include - diff --git a/compat/thrust/system/omp/detail/get_value.h b/compat/thrust/system/omp/detail/get_value.h deleted file mode 100644 index e376e65..0000000 --- a/compat/thrust/system/omp/detail/get_value.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits get_value -#include - diff --git a/compat/thrust/system/omp/detail/inner_product.h b/compat/thrust/system/omp/detail/inner_product.h deleted file mode 100644 index 351421a..0000000 --- a/compat/thrust/system/omp/detail/inner_product.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits inner_product -#include - diff --git a/compat/thrust/system/omp/detail/iter_swap.h b/compat/thrust/system/omp/detail/iter_swap.h deleted file mode 100644 index 16176ec..0000000 --- a/compat/thrust/system/omp/detail/iter_swap.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits iter_swap -#include - diff --git a/compat/thrust/system/omp/detail/logical.h b/compat/thrust/system/omp/detail/logical.h deleted file mode 100644 index b2a80de..0000000 --- a/compat/thrust/system/omp/detail/logical.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits logical -#include - diff --git a/compat/thrust/system/omp/detail/malloc_and_free.h b/compat/thrust/system/omp/detail/malloc_and_free.h deleted file mode 100644 index 811a552..0000000 --- a/compat/thrust/system/omp/detail/malloc_and_free.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits malloc and free -#include - diff --git a/compat/thrust/system/omp/detail/memory.inl b/compat/thrust/system/omp/detail/memory.inl deleted file mode 100644 index 7d53de6..0000000 --- a/compat/thrust/system/omp/detail/memory.inl +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ - - -template - template - reference & - reference - ::operator=(const reference &other) -{ - return super_t::operator=(other); -} // end reference::operator=() - -template - reference & - reference - ::operator=(const value_type &x) -{ - return super_t::operator=(x); -} // end reference::operator=() - -template -__host__ __device__ -void swap(reference a, reference b) -{ - a.swap(b); -} // end swap() - -namespace detail -{ - -// XXX circular #inclusion problems cause the compiler to believe that cpp::malloc -// is not defined -// WAR the problem by using adl to call cpp::malloc, which requires it to depend -// on a template parameter -template - pointer malloc_workaround(Tag t, std::size_t n) -{ - return pointer(malloc(t, n)); -} // end malloc_workaround() - -// XXX circular #inclusion problems cause the compiler to believe that cpp::free -// is not defined -// WAR the problem by using adl to call cpp::free, which requires it to depend -// on a template parameter -template - void free_workaround(Tag t, pointer ptr) -{ - free(t, ptr.get()); -} // end free_workaround() - -} // end detail - -inline pointer malloc(std::size_t n) -{ - // XXX this is how we'd like to implement this function, - // if not for circular #inclusion problems: - // - // return pointer(thrust::system::cpp::malloc(n)) - // - return detail::malloc_workaround(cpp::tag(), n); -} // end malloc() - -template -pointer malloc(std::size_t n) -{ - pointer raw_ptr = thrust::system::omp::malloc(sizeof(T) * n); - return pointer(reinterpret_cast(raw_ptr.get())); -} // end malloc() - -inline void free(pointer ptr) -{ - // XXX this is how we'd like to implement this function, - // if not for circular #inclusion problems: - // - // thrust::system::cpp::free(ptr) - // - detail::free_workaround(cpp::tag(), ptr); -} // end free() - -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/detail/merge.h b/compat/thrust/system/omp/detail/merge.h deleted file mode 100644 index a7047aa..0000000 --- a/compat/thrust/system/omp/detail/merge.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits merge -#include - diff --git a/compat/thrust/system/omp/detail/mismatch.h b/compat/thrust/system/omp/detail/mismatch.h deleted file mode 100644 index 03980cf..0000000 --- a/compat/thrust/system/omp/detail/mismatch.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits mismatch -#include - diff --git a/compat/thrust/system/omp/detail/par.h b/compat/thrust/system/omp/detail/par.h deleted file mode 100644 index fa6d18e..0000000 --- a/compat/thrust/system/omp/detail/par.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -struct par_t : thrust::system::omp::detail::execution_policy -{ - par_t() : thrust::system::omp::detail::execution_policy() {} - - template - thrust::detail::execute_with_allocator - operator()(Allocator &alloc) const - { - return thrust::detail::execute_with_allocator(alloc); - } -}; - - -} // end detail - - -static const detail::par_t par; - - -} // end omp -} // end system - - -// alias par here -namespace omp -{ - - -using thrust::system::omp::par; - - -} // end omp -} // end thrust - diff --git a/compat/thrust/system/omp/detail/partition.h b/compat/thrust/system/omp/detail/partition.h deleted file mode 100644 index edcbc30..0000000 --- a/compat/thrust/system/omp/detail/partition.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief OpenMP implementation of reduce algorithms. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/partition.inl b/compat/thrust/system/omp/detail/partition.inl deleted file mode 100644 index da629e5..0000000 --- a/compat/thrust/system/omp/detail/partition.inl +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief OpenMP implementation of reduce algorithms. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - // omp prefers generic::stable_partition to cpp::stable_partition - return thrust::system::detail::generic::stable_partition(exec, first, last, pred); -} // end stable_partition() - - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - // omp prefers generic::stable_partition to cpp::stable_partition - return thrust::system::detail::generic::stable_partition(exec, first, last, stencil, pred); -} // end stable_partition() - - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - // omp prefers generic::stable_partition_copy to cpp::stable_partition_copy - return thrust::system::detail::generic::stable_partition_copy(exec, first, last, out_true, out_false, pred); -} // end stable_partition_copy() - - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - // omp prefers generic::stable_partition_copy to cpp::stable_partition_copy - return thrust::system::detail::generic::stable_partition_copy(exec, first, last, stencil, out_true, out_false, pred); -} // end stable_partition_copy() - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/reduce.h b/compat/thrust/system/omp/detail/reduce.h deleted file mode 100644 index 0cc5ceb..0000000 --- a/compat/thrust/system/omp/detail/reduce.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief OpenMP implementation of reduce algorithms. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - OutputType reduce(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputType init, - BinaryFunction binary_op); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/reduce.inl b/compat/thrust/system/omp/detail/reduce.inl deleted file mode 100644 index 1347bfd..0000000 --- a/compat/thrust/system/omp/detail/reduce.inl +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - OutputType reduce(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputType init, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_difference::type difference_type; - - const difference_type n = thrust::distance(first,last); - - // determine first and second level decomposition - thrust::system::detail::internal::uniform_decomposition decomp1 = thrust::system::omp::detail::default_decomposition(n); - thrust::system::detail::internal::uniform_decomposition decomp2(decomp1.size() + 1, 1, 1); - - // allocate storage for the initializer and partial sums - // XXX use select_system for Tag - thrust::detail::temporary_array partial_sums(exec, decomp1.size() + 1); - - // set first element of temp array to init - partial_sums[0] = init; - - // accumulate partial sums (first level reduction) - thrust::system::omp::detail::reduce_intervals(exec, first, partial_sums.begin() + 1, binary_op, decomp1); - - // reduce partial sums (second level reduction) - thrust::system::omp::detail::reduce_intervals(exec, partial_sums.begin(), partial_sums.begin(), binary_op, decomp2); - - return partial_sums[0]; -} // end reduce() - - -} // end detail -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/detail/reduce_by_key.h b/compat/thrust/system/omp/detail/reduce_by_key.h deleted file mode 100644 index d7243ee..0000000 --- a/compat/thrust/system/omp/detail/reduce_by_key.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief OpenMP implementation of reduce algorithms. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - thrust::pair - reduce_by_key(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/reduce_by_key.inl b/compat/thrust/system/omp/detail/reduce_by_key.inl deleted file mode 100644 index 91402d8..0000000 --- a/compat/thrust/system/omp/detail/reduce_by_key.inl +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template - thrust::pair - reduce_by_key(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - // omp prefers generic::reduce_by_key to cpp::reduce_by_key - return thrust::system::detail::generic::reduce_by_key(exec, keys_first, keys_last, values_first, keys_output, values_output, binary_pred, binary_op); -} // end reduce_by_key() - - -} // end detail -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/detail/reduce_intervals.h b/compat/thrust/system/omp/detail/reduce_intervals.h deleted file mode 100644 index 7bce207..0000000 --- a/compat/thrust/system/omp/detail/reduce_intervals.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce_intervals.h - * \brief OpenMP implementations of reduce_intervals algorithms. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -void reduce_intervals(execution_policy &exec, - InputIterator input, - OutputIterator output, - BinaryFunction binary_op, - Decomposition decomp); - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/reduce_intervals.inl b/compat/thrust/system/omp/detail/reduce_intervals.inl deleted file mode 100644 index 0752b8a..0000000 --- a/compat/thrust/system/omp/detail/reduce_intervals.inl +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -void reduce_intervals(execution_policy &, - InputIterator input, - OutputIterator output, - BinaryFunction binary_op, - Decomposition decomp) -{ - // we're attempting to launch an omp kernel, assert we're compiling with omp support - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to enable OpenMP support in your compiler. X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) - typedef typename thrust::iterator_value::type OutputType; - - // wrap binary_op - thrust::detail::host_function wrapped_binary_op(binary_op); - - typedef thrust::detail::intptr_t index_type; - - index_type n = static_cast(decomp.size()); - -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) -# pragma omp parallel for -#endif // THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE - for(index_type i = 0; i < n; i++) - { - InputIterator begin = input + decomp[i].begin(); - InputIterator end = input + decomp[i].end(); - - if (begin != end) - { - OutputType sum = thrust::raw_reference_cast(*begin); - - ++begin; - - while (begin != end) - { - sum = wrapped_binary_op(sum, *begin); - ++begin; - } - - OutputIterator tmp = output + i; - *tmp = sum; - } - } -#endif // THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE -} - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/remove.h b/compat/thrust/system/omp/detail/remove.h deleted file mode 100644 index ebcb496..0000000 --- a/compat/thrust/system/omp/detail/remove.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/remove.inl b/compat/thrust/system/omp/detail/remove.inl deleted file mode 100644 index c056f96..0000000 --- a/compat/thrust/system/omp/detail/remove.inl +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - // omp prefers generic::remove_if to cpp::remove_if - return thrust::system::detail::generic::remove_if(exec, first, last, pred); -} - - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - // omp prefers generic::remove_if to cpp::remove_if - return thrust::system::detail::generic::remove_if(exec, first, last, stencil, pred); -} - - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - // omp prefers generic::remove_copy_if to cpp::remove_copy_if - return thrust::system::detail::generic::remove_copy_if(exec, first, last, result, pred); -} - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - // omp prefers generic::remove_copy_if to cpp::remove_copy_if - return thrust::system::detail::generic::remove_copy_if(exec, first, last, stencil, result, pred); -} - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/replace.h b/compat/thrust/system/omp/detail/replace.h deleted file mode 100644 index c48555d..0000000 --- a/compat/thrust/system/omp/detail/replace.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits this algorithm -#include - diff --git a/compat/thrust/system/omp/detail/reverse.h b/compat/thrust/system/omp/detail/reverse.h deleted file mode 100644 index 04923d1..0000000 --- a/compat/thrust/system/omp/detail/reverse.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits reverse -#include - diff --git a/compat/thrust/system/omp/detail/scan.h b/compat/thrust/system/omp/detail/scan.h deleted file mode 100644 index c105951..0000000 --- a/compat/thrust/system/omp/detail/scan.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits scan -#include - diff --git a/compat/thrust/system/omp/detail/scan_by_key.h b/compat/thrust/system/omp/detail/scan_by_key.h deleted file mode 100644 index bfbd5d6..0000000 --- a/compat/thrust/system/omp/detail/scan_by_key.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits this algorithm -#include - diff --git a/compat/thrust/system/omp/detail/scatter.h b/compat/thrust/system/omp/detail/scatter.h deleted file mode 100644 index c48555d..0000000 --- a/compat/thrust/system/omp/detail/scatter.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits this algorithm -#include - diff --git a/compat/thrust/system/omp/detail/sequence.h b/compat/thrust/system/omp/detail/sequence.h deleted file mode 100644 index 811d8f5..0000000 --- a/compat/thrust/system/omp/detail/sequence.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits sequence -#include - diff --git a/compat/thrust/system/omp/detail/set_operations.h b/compat/thrust/system/omp/detail/set_operations.h deleted file mode 100644 index 687edb2..0000000 --- a/compat/thrust/system/omp/detail/set_operations.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits set_operations -#include - diff --git a/compat/thrust/system/omp/detail/sort.h b/compat/thrust/system/omp/detail/sort.h deleted file mode 100644 index 9a480f2..0000000 --- a/compat/thrust/system/omp/detail/sort.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template -void stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - -template -void stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/sort.inl b/compat/thrust/system/omp/detail/sort.inl deleted file mode 100644 index ab4f4a1..0000000 --- a/compat/thrust/system/omp/detail/sort.inl +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -// don't attempt to #include this file without omp support -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) -#include -#endif // omp support - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ -namespace sort_detail -{ - - -template -void inplace_merge(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator middle, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_value::type value_type; - - thrust::detail::temporary_array a(exec, first, middle); - thrust::detail::temporary_array b(exec, middle, last); - - thrust::system::cpp::detail::merge(exec, a.begin(), a.end(), b.begin(), b.end(), first, comp); -} - - -template -void inplace_merge_by_key(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 middle1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_value::type value_type1; - typedef typename thrust::iterator_value::type value_type2; - - RandomAccessIterator2 middle2 = first2 + (middle1 - first1); - RandomAccessIterator2 last2 = first2 + (last1 - first1); - - thrust::detail::temporary_array lhs1(exec, first1, middle1); - thrust::detail::temporary_array rhs1(exec, middle1, last1); - thrust::detail::temporary_array lhs2(exec, first2, middle2); - thrust::detail::temporary_array rhs2(exec, middle2, last2); - - thrust::system::cpp::detail::merge_by_key - (exec, - lhs1.begin(), lhs1.end(), rhs1.begin(), rhs1.end(), - lhs2.begin(), rhs2.begin(), - first1, first2, comp); -} - - -} // end sort_detail - - -template -void stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - // we're attempting to launch an omp kernel, assert we're compiling with omp support - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to enable OpenMP support in your compiler. X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) - typedef typename thrust::iterator_difference::type IndexType; - - if (first == last) - return; - - #pragma omp parallel - { - thrust::system::detail::internal::uniform_decomposition decomp(last - first, 1, omp_get_num_threads()); - - // process id - IndexType p_i = omp_get_thread_num(); - - // every thread sorts its own tile - if (p_i < decomp.size()) - { - thrust::system::cpp::detail::stable_sort(exec, - first + decomp[p_i].begin(), - first + decomp[p_i].end(), - comp); - } - - #pragma omp barrier - - IndexType nseg = decomp.size(); - IndexType h = 2; - - // keep track of which sub-range we're processing - IndexType a=p_i, b=p_i, c=p_i+1; - - while( nseg>1 ) - { - if(c >= decomp.size()) - c = decomp.size() - 1; - - if((p_i % h) == 0 && c > b) - { - thrust::system::omp::detail::sort_detail::inplace_merge - (exec, - first + decomp[a].begin(), - first + decomp[b].end(), - first + decomp[c].end(), - comp); - b = c; - c += h; - } - - nseg = (nseg + 1) / 2; - h *= 2; - - #pragma omp barrier - } - } -#endif // THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE -} - - -template -void stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp) -{ - // we're attempting to launch an omp kernel, assert we're compiling with omp support - // ======================================================================== - // X Note to the user: If you've found this line due to a compiler error, X - // X you need to enable OpenMP support in your compiler. X - // ======================================================================== - THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation::value) ); - -#if (THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE == THRUST_TRUE) - typedef typename thrust::iterator_difference::type IndexType; - - if (keys_first == keys_last) - return; - - #pragma omp parallel - { - thrust::system::detail::internal::uniform_decomposition decomp(keys_last - keys_first, 1, omp_get_num_threads()); - - // process id - IndexType p_i = omp_get_thread_num(); - - // every thread sorts its own tile - if (p_i < decomp.size()) - { - thrust::system::cpp::detail::stable_sort_by_key(exec, - keys_first + decomp[p_i].begin(), - keys_first + decomp[p_i].end(), - values_first + decomp[p_i].begin(), - comp); - } - - #pragma omp barrier - - IndexType nseg = decomp.size(); - IndexType h = 2; - - // keep track of which sub-range we're processing - IndexType a=p_i, b=p_i, c=p_i+1; - - while( nseg>1 ) - { - if(c >= decomp.size()) - c = decomp.size() - 1; - - if((p_i % h) == 0 && c > b) - { - thrust::system::omp::detail::sort_detail::inplace_merge_by_key - (exec, - keys_first + decomp[a].begin(), - keys_first + decomp[b].end(), - keys_first + decomp[c].end(), - values_first + decomp[a].begin(), - comp); - b = c; - c += h; - } - - nseg = (nseg + 1) / 2; - h *= 2; - - #pragma omp barrier - } - } -#endif // THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE -} - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/swap_ranges.h b/compat/thrust/system/omp/detail/swap_ranges.h deleted file mode 100644 index e683aaa..0000000 --- a/compat/thrust/system/omp/detail/swap_ranges.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// omp inherits swap_ranges -#include - diff --git a/compat/thrust/system/omp/detail/tabulate.h b/compat/thrust/system/omp/detail/tabulate.h deleted file mode 100644 index da65d8e..0000000 --- a/compat/thrust/system/omp/detail/tabulate.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits tabulate -#include - diff --git a/compat/thrust/system/omp/detail/temporary_buffer.h b/compat/thrust/system/omp/detail/temporary_buffer.h deleted file mode 100644 index 628bd75..0000000 --- a/compat/thrust/system/omp/detail/temporary_buffer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special temporary buffer functions - diff --git a/compat/thrust/system/omp/detail/transform.h b/compat/thrust/system/omp/detail/transform.h deleted file mode 100644 index 70ce1f4..0000000 --- a/compat/thrust/system/omp/detail/transform.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// omp inherits transform -#include - diff --git a/compat/thrust/system/omp/detail/transform_reduce.h b/compat/thrust/system/omp/detail/transform_reduce.h deleted file mode 100644 index 23ed070..0000000 --- a/compat/thrust/system/omp/detail/transform_reduce.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits transform_reduce -#include - diff --git a/compat/thrust/system/omp/detail/transform_scan.h b/compat/thrust/system/omp/detail/transform_scan.h deleted file mode 100644 index fc2e55d..0000000 --- a/compat/thrust/system/omp/detail/transform_scan.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits transform_scan -#include - diff --git a/compat/thrust/system/omp/detail/uninitialized_copy.h b/compat/thrust/system/omp/detail/uninitialized_copy.h deleted file mode 100644 index 944f4ba..0000000 --- a/compat/thrust/system/omp/detail/uninitialized_copy.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits uninitialized_copy -#include - diff --git a/compat/thrust/system/omp/detail/uninitialized_fill.h b/compat/thrust/system/omp/detail/uninitialized_fill.h deleted file mode 100644 index b9d6de2..0000000 --- a/compat/thrust/system/omp/detail/uninitialized_fill.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits uninitialized_fill -#include - diff --git a/compat/thrust/system/omp/detail/unique.h b/compat/thrust/system/omp/detail/unique.h deleted file mode 100644 index 60c617b..0000000 --- a/compat/thrust/system/omp/detail/unique.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - ForwardIterator unique(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred); - - -template - OutputIterator unique_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/unique.inl b/compat/thrust/system/omp/detail/unique.inl deleted file mode 100644 index d66ac3b..0000000 --- a/compat/thrust/system/omp/detail/unique.inl +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - ForwardIterator unique(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - // omp prefers generic::unique to cpp::unique - return thrust::system::detail::generic::unique(exec,first,last,binary_pred); -} // end unique() - - -template - OutputIterator unique_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - // omp prefers generic::unique_copy to cpp::unique_copy - return thrust::system::detail::generic::unique_copy(exec,first,last,output,binary_pred); -} // end unique_copy() - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/unique_by_key.h b/compat/thrust/system/omp/detail/unique_by_key.h deleted file mode 100644 index 8fdde66..0000000 --- a/compat/thrust/system/omp/detail/unique_by_key.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - thrust::pair - unique_by_key(execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred); - - -template - thrust::pair - unique_by_key_copy(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/omp/detail/unique_by_key.inl b/compat/thrust/system/omp/detail/unique_by_key.inl deleted file mode 100644 index 644b5ed..0000000 --- a/compat/thrust/system/omp/detail/unique_by_key.inl +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - - -template - thrust::pair - unique_by_key(execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - // omp prefers generic::unique_by_key to cpp::unique_by_key - return thrust::system::detail::generic::unique_by_key(exec,keys_first,keys_last,values_first,binary_pred); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key_copy(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - // omp prefers generic::unique_by_key_copy to cpp::unique_by_key_copy - return thrust::system::detail::generic::unique_by_key_copy(exec,keys_first,keys_last,values_first,keys_output,values_output,binary_pred); -} // end unique_by_key_copy() - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/omp/detail/vector.inl b/compat/thrust/system/omp/detail/vector.inl deleted file mode 100644 index 32c845c..0000000 --- a/compat/thrust/system/omp/detail/vector.inl +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ - -template - vector - ::vector() - : super_t() -{} - -template - vector - ::vector(size_type n) - : super_t(n) -{} - -template - vector - ::vector(size_type n, const value_type &value) - : super_t(n,value) -{} - -template - vector - ::vector(const vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(const thrust::detail::vector_base &x) - : super_t(x) -{} - -template - template - vector - ::vector(const std::vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(InputIterator first, InputIterator last) - : super_t(first,last) -{} - -template - template - vector & - vector - ::operator=(const std::vector &x) -{ - super_t::operator=(x); - return *this; -} - -template - template - vector & - vector - ::operator=(const thrust::detail::vector_base &x) -{ - super_t::operator=(x); - return *this; -} - -} // end omp -} // end system -} // end thrust - diff --git a/compat/thrust/system/omp/execution_policy.h b/compat/thrust/system/omp/execution_policy.h deleted file mode 100644 index 7d5d1d8..0000000 --- a/compat/thrust/system/omp/execution_policy.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -/*! \file thrust/system/omp/execution_policy.h - * \brief Execution policies for Thrust's OpenMP system. - */ - -#include - -// get the execution policies definitions first -#include - -// get the definition of par -#include - -// now get all the algorithm definitions - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// define these entities here for the purpose of Doxygenating them -// they are actually defined elsewhere -#if 0 -namespace thrust -{ -namespace system -{ -namespace omp -{ - - -/*! \addtogroup execution_policies - * \{ - */ - - -/*! \p thrust::omp::execution_policy is the base class for all Thrust parallel execution - * policies which are derived from Thrust's OpenMP backend system. - */ -template -struct execution_policy : thrust::execution_policy -{}; - - -/*! \p omp::tag is a type representing Thrust's standard C++ backend system in C++'s type system. - * Iterators "tagged" with a type which is convertible to \p omp::tag assert that they may be - * "dispatched" to algorithm implementations in the \p omp system. - */ -struct tag : thrust::system::omp::execution_policy { unspecified }; - - -/*! \p thrust::omp::par is the parallel execution policy associated with Thrust's OpenMP - * backend system. - * - * Instead of relying on implicit algorithm dispatch through iterator system tags, users may - * directly target Thrust's OpenMP backend system by providing \p thrust::omp::par as an algorithm - * parameter. - * - * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such - * as \p thrust::omp::vector. - * - * The type of \p thrust::omp::par is implementation-defined. - * - * The following code snippet demonstrates how to use \p thrust::omp::par to explicitly dispatch an - * invocation of \p thrust::for_each to the OpenMP backend system: - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * printf("%d\n"); - * } - * }; - * ... - * int vec[3]; - * vec[0] = 0; vec[1] = 1; vec[2] = 2; - * - * thrust::for_each(thrust::omp::par, vec.begin(), vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - */ -static const unspecified par; - - -/*! \} - */ - - -} // end cpp -} // end system -} // end thrust -#endif - - diff --git a/compat/thrust/system/omp/memory.h b/compat/thrust/system/omp/memory.h deleted file mode 100644 index 0a23434..0000000 --- a/compat/thrust/system/omp/memory.h +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/omp/memory.h - * \brief Managing memory associated with Thrust's OpenMP system. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ - -template class pointer; - -} // end omp -} // end system -} // end thrust - - -/*! \cond - */ - -// specialize std::iterator_traits to avoid problems with the name of -// pointer's constructor shadowing its nested pointer type -// do this before pointer is defined so the specialization is correctly -// used inside the definition -namespace std -{ - -template - struct iterator_traits > -{ - private: - typedef thrust::system::omp::pointer ptr; - - public: - typedef typename ptr::iterator_category iterator_category; - typedef typename ptr::value_type value_type; - typedef typename ptr::difference_type difference_type; - typedef ptr pointer; - typedef typename ptr::reference reference; -}; // end iterator_traits - -} // end std - -/*! \endcond - */ - - -namespace thrust -{ -namespace system -{ - -/*! \addtogroup system_backends Systems - * \ingroup system - * \{ - */ - -/*! \namespace thrust::system::omp - * \brief \p thrust::system::omp is the namespace containing functionality for allocating, manipulating, - * and deallocating memory available to Thrust's OpenMP backend system. - * The identifiers are provided in a separate namespace underneath thrust::system - * for import convenience but are also aliased in the top-level thrust::omp - * namespace for easy access. - * - */ -namespace omp -{ - -// forward declaration of reference for pointer -template class reference; - -/*! \cond - */ - -// XXX nvcc + msvc have trouble instantiating reference below -// this is a workaround -namespace detail -{ - -template - struct reference_msvc_workaround -{ - typedef thrust::system::omp::reference type; -}; // end reference_msvc_workaround - -} // end detail - -/*! \endcond - */ - - -/*! \p pointer stores a pointer to an object allocated in memory available to the omp system. - * This type provides type safety when dispatching standard algorithms on ranges resident - * in omp memory. - * - * \p pointer has pointer semantics: it may be dereferenced and manipulated with pointer arithmetic. - * - * \p pointer can be created with the function \p omp::malloc, or by explicitly calling its constructor - * with a raw pointer. - * - * The raw pointer encapsulated by a \p pointer may be obtained by eiter its get member function - * or the \p raw_pointer_cast function. - * - * \note \p pointer is not a "smart" pointer; it is the programmer's responsibility to deallocate memory - * pointed to by \p pointer. - * - * \tparam T specifies the type of the pointee. - * - * \see omp::malloc - * \see omp::free - * \see raw_pointer_cast - */ -template - class pointer - : public thrust::pointer< - T, - thrust::system::omp::tag, - thrust::system::omp::reference, - thrust::system::omp::pointer - > -{ - /*! \cond - */ - - private: - typedef thrust::pointer< - T, - thrust::system::omp::tag, - //thrust::system::omp::reference, - typename detail::reference_msvc_workaround::type, - thrust::system::omp::pointer - > super_t; - - /*! \endcond - */ - - public: - // note that omp::pointer's member functions need __host__ __device__ - // to interoperate with nvcc + iterators' dereference member function - - /*! \p pointer's no-argument constructor initializes its encapsulated pointer to \c 0. - */ - __host__ __device__ - pointer() : super_t() {} - - /*! This constructor allows construction of a pointer from a T*. - * - * \param ptr A raw pointer to copy from, presumed to point to a location in memory - * accessible by the \p omp system. - * \tparam OtherT \p OtherT shall be convertible to \p T. - */ - template - __host__ __device__ - explicit pointer(OtherT *ptr) : super_t(ptr) {} - - /*! This constructor allows construction from another pointer-like object with related type. - * - * \param other The \p OtherPointer to copy. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::omp::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type * = 0) : super_t(other) {} - - /*! Assignment operator allows assigning from another pointer-like object with related type. - * - * \param other The other pointer-like object to assign from. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::omp::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - pointer & - >::type - operator=(const OtherPointer &other) - { - return super_t::operator=(other); - } -}; // end pointer - - -/*! \p reference is a wrapped reference to an object stored in memory available to the \p omp system. - * \p reference is the type of the result of dereferencing a \p omp::pointer. - * - * \tparam T Specifies the type of the referenced object. - */ -template - class reference - : public thrust::reference< - T, - thrust::system::omp::pointer, - thrust::system::omp::reference - > -{ - /*! \cond - */ - - private: - typedef thrust::reference< - T, - thrust::system::omp::pointer, - thrust::system::omp::reference - > super_t; - - /*! \endcond - */ - - public: - /*! \cond - */ - - typedef typename super_t::value_type value_type; - typedef typename super_t::pointer pointer; - - /*! \endcond - */ - - /*! This constructor initializes this \p reference to refer to an object - * pointed to by the given \p pointer. After this \p reference is constructed, - * it shall refer to the object pointed to by \p ptr. - * - * \param ptr A \p pointer to copy from. - */ - __host__ __device__ - explicit reference(const pointer &ptr) - : super_t(ptr) - {} - - /*! This constructor accepts a const reference to another \p reference of related type. - * After this \p reference is constructed, it shall refer to the same object as \p other. - * - * \param other A \p reference to copy from. - * \tparam OtherT The element type of the other \p reference. - * - * \note This constructor is templated primarily to allow initialization of reference - * from reference. - */ - template - __host__ __device__ - reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type * = 0) - : super_t(other) - {} - - /*! Copy assignment operator copy assigns from another \p reference of related type. - * - * \param other The other \p reference to assign from. - * \return *this - * \tparam OtherT The element type of the other \p reference. - */ - template - reference &operator=(const reference &other); - - /*! Assignment operator assigns from a \p value_type. - * - * \param x The \p value_type to assign from. - * \return *this - */ - reference &operator=(const value_type &x); -}; // end reference - -/*! Exchanges the values of two objects referred to by \p reference. - * \p x The first \p reference of interest. - * \p y The second \p reference ot interest. - */ -template -__host__ __device__ -void swap(reference x, reference y); - -/*! Allocates an area of memory available to Thrust's omp system. - * \param n Number of bytes to allocate. - * \return A omp::pointer pointing to the beginning of the newly - * allocated memory. A null omp::pointer is returned if - * an error occurs. - * \note The omp::pointer returned by this function must be - * deallocated with \p omp::free. - * \see omp::free - * \see std::malloc - */ -inline pointer malloc(std::size_t n); - -/*! Allocates a typed area of memory available to Thrust's omp system. - * \param n Number of elements to allocate. - * \return A omp::pointer pointing to the beginning of the newly - * allocated memory. A null omp::pointer is returned if - * an error occurs. - * \note The omp::pointer returned by this function must be - * deallocated with \p omp::free. - * \see omp::free - * \see std::malloc - */ -template -inline pointer malloc(std::size_t n); - -/*! Deallocates an area of memory previously allocated by omp::malloc. - * \param ptr A omp::pointer pointing to the beginning of an area - * of memory previously allocated with omp::malloc. - * \see omp::malloc - * \see std::free - */ -inline void free(pointer ptr); - -// XXX upon c++11 -// template using allocator = thrust::detail::malloc_allocator >; - -/*! \p omp::allocator is the default allocator used by the \p omp system's containers such as - * omp::vector if no user-specified allocator is provided. \p omp::allocator allocates - * (deallocates) storage with \p omp::malloc (\p omp::free). - */ -template - struct allocator - : thrust::detail::malloc_allocator< - T, - tag, - pointer - > -{ - /*! The \p rebind metafunction provides the type of an \p allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p allocator. - */ - typedef allocator other; - }; - - /*! No-argument constructor has no effect. - */ - __host__ __device__ - inline allocator() {} - - /*! Copy constructor has no effect. - */ - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Constructor from other \p allocator has no effect. - */ - template - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Destructor has no effect. - */ - __host__ __device__ - inline ~allocator() {} -}; // end allocator - -} // end omp - -/*! \} - */ - -} // end system - -/*! \namespace thrust::omp - * \brief \p thrust::omp is a top-level alias for thrust::system::omp. - */ -namespace omp -{ - -using thrust::system::omp::pointer; -using thrust::system::omp::reference; -using thrust::system::omp::malloc; -using thrust::system::omp::free; -using thrust::system::omp::allocator; - -} // end omp - -} // end thrust - -#include - diff --git a/compat/thrust/system/omp/vector.h b/compat/thrust/system/omp/vector.h deleted file mode 100644 index 5f45a91..0000000 --- a/compat/thrust/system/omp/vector.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/omp/vector.h - * \brief A dynamically-sizable array of elements which reside in memory available to - * Thrust's OpenMP system. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ - -// forward declaration of host_vector -// XXX why is this here? it doesn't seem necessary for anything below -template class host_vector; - -namespace system -{ -namespace omp -{ - -// XXX upon c++11 -// template > using vector = thrust::detail::vector_base; - -/*! \p omp::vector is a container that supports random access to elements, - * constant time removal of elements at the end, and linear time insertion - * and removal of elements at the beginning or in the middle. The number of - * elements in a \p omp::vector may vary dynamically; memory management is - * automatic. The elements contained in an \p omp::vector reside in memory - * available to the \p omp system. - * - * \tparam T The element type of the \p omp::vector. - * \tparam Allocator The allocator type of the \p omp::vector. Defaults to \p omp::allocator. - * - * \see http://www.sgi.com/tech/stl/Vector.html - * \see host_vector For the documentation of the complete interface which is - * shared by \p omp::vector - * \see device_vector - */ -template > - class vector - : public thrust::detail::vector_base -{ - /*! \cond - */ - private: - typedef thrust::detail::vector_base super_t; - /*! \endcond - */ - - public: - - /*! \cond - */ - typedef typename super_t::size_type size_type; - typedef typename super_t::value_type value_type; - /*! \endcond - */ - - /*! This constructor creates an empty \p omp::vector. - */ - vector(); - - /*! This constructor creates a \p omp::vector with \p n default-constructed elements. - * \param n The size of the \p omp::vector to create. - */ - explicit vector(size_type n); - - /*! This constructor creates a \p omp::vector with \p n copies of \p value. - * \param n The size of the \p omp::vector to create. - * \param value An element to copy. - */ - explicit vector(size_type n, const value_type &value); - - /*! Copy constructor copies from another \p omp::vector. - * \param x The other \p omp::vector to copy. - */ - vector(const vector &x); - - /*! This constructor copies from another Thrust vector-like object. - * \param x The other object to copy from. - */ - template - vector(const thrust::detail::vector_base &x); - - /*! This constructor copies from a \c std::vector. - * \param x The \c std::vector to copy from. - */ - template - vector(const std::vector &x); - - /*! This constructor creates an \p omp::vector by copying from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - vector(InputIterator first, InputIterator last); - - // XXX vector_base should take a Derived type so we don't have to define these superfluous assigns - - /*! Assignment operator assigns from a \c std::vector. - * \param x The \c std::vector to assign from. - * \return *this - */ - template - vector &operator=(const std::vector &x); - - /*! Assignment operator assigns from another Thrust vector-like object. - * \param x The other object to assign from. - * \return *this - */ - template - vector &operator=(const thrust::detail::vector_base &x); -}; // end vector - -} // end omp -} // end system - -// alias system::omp names at top-level -namespace omp -{ - -using thrust::system::omp::vector; - -} // end omp - -} // end thrust - -#include - diff --git a/compat/thrust/system/system_error.h b/compat/thrust/system/system_error.h deleted file mode 100644 index 6f94b61..0000000 --- a/compat/thrust/system/system_error.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file system/system_error.h - * \brief An exception object used to report error conditions that have an - * associated error code - */ - -#pragma once - -#include -#include -#include - -#include - -namespace thrust -{ - -namespace system -{ - -// [19.5.5] Class system_error - -// [19.5.5.1] Class system_error overview - -/*! \addtogroup system_diagnostics System Diagnostics - * \ingroup system - * \{ - */ - -/*! \brief The class \p system_error describes an exception object used to report error - * conditions that have an associated \p error_code. Such error conditions typically - * originate from the operating system or other low-level application program interfaces. - * - * Thrust uses \p system_error to report the error codes returned from device backends - * such as the CUDA runtime. - * - * The following code listing demonstrates how to catch a \p system_error to recover - * from an error. - * - * \code - * - * #include - * #include - * #include - * - * void terminate_gracefully(void) - * { - * // application-specific termination code here - * ... - * } - * - * int main(void) - * { - * try - * { - * thrust::device_vector vec; - * thrust::sort(vec.begin(), vec.end()); - * } - * catch(thrust::system_error e) - * { - * std::cerr << "Error inside sort: " << e.what() << std::endl; - * terminate_gracefully(); - * } - * - * return 0; - * } - * - * \endcode - * - * \note If an error represents an out-of-memory condition, implementations are encouraged - * to throw an exception object of type \p std::bad_alloc rather than \p system_error. - */ -class system_error - : public std::runtime_error -{ - public: - // [19.5.5.2] Class system_error members - - /*! Constructs an object of class \p system_error. - * \param ec The value returned by \p code(). - * \param what_arg A string to include in the result returned by \p what(). - * \post code() == ec. - * \post std::string(what()).find(what_arg) != string::npos. - */ - inline system_error(error_code ec, const std::string &what_arg); - - /*! Constructs an object of class \p system_error. - * \param ec The value returned by \p code(). - * \param what_arg A string to include in the result returned by \p what(). - * \post code() == ec. - * \post std::string(what()).find(what_arg) != string::npos. - */ - inline system_error(error_code ec, const char *what_arg); - - /*! Constructs an object of class \p system_error. - * \param ec The value returned by \p code(). - * \post code() == ec. - */ - inline system_error(error_code ec); - - /*! Constructs an object of class \p system_error. - * \param ev The error value used to create an \p error_code. - * \param ecat The \p error_category used to create an \p error_code. - * \param what_arg A string to include in the result returned by \p what(). - * \post code() == error_code(ev, ecat). - * \post std::string(what()).find(what_arg) != string::npos. - */ - inline system_error(int ev, const error_category &ecat, const std::string &what_arg); - - /*! Constructs an object of class \p system_error. - * \param ev The error value used to create an \p error_code. - * \param ecat The \p error_category used to create an \p error_code. - * \param what_arg A string to include in the result returned by \p what(). - * \post code() == error_code(ev, ecat). - * \post std::string(what()).find(what_arg) != string::npos. - */ - inline system_error(int ev, const error_category &ecat, const char *what_arg); - - /*! Constructs an object of class \p system_error. - * \param ev The error value used to create an \p error_code. - * \param ecat The \p error_category used to create an \p error_code. - * \post code() == error_code(ev, ecat). - */ - inline system_error(int ev, const error_category &ecat); - - /*! Destructor does not throw. - */ - inline virtual ~system_error(void) throw () {}; - - /*! Returns an object encoding the error. - * \return ec or error_code(ev, ecat), from the - * constructor, as appropriate. - */ - inline const error_code &code(void) const throw(); - - /*! Returns a human-readable string indicating the nature of the error. - * \return a string incorporating code().message() and the - * arguments supplied in the constructor. - */ - inline const char *what(void) const throw(); - - /*! \cond - */ - private: - error_code m_error_code; - mutable std::string m_what; - - /*! \endcond - */ -}; // end system_error - -} // end system - -/*! \} // end system_diagnostics - */ - -// import names into thrust:: -using system::system_error; - -} // end thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/adjacent_difference.h b/compat/thrust/system/tbb/detail/adjacent_difference.h deleted file mode 100644 index 37c9adc..0000000 --- a/compat/thrust/system/tbb/detail/adjacent_difference.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template - OutputIterator adjacent_difference(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - // tbb prefers generic::adjacent_difference to cpp::adjacent_difference - return thrust::system::detail::generic::adjacent_difference(exec, first, last, result, binary_op); -} // end adjacent_difference() - -} // end detail -} // end tbb -} // end system -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/assign_value.h b/compat/thrust/system/tbb/detail/assign_value.h deleted file mode 100644 index eda3b97..0000000 --- a/compat/thrust/system/tbb/detail/assign_value.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits assign_value -#include - diff --git a/compat/thrust/system/tbb/detail/binary_search.h b/compat/thrust/system/tbb/detail/binary_search.h deleted file mode 100644 index 8dec989..0000000 --- a/compat/thrust/system/tbb/detail/binary_search.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits binary_search -#include - diff --git a/compat/thrust/system/tbb/detail/copy.h b/compat/thrust/system/tbb/detail/copy.h deleted file mode 100644 index 7604e6f..0000000 --- a/compat/thrust/system/tbb/detail/copy.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template -OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -template -OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/copy.inl b/compat/thrust/system/tbb/detail/copy.inl deleted file mode 100644 index 6d354d0..0000000 --- a/compat/thrust/system/tbb/detail/copy.inl +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace dispatch -{ - -template - OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - thrust::incrementable_traversal_tag) -{ - return thrust::system::cpp::detail::copy(exec, first, last, result); -} // end copy() - - -template - OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - thrust::random_access_traversal_tag) -{ - return thrust::system::detail::generic::copy(exec, first, last, result); -} // end copy() - - -template - OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result, - thrust::incrementable_traversal_tag) -{ - return thrust::system::cpp::detail::copy_n(exec, first, n, result); -} // end copy_n() - - -template - OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result, - thrust::random_access_traversal_tag) -{ - return thrust::system::detail::generic::copy_n(exec, first, n, result); -} // end copy_n() - -} // end dispatch - - -template -OutputIterator copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result) -{ - typedef typename thrust::iterator_traversal::type traversal1; - typedef typename thrust::iterator_traversal::type traversal2; - - typedef typename thrust::detail::minimum_type::type traversal; - - // dispatch on minimum traversal - return thrust::system::tbb::detail::dispatch::copy(exec,first,last,result,traversal()); -} // end copy() - - - -template -OutputIterator copy_n(execution_policy &exec, - InputIterator first, - Size n, - OutputIterator result) -{ - typedef typename thrust::iterator_traversal::type traversal1; - typedef typename thrust::iterator_traversal::type traversal2; - - typedef typename thrust::detail::minimum_type::type traversal; - - // dispatch on minimum traversal - return thrust::system::tbb::detail::dispatch::copy_n(exec,first,n,result,traversal()); -} // end copy_n() - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/copy_if.h b/compat/thrust/system/tbb/detail/copy_if.h deleted file mode 100644 index ffbd4f8..0000000 --- a/compat/thrust/system/tbb/detail/copy_if.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - OutputIterator copy_if(tag, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -} // end detail -} // end tbb -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/copy_if.inl b/compat/thrust/system/tbb/detail/copy_if.inl deleted file mode 100644 index 4353b3b..0000000 --- a/compat/thrust/system/tbb/detail/copy_if.inl +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace copy_if_detail -{ - -template -struct body -{ - - InputIterator1 first; - InputIterator2 stencil; - OutputIterator result; - thrust::detail::host_function pred; - Size sum; - - body(InputIterator1 first, InputIterator2 stencil, OutputIterator result, Predicate pred) - : first(first), stencil(stencil), result(result), pred(pred), sum(0) - {} - - body(body& b, ::tbb::split) - : first(b.first), stencil(b.stencil), result(b.result), pred(b.pred), sum(0) - {} - - void operator()(const ::tbb::blocked_range& r, ::tbb::pre_scan_tag) - { - InputIterator2 iter = stencil + r.begin(); - - for (Size i = r.begin(); i != r.end(); ++i, ++iter) - { - if (pred(*iter)) - ++sum; - } - } - - void operator()(const ::tbb::blocked_range& r, ::tbb::final_scan_tag) - { - InputIterator1 iter1 = first + r.begin(); - InputIterator2 iter2 = stencil + r.begin(); - OutputIterator iter3 = result + sum; - - for (Size i = r.begin(); i != r.end(); ++i, ++iter1, ++iter2) - { - if (pred(*iter2)) - { - *iter3 = *iter1; - ++sum; - ++iter3; - } - } - } - - void reverse_join(body& b) - { - sum = b.sum + sum; - } - - void assign(body& b) - { - sum = b.sum; - } -}; // end body - -} // end copy_if_detail - -template - OutputIterator copy_if(tag, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - typedef typename thrust::iterator_difference::type Size; - typedef typename copy_if_detail::body Body; - - Size n = thrust::distance(first, last); - - if (n != 0) - { - Body body(first, stencil, result, pred); - ::tbb::parallel_scan(::tbb::blocked_range(0,n), body); - thrust::advance(result, body.sum); - } - - return result; -} // end copy_if() - -} // end detail -} // end tbb -} // end system -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/count.h b/compat/thrust/system/tbb/detail/count.h deleted file mode 100644 index da31ee8..0000000 --- a/compat/thrust/system/tbb/detail/count.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits count -#include - diff --git a/compat/thrust/system/tbb/detail/equal.h b/compat/thrust/system/tbb/detail/equal.h deleted file mode 100644 index 74e5518..0000000 --- a/compat/thrust/system/tbb/detail/equal.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits equal -#include - diff --git a/compat/thrust/system/tbb/detail/execution_policy.h b/compat/thrust/system/tbb/detail/execution_policy.h deleted file mode 100644 index 167d1dc..0000000 --- a/compat/thrust/system/tbb/detail/execution_policy.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -// put the canonical tag in the same ns as the backend's entry points -namespace tbb -{ -namespace detail -{ - -// this awkward sequence of definitions arise -// from the desire both for tag to derive -// from execution_policy and for execution_policy -// to convert to tag (when execution_policy is not -// an ancestor of tag) - -// forward declaration of tag -struct tag; - -// forward declaration of execution_policy -template struct execution_policy; - -// specialize execution_policy for tag -template<> - struct execution_policy - : thrust::system::cpp::detail::execution_policy -{}; - -// tag's definition comes before the -// generic definition of execution_policy -struct tag : execution_policy {}; - -// allow conversion to tag when it is not a successor -template - struct execution_policy - : thrust::system::cpp::detail::execution_policy -{ - // allow conversion to tag - inline operator tag () const - { - return tag(); - } -}; - -} // end detail - -// alias execution_policy and tag here -using thrust::system::tbb::detail::execution_policy; -using thrust::system::tbb::detail::tag; - -} // end tbb -} // end system - -// alias items at top-level -namespace tbb -{ - -using thrust::system::tbb::execution_policy; -using thrust::system::tbb::tag; - -} // end tbb -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/extrema.h b/compat/thrust/system/tbb/detail/extrema.h deleted file mode 100644 index 4715a89..0000000 --- a/compat/thrust/system/tbb/detail/extrema.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template -ForwardIterator max_element(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // tbb prefers generic::max_element to cpp::max_element - return thrust::system::detail::generic::max_element(exec, first, last, comp); -} // end max_element() - -template -ForwardIterator min_element(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // tbb prefers generic::min_element to cpp::min_element - return thrust::system::detail::generic::min_element(exec, first, last, comp); -} // end min_element() - -template -thrust::pair minmax_element(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate comp) -{ - // tbb prefers generic::minmax_element to cpp::minmax_element - return thrust::system::detail::generic::minmax_element(exec, first, last, comp); -} // end minmax_element() - -} // end detail -} // end tbb -} // end system -} // end thrust - - diff --git a/compat/thrust/system/tbb/detail/fill.h b/compat/thrust/system/tbb/detail/fill.h deleted file mode 100644 index 5219e1c..0000000 --- a/compat/thrust/system/tbb/detail/fill.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits fill -#include - diff --git a/compat/thrust/system/tbb/detail/find.h b/compat/thrust/system/tbb/detail/find.h deleted file mode 100644 index d351454..0000000 --- a/compat/thrust/system/tbb/detail/find.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template -InputIterator find_if(execution_policy &exec, - InputIterator first, - InputIterator last, - Predicate pred) -{ - // tbb prefers generic::find_if to cpp::find_if - return thrust::system::detail::generic::find_if(exec, first, last, pred); -} - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/for_each.h b/compat/thrust/system/tbb/detail/for_each.h deleted file mode 100644 index 573bb81..0000000 --- a/compat/thrust/system/tbb/detail/for_each.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template - RandomAccessIterator for_each(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - UnaryFunction f); - -template - RandomAccessIterator for_each_n(execution_policy &exec, - RandomAccessIterator first, - Size n, - UnaryFunction f); - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/for_each.inl b/compat/thrust/system/tbb/detail/for_each.inl deleted file mode 100644 index b09c7be..0000000 --- a/compat/thrust/system/tbb/detail/for_each.inl +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace for_each_detail -{ - -template - struct body -{ - RandomAccessIterator m_first; - UnaryFunction m_f; - - body(RandomAccessIterator first, UnaryFunction f) - : m_first(first), m_f(f) - {} - - void operator()(const ::tbb::blocked_range &r) const - { - // we assume that blocked_range specifies a contiguous range of integers - thrust::system::detail::internal::scalar::for_each_n(m_first + r.begin(), r.size(), m_f); - } // end operator()() -}; // end body - - -template - body - make_body(RandomAccessIterator first, UnaryFunction f) -{ - return body(first, f); -} // end make_body() - - -} // end for_each_detail - - -template -RandomAccessIterator for_each_n(execution_policy &, - RandomAccessIterator first, - Size n, - UnaryFunction f) -{ - ::tbb::parallel_for(::tbb::blocked_range(0,n), for_each_detail::make_body(first,f)); - - // return the end of the range - return first + n; -} // end for_each_n - - -template - RandomAccessIterator for_each(execution_policy &s, - RandomAccessIterator first, - RandomAccessIterator last, - UnaryFunction f) -{ - return tbb::detail::for_each_n(s, first, thrust::distance(first,last), f); -} // end for_each() - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/gather.h b/compat/thrust/system/tbb/detail/gather.h deleted file mode 100644 index dfb7d7f..0000000 --- a/compat/thrust/system/tbb/detail/gather.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits gather -#include - diff --git a/compat/thrust/system/tbb/detail/generate.h b/compat/thrust/system/tbb/detail/generate.h deleted file mode 100644 index 0cb33b9..0000000 --- a/compat/thrust/system/tbb/detail/generate.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits generate -#include - diff --git a/compat/thrust/system/tbb/detail/get_value.h b/compat/thrust/system/tbb/detail/get_value.h deleted file mode 100644 index e376e65..0000000 --- a/compat/thrust/system/tbb/detail/get_value.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits get_value -#include - diff --git a/compat/thrust/system/tbb/detail/inner_product.h b/compat/thrust/system/tbb/detail/inner_product.h deleted file mode 100644 index 351421a..0000000 --- a/compat/thrust/system/tbb/detail/inner_product.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits inner_product -#include - diff --git a/compat/thrust/system/tbb/detail/iter_swap.h b/compat/thrust/system/tbb/detail/iter_swap.h deleted file mode 100644 index 16176ec..0000000 --- a/compat/thrust/system/tbb/detail/iter_swap.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits iter_swap -#include - diff --git a/compat/thrust/system/tbb/detail/logical.h b/compat/thrust/system/tbb/detail/logical.h deleted file mode 100644 index b2a80de..0000000 --- a/compat/thrust/system/tbb/detail/logical.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits logical -#include - diff --git a/compat/thrust/system/tbb/detail/malloc_and_free.h b/compat/thrust/system/tbb/detail/malloc_and_free.h deleted file mode 100644 index 811a552..0000000 --- a/compat/thrust/system/tbb/detail/malloc_and_free.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits malloc and free -#include - diff --git a/compat/thrust/system/tbb/detail/memory.inl b/compat/thrust/system/tbb/detail/memory.inl deleted file mode 100644 index 420a8a1..0000000 --- a/compat/thrust/system/tbb/detail/memory.inl +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ - - -template - template - reference & - reference - ::operator=(const reference &other) -{ - return super_t::operator=(other); -} // end reference::operator=() - -template - reference & - reference - ::operator=(const value_type &x) -{ - return super_t::operator=(x); -} // end reference::operator=() - -template -__host__ __device__ -void swap(reference a, reference b) -{ - a.swap(b); -} // end swap() - -namespace detail -{ - -// XXX circular #inclusion problems cause the compiler to believe that cpp::malloc -// is not defined -// WAR the problem by using adl to call cpp::malloc, which requires it to depend -// on a template parameter -template - pointer malloc_workaround(Tag t, std::size_t n) -{ - return pointer(malloc(t, n)); -} // end malloc_workaround() - -// XXX circular #inclusion problems cause the compiler to believe that cpp::free -// is not defined -// WAR the problem by using adl to call cpp::free, which requires it to depend -// on a template parameter -template - void free_workaround(Tag t, pointer ptr) -{ - free(t, ptr.get()); -} // end free_workaround() - -} // end detail - -inline pointer malloc(std::size_t n) -{ - // XXX this is how we'd like to implement this function, - // if not for circular #inclusion problems: - // - // return pointer(thrust::system::cpp::malloc(n)) - // - return detail::malloc_workaround(cpp::tag(), n); -} // end malloc() - -template -pointer malloc(std::size_t n) -{ - pointer raw_ptr = thrust::system::tbb::malloc(sizeof(T) * n); - return pointer(reinterpret_cast(raw_ptr.get())); -} // end malloc() - -inline void free(pointer ptr) -{ - // XXX this is how we'd like to implement this function, - // if not for circular #inclusion problems: - // - // thrust::system::cpp::free(ptr) - // - detail::free_workaround(cpp::tag(), ptr); -} // end free() - -} // end tbb -} // end system -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/merge.h b/compat/thrust/system/tbb/detail/merge.h deleted file mode 100644 index 7b203ec..0000000 --- a/compat/thrust/system/tbb/detail/merge.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template -OutputIterator merge(execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp); - -template -thrust::pair - merge_by_key(execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first3, - InputIterator4 values_first4, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp); - -} // end detail -} // end tbb -} // end system -} // end thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/merge.inl b/compat/thrust/system/tbb/detail/merge.inl deleted file mode 100644 index cc902af..0000000 --- a/compat/thrust/system/tbb/detail/merge.inl +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace merge_detail -{ - -template -struct range -{ - InputIterator1 first1, last1; - InputIterator2 first2, last2; - OutputIterator result; - StrictWeakOrdering comp; - size_t grain_size; - - range(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp, - size_t grain_size = 1024) - : first1(first1), last1(last1), - first2(first2), last2(last2), - result(result), comp(comp), grain_size(grain_size) - {} - - range(range& r, ::tbb::split) - : first1(r.first1), last1(r.last1), - first2(r.first2), last2(r.last2), - result(r.result), comp(r.comp), grain_size(r.grain_size) - { - // we can assume n1 and n2 are not both 0 - size_t n1 = thrust::distance(first1, last1); - size_t n2 = thrust::distance(first2, last2); - - InputIterator1 mid1 = first1; - InputIterator2 mid2 = first2; - - if (n1 > n2) - { - mid1 += n1 / 2; - mid2 = thrust::system::detail::internal::scalar::lower_bound(first2, last2, raw_reference_cast(*mid1), comp); - } - else - { - mid2 += n2 / 2; - mid1 = thrust::system::detail::internal::scalar::upper_bound(first1, last1, raw_reference_cast(*mid2), comp); - } - - // set first range to [first1, mid1), [first2, mid2), result - r.last1 = mid1; - r.last2 = mid2; - - // set second range to [mid1, last1), [mid2, last2), result + (mid1 - first1) + (mid2 - first2) - first1 = mid1; - first2 = mid2; - result += thrust::distance(r.first1, mid1) + thrust::distance(r.first2, mid2); - } - - bool empty(void) const - { - return (first1 == last1) && (first2 == last2); - } - - bool is_divisible(void) const - { - return static_cast(thrust::distance(first1, last1) + thrust::distance(first2, last2)) > grain_size; - } -}; - -struct body -{ - template - void operator()(Range& r) const - { - thrust::system::detail::internal::scalar::merge - (r.first1, r.last1, - r.first2, r.last2, - r.result, - r.comp); - } -}; - -} // end namespace merge_detail - -namespace merge_by_key_detail -{ - -template -struct range -{ - InputIterator1 keys_first1, keys_last1; - InputIterator2 keys_first2, keys_last2; - InputIterator3 values_first1; - InputIterator4 values_first2; - OutputIterator1 keys_result; - OutputIterator2 values_result; - StrictWeakOrdering comp; - size_t grain_size; - - range(InputIterator1 keys_first1, InputIterator1 keys_last1, - InputIterator2 keys_first2, InputIterator2 keys_last2, - InputIterator3 values_first1, - InputIterator4 values_first2, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp, - size_t grain_size = 1024) - : keys_first1(keys_first1), keys_last1(keys_last1), - keys_first2(keys_first2), keys_last2(keys_last2), - values_first1(values_first1), - values_first2(values_first2), - keys_result(keys_result), values_result(values_result), - comp(comp), grain_size(grain_size) - {} - - range(range& r, ::tbb::split) - : keys_first1(r.keys_first1), keys_last1(r.keys_last1), - keys_first2(r.keys_first2), keys_last2(r.keys_last2), - values_first1(r.values_first1), - values_first2(r.values_first2), - keys_result(r.keys_result), values_result(r.values_result), - comp(r.comp), grain_size(r.grain_size) - { - // we can assume n1 and n2 are not both 0 - size_t n1 = thrust::distance(keys_first1, keys_last1); - size_t n2 = thrust::distance(keys_first2, keys_last2); - - InputIterator1 mid1 = keys_first1; - InputIterator2 mid2 = keys_first2; - - if (n1 > n2) - { - mid1 += n1 / 2; - mid2 = thrust::system::detail::internal::scalar::lower_bound(keys_first2, keys_last2, raw_reference_cast(*mid1), comp); - } - else - { - mid2 += n2 / 2; - mid1 = thrust::system::detail::internal::scalar::upper_bound(keys_first1, keys_last1, raw_reference_cast(*mid2), comp); - } - - // set first range to [keys_first1, mid1), [keys_first2, mid2), keys_result, values_result - r.keys_last1 = mid1; - r.keys_last2 = mid2; - - // set second range to [mid1, keys_last1), [mid2, keys_last2), keys_result + (mid1 - keys_first1) + (mid2 - keys_first2), values_result + (mid1 - keys_first1) + (mid2 - keys_first2) - keys_first1 = mid1; - keys_first2 = mid2; - values_first1 += thrust::distance(r.keys_first1, mid1); - values_first2 += thrust::distance(r.keys_first2, mid2); - keys_result += thrust::distance(r.keys_first1, mid1) + thrust::distance(r.keys_first2, mid2); - values_result += thrust::distance(r.keys_first1, mid1) + thrust::distance(r.keys_first2, mid2); - } - - bool empty(void) const - { - return (keys_first1 == keys_last1) && (keys_first2 == keys_last2); - } - - bool is_divisible(void) const - { - return static_cast(thrust::distance(keys_first1, keys_last1) + thrust::distance(keys_first2, keys_last2)) > grain_size; - } -}; - -struct body -{ - template - void operator()(Range& r) const - { - thrust::system::detail::internal::scalar::merge_by_key - (r.keys_first1, r.keys_last1, - r.keys_first2, r.keys_last2, - r.values_first1, - r.values_first2, - r.keys_result, - r.values_result, - r.comp); - } -}; - -} // end namespace merge_by_key_detail - - -template -OutputIterator merge(execution_policy &exec, - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - StrictWeakOrdering comp) -{ - typedef typename merge_detail::range Range; - typedef merge_detail::body Body; - Range range(first1, last1, first2, last2, result, comp); - Body body; - - ::tbb::parallel_for(range, body); - - thrust::advance(result, thrust::distance(first1, last1) + thrust::distance(first2, last2)); - - return result; -} // end merge() - -template -thrust::pair - merge_by_key(execution_policy &exec, - InputIterator1 keys_first1, - InputIterator1 keys_last1, - InputIterator2 keys_first2, - InputIterator2 keys_last2, - InputIterator3 values_first3, - InputIterator4 values_first4, - OutputIterator1 keys_result, - OutputIterator2 values_result, - StrictWeakOrdering comp) -{ - typedef typename merge_by_key_detail::range Range; - typedef merge_by_key_detail::body Body; - - Range range(keys_first1, keys_last1, keys_first2, keys_last2, values_first3, values_first4, keys_result, values_result, comp); - Body body; - - ::tbb::parallel_for(range, body); - - thrust::advance(keys_result, thrust::distance(keys_first1, keys_last1) + thrust::distance(keys_first2, keys_last2)); - thrust::advance(values_result, thrust::distance(keys_first1, keys_last1) + thrust::distance(keys_first2, keys_last2)); - - return thrust::make_pair(keys_result,values_result); -} - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/mismatch.h b/compat/thrust/system/tbb/detail/mismatch.h deleted file mode 100644 index 03980cf..0000000 --- a/compat/thrust/system/tbb/detail/mismatch.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits mismatch -#include - diff --git a/compat/thrust/system/tbb/detail/par.h b/compat/thrust/system/tbb/detail/par.h deleted file mode 100644 index 74801ab..0000000 --- a/compat/thrust/system/tbb/detail/par.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -struct par_t : thrust::system::tbb::detail::execution_policy -{ - par_t() : thrust::system::tbb::detail::execution_policy() {} - - template - thrust::detail::execute_with_allocator - operator()(Allocator &alloc) const - { - return thrust::detail::execute_with_allocator(alloc); - } -}; - - -} // end detail - - -static const detail::par_t par; - - -} // end tbb -} // end system - - -// alias par here -namespace tbb -{ - - -using thrust::system::tbb::par; - - -} // end tbb -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/partition.h b/compat/thrust/system/tbb/detail/partition.h deleted file mode 100644 index af37121..0000000 --- a/compat/thrust/system/tbb/detail/partition.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/partition.inl b/compat/thrust/system/tbb/detail/partition.inl deleted file mode 100644 index 1e421e1..0000000 --- a/compat/thrust/system/tbb/detail/partition.inl +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - // tbb prefers generic::stable_partition to cpp::stable_partition - return thrust::system::detail::generic::stable_partition(exec, first, last, pred); -} // end stable_partition() - - -template - ForwardIterator stable_partition(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - // tbb prefers generic::stable_partition to cpp::stable_partition - return thrust::system::detail::generic::stable_partition(exec, first, last, stencil, pred); -} // end stable_partition() - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - // tbb prefers generic::stable_partition_copy to cpp::stable_partition_copy - return thrust::system::detail::generic::stable_partition_copy(exec, first, last, out_true, out_false, pred); -} // end stable_partition_copy() - - -template - thrust::pair - stable_partition_copy(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator1 out_true, - OutputIterator2 out_false, - Predicate pred) -{ - // tbb prefers generic::stable_partition_copy to cpp::stable_partition_copy - return thrust::system::detail::generic::stable_partition_copy(exec, first, last, stencil, out_true, out_false, pred); -} // end stable_partition_copy() - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/reduce.h b/compat/thrust/system/tbb/detail/reduce.h deleted file mode 100644 index 83a7cc3..0000000 --- a/compat/thrust/system/tbb/detail/reduce.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file reduce.h - * \brief TBB implementation of reduce. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - OutputType reduce(execution_policy &exec, - InputIterator begin, - InputIterator end, - OutputType init, - BinaryFunction binary_op); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/reduce.inl b/compat/thrust/system/tbb/detail/reduce.inl deleted file mode 100644 index c249852..0000000 --- a/compat/thrust/system/tbb/detail/reduce.inl +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace reduce_detail -{ - -template -struct body -{ - RandomAccessIterator first; - OutputType sum; - bool first_call; // TBB can invoke operator() multiple times on the same body - thrust::detail::host_function binary_op; - - // note: we only initalize sum with init to avoid calling OutputType's default constructor - body(RandomAccessIterator first, OutputType init, BinaryFunction binary_op) - : first(first), sum(init), first_call(true), binary_op(binary_op) - {} - - // note: we only initalize sum with b.sum to avoid calling OutputType's default constructor - body(body& b, ::tbb::split) - : first(b.first), sum(b.sum), first_call(true), binary_op(b.binary_op) - {} - - template - void operator()(const ::tbb::blocked_range &r) - { - // we assume that blocked_range specifies a contiguous range of integers - - if (r.empty()) return; // nothing to do - - RandomAccessIterator iter = first + r.begin(); - - OutputType temp = thrust::raw_reference_cast(*iter); - - ++iter; - - for (Size i = r.begin() + 1; i != r.end(); ++i, ++iter) - temp = binary_op(temp, *iter); - - - if (first_call) - { - // first time body has been invoked - first_call = false; - sum = temp; - } - else - { - // body has been previously invoked, accumulate temp into sum - sum = binary_op(sum, temp); - } - } // end operator()() - - void join(body& b) - { - sum = binary_op(sum, b.sum); - } -}; // end body - -} // end reduce_detail - - -template - OutputType reduce(execution_policy &exec, - InputIterator begin, - InputIterator end, - OutputType init, - BinaryFunction binary_op) -{ - typedef typename thrust::iterator_difference::type Size; - - Size n = thrust::distance(begin, end); - - if (n == 0) - { - return init; - } - else - { - typedef typename reduce_detail::body Body; - Body reduce_body(begin, init, binary_op); - ::tbb::parallel_reduce(::tbb::blocked_range(0,n), reduce_body); - return binary_op(init, reduce_body.sum); - } -} - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/reduce_by_key.h b/compat/thrust/system/tbb/detail/reduce_by_key.h deleted file mode 100644 index 0149a76..0000000 --- a/compat/thrust/system/tbb/detail/reduce_by_key.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - thrust::pair - reduce_by_key(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/reduce_by_key.inl b/compat/thrust/system/tbb/detail/reduce_by_key.inl deleted file mode 100644 index 10d2d8b..0000000 --- a/compat/thrust/system/tbb/detail/reduce_by_key.inl +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace reduce_by_key_detail -{ - - -template - inline L divide_ri(const L x, const R y) -{ - return (x + (y - 1)) / y; -} - - -template - struct partial_sum_type - : thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::detail::eval_if< - thrust::detail::is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - > -{}; - - -template - struct partial_sum_type - : thrust::detail::eval_if< - thrust::detail::has_result_type::value, - thrust::detail::result_type, - thrust::iterator_value - > -{}; - - -template - thrust::pair< - InputIterator1, - thrust::pair< - typename InputIterator1::value_type, - typename partial_sum_type::type - > - > - reduce_last_segment_backward(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - typename thrust::iterator_difference::type n = keys_last - keys_first; - - // reverse the ranges and consume from the end - thrust::reverse_iterator keys_first_r(keys_last); - thrust::reverse_iterator keys_last_r(keys_first); - thrust::reverse_iterator values_first_r(values_first + n); - - typename InputIterator1::value_type result_key = *keys_first_r; - typename partial_sum_type::type result_value = *values_first_r; - - // consume the entirety of the first key's sequence - for(++keys_first_r, ++values_first_r; - (keys_first_r != keys_last_r) && binary_pred(*keys_first_r, result_key); - ++keys_first_r, ++values_first_r) - { - result_value = binary_op(result_value, *values_first_r); - } - - return thrust::make_pair(keys_first_r.base(), thrust::make_pair(result_key, result_value)); -} - - -template - thrust::tuple< - OutputIterator1, - OutputIterator2, - typename InputIterator1::value_type, - typename partial_sum_type::type - > - reduce_by_key_with_carry(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - // first, consume the last sequence to produce the carry - // XXX is there an elegant way to pose this such that we don't need to default construct carry? - thrust::pair< - typename InputIterator1::value_type, - typename partial_sum_type::type - > carry; - - thrust::tie(keys_last, carry) = reduce_last_segment_backward(keys_first, keys_last, values_first, binary_pred, binary_op); - - // finish with sequential reduce_by_key - thrust::cpp::tag seq; - thrust::tie(keys_output, values_output) = - thrust::reduce_by_key(seq, keys_first, keys_last, values_first, keys_output, values_output, binary_pred, binary_op); - - return thrust::make_tuple(keys_output, values_output, carry.first, carry.second); -} - - -template - bool interval_has_carry(size_t interval_idx, size_t interval_size, size_t num_intervals, Iterator tail_flags) -{ - // to discover whether the interval has a carry, look at the tail_flag corresponding to its last element - // the final interval never has a carry by definition - return (interval_idx + 1 < num_intervals) ? !tail_flags[(interval_idx + 1) * interval_size - 1] : false; -} - - -template - struct serial_reduce_by_key_body -{ - typedef typename thrust::iterator_difference::type size_type; - - Iterator1 keys_first; - Iterator2 values_first; - Iterator3 result_offset; - Iterator4 keys_result; - Iterator5 values_result; - Iterator6 carry_result; - - size_type n; - size_type interval_size; - size_type num_intervals; - - BinaryPredicate binary_pred; - BinaryFunction binary_op; - - serial_reduce_by_key_body(Iterator1 keys_first, Iterator2 values_first, Iterator3 result_offset, Iterator4 keys_result, Iterator5 values_result, Iterator6 carry_result, size_type n, size_type interval_size, size_type num_intervals, BinaryPredicate binary_pred, BinaryFunction binary_op) - : keys_first(keys_first), values_first(values_first), - result_offset(result_offset), - keys_result(keys_result), - values_result(values_result), - carry_result(carry_result), - n(n), - interval_size(interval_size), - num_intervals(num_intervals), - binary_pred(binary_pred), - binary_op(binary_op) - {} - - void operator()(const ::tbb::blocked_range &r) const - { - assert(r.size() == 1); - - const size_type interval_idx = r.begin(); - - const size_type offset_to_first = interval_size * interval_idx; - const size_type offset_to_last = thrust::min(n, offset_to_first + interval_size); - - Iterator1 my_keys_first = keys_first + offset_to_first; - Iterator1 my_keys_last = keys_first + offset_to_last; - Iterator2 my_values_first = values_first + offset_to_first; - Iterator3 my_result_offset = result_offset + interval_idx; - Iterator4 my_keys_result = keys_result + *my_result_offset; - Iterator5 my_values_result = values_result + *my_result_offset; - Iterator6 my_carry_result = carry_result + interval_idx; - - // consume the rest of the interval with reduce_by_key - typedef typename thrust::iterator_value::type key_type; - typedef typename partial_sum_type::type value_type; - - // XXX is there a way to pose this so that we don't require default construction of carry? - thrust::pair carry; - - thrust::tie(my_keys_result, my_values_result, carry.first, carry.second) = - reduce_by_key_with_carry(my_keys_first, - my_keys_last, - my_values_first, - my_keys_result, - my_values_result, - binary_pred, - binary_op); - - // store to carry only when we actually have a carry - // store to my_keys_result & my_values_result otherwise - - // create tail_flags so we can check for a carry - thrust::detail::tail_flags flags = thrust::detail::make_tail_flags(keys_first, keys_first + n, binary_pred); - - if(interval_has_carry(interval_idx, interval_size, num_intervals, flags.begin())) - { - // we can ignore the carry's key - // XXX because the carry result is uninitialized, we should copy construct - *my_carry_result = carry.second; - } - else - { - *my_keys_result = carry.first; - *my_values_result = carry.second; - } - } -}; - - -template - serial_reduce_by_key_body - make_serial_reduce_by_key_body(Iterator1 keys_first, Iterator2 values_first, Iterator3 result_offset, Iterator4 keys_result, Iterator5 values_result, Iterator6 carry_result, typename thrust::iterator_difference::type n, size_t interval_size, size_t num_intervals, BinaryPredicate binary_pred, BinaryFunction binary_op) -{ - return serial_reduce_by_key_body(keys_first, values_first, result_offset, keys_result, values_result, carry_result, n, interval_size, num_intervals, binary_pred, binary_op); -} - - -} // end reduce_by_key_detail - - -template - thrust::pair - reduce_by_key(thrust::tbb::execution_policy &exec, - Iterator1 keys_first, Iterator1 keys_last, - Iterator2 values_first, - Iterator3 keys_result, - Iterator4 values_result, - BinaryPredicate binary_pred, - BinaryFunction binary_op) -{ - - typedef typename thrust::iterator_difference::type difference_type; - difference_type n = keys_last - keys_first; - if(n == 0) return thrust::make_pair(keys_result, values_result); - - // XXX this value is a tuning opportunity - const difference_type parallelism_threshold = 10000; - - if(n < parallelism_threshold) - { - // don't bother parallelizing for small n - thrust::cpp::tag seq; - return thrust::reduce_by_key(seq, keys_first, keys_last, values_first, keys_result, values_result, binary_pred, binary_op); - } - - // count the number of processors - const unsigned int p = thrust::max(1u, ::tbb::tbb_thread::hardware_concurrency()); - - // generate O(P) intervals of sequential work - // XXX oversubscribing is a tuning opportunity - const unsigned int subscription_rate = 1; - difference_type interval_size = thrust::min(parallelism_threshold, thrust::max(n, n / (subscription_rate * p))); - difference_type num_intervals = reduce_by_key_detail::divide_ri(n, interval_size); - - // decompose the input into intervals of size N / num_intervals - // add one extra element to this vector to store the size of the entire result - thrust::detail::temporary_array interval_output_offsets(0, exec, num_intervals + 1); - - // first count the number of tail flags in each interval - thrust::detail::tail_flags tail_flags = thrust::detail::make_tail_flags(keys_first, keys_last, binary_pred); - thrust::system::tbb::detail::reduce_intervals(exec, tail_flags.begin(), tail_flags.end(), interval_size, interval_output_offsets.begin() + 1, thrust::plus()); - interval_output_offsets[0] = 0; - - // scan the counts to get each body's output offset - thrust::cpp::tag seq; - thrust::inclusive_scan(seq, - interval_output_offsets.begin() + 1, interval_output_offsets.end(), - interval_output_offsets.begin() + 1); - - // do a reduce_by_key serially in each thread - // the final interval never has a carry by definition, so don't reserve space for it - typedef typename reduce_by_key_detail::partial_sum_type::type carry_type; - thrust::detail::temporary_array carries(0, exec, num_intervals - 1); - - // force grainsize == 1 with simple_partioner() - ::tbb::parallel_for(::tbb::blocked_range(0, num_intervals, 1), - reduce_by_key_detail::make_serial_reduce_by_key_body(keys_first, values_first, interval_output_offsets.begin(), keys_result, values_result, carries.begin(), n, interval_size, num_intervals, binary_pred, binary_op), - ::tbb::simple_partitioner()); - - difference_type size_of_result = interval_output_offsets[num_intervals]; - - // sequentially accumulate the carries - // note that the last interval does not have a carry - // XXX find a way to express this loop via a sequential algorithm, perhaps reduce_by_key - for(typename thrust::detail::temporary_array::size_type i = 0; i < carries.size(); ++i) - { - // if our interval has a carry, then we need to sum the carry to the next interval's output offset - // if it does not have a carry, then we need to ignore carry_value[i] - if(reduce_by_key_detail::interval_has_carry(i, interval_size, num_intervals, tail_flags.begin())) - { - difference_type output_idx = interval_output_offsets[i+1]; - - values_result[output_idx] = binary_op(values_result[output_idx], carries[i]); - } - } - - return thrust::make_pair(keys_result + size_of_result, values_result + size_of_result); -} - - -} // end detail -} // end tbb -} // end system -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/reduce_intervals.h b/compat/thrust/system/tbb/detail/reduce_intervals.h deleted file mode 100644 index 0647ffd..0000000 --- a/compat/thrust/system/tbb/detail/reduce_intervals.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace reduce_intervals_detail -{ - - -template - inline L divide_ri(const L x, const R y) -{ - return (x + (y - 1)) / y; -} - - -template - struct body -{ - RandomAccessIterator1 first; - RandomAccessIterator2 result; - Size n, interval_size; - BinaryFunction binary_op; - - body(RandomAccessIterator1 first, RandomAccessIterator2 result, Size n, Size interval_size, BinaryFunction binary_op) - : first(first), result(result), n(n), interval_size(interval_size), binary_op(binary_op) - {} - - void operator()(const ::tbb::blocked_range &r) const - { - assert(r.size() == 1); - - Size interval_idx = r.begin(); - - Size offset_to_first = interval_size * interval_idx; - Size offset_to_last = thrust::min(n, offset_to_first + interval_size); - - RandomAccessIterator1 my_first = first + offset_to_first; - RandomAccessIterator1 my_last = first + offset_to_last; - - thrust::cpp::tag seq; - - // carefully pass the init value for the interval with raw_reference_cast - typedef typename BinaryFunction::result_type sum_type; - result[interval_idx] = - thrust::reduce(seq, my_first + 1, my_last, sum_type(thrust::raw_reference_cast(*my_first)), binary_op); - } -}; - - -template - body - make_body(RandomAccessIterator1 first, RandomAccessIterator2 result, Size n, Size interval_size, BinaryFunction binary_op) -{ - return body(first, result, n, interval_size, binary_op); -} - - -} // end reduce_intervals_detail - - -template - void reduce_intervals(thrust::tbb::execution_policy &, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - Size interval_size, - RandomAccessIterator2 result, - BinaryFunction binary_op) -{ - typename thrust::iterator_difference::type n = last - first; - - Size num_intervals = reduce_intervals_detail::divide_ri(n, interval_size); - - ::tbb::parallel_for(::tbb::blocked_range(0, num_intervals, 1), reduce_intervals_detail::make_body(first, result, Size(n), interval_size, binary_op), ::tbb::simple_partitioner()); -} - - -template - void reduce_intervals(thrust::tbb::execution_policy &exec, - RandomAccessIterator1 first, - RandomAccessIterator1 last, - Size interval_size, - RandomAccessIterator2 result) -{ - typedef typename thrust::iterator_value::type value_type; - - return thrust::system::tbb::detail::reduce_intervals(exec, first, last, interval_size, result, thrust::plus()); -} - - -} // end detail -} // end tbb -} // end system -} // end thrust - diff --git a/compat/thrust/system/tbb/detail/remove.h b/compat/thrust/system/tbb/detail/remove.h deleted file mode 100644 index 48cbb5c..0000000 --- a/compat/thrust/system/tbb/detail/remove.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace omp -{ -namespace detail -{ - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred); - - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred); - - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred); - - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred); - - -} // end namespace detail -} // end namespace omp -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/remove.inl b/compat/thrust/system/tbb/detail/remove.inl deleted file mode 100644 index 01916c5..0000000 --- a/compat/thrust/system/tbb/detail/remove.inl +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - Predicate pred) -{ - // tbb prefers generic::remove_if to cpp::remove_if - return thrust::system::detail::generic::remove_if(exec, first, last, pred); -} - - -template - ForwardIterator remove_if(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - InputIterator stencil, - Predicate pred) -{ - // tbb prefers generic::remove_if to cpp::remove_if - return thrust::system::detail::generic::remove_if(exec, first, last, stencil, pred); -} - - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - Predicate pred) -{ - // tbb prefers generic::remove_copy_if to cpp::remove_copy_if - return thrust::system::detail::generic::remove_copy_if(exec, first, last, result, pred); -} - -template - OutputIterator remove_copy_if(execution_policy &exec, - InputIterator1 first, - InputIterator1 last, - InputIterator2 stencil, - OutputIterator result, - Predicate pred) -{ - // tbb prefers generic::remove_copy_if to cpp::remove_copy_if - return thrust::system::detail::generic::remove_copy_if(exec, first, last, stencil, result, pred); -} - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/replace.h b/compat/thrust/system/tbb/detail/replace.h deleted file mode 100644 index c48555d..0000000 --- a/compat/thrust/system/tbb/detail/replace.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits this algorithm -#include - diff --git a/compat/thrust/system/tbb/detail/reverse.h b/compat/thrust/system/tbb/detail/reverse.h deleted file mode 100644 index 04923d1..0000000 --- a/compat/thrust/system/tbb/detail/reverse.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits reverse -#include - diff --git a/compat/thrust/system/tbb/detail/scan.h b/compat/thrust/system/tbb/detail/scan.h deleted file mode 100644 index ed5cacd..0000000 --- a/compat/thrust/system/tbb/detail/scan.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file scan.h - * \brief TBB implementations of scan functions. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template - OutputIterator inclusive_scan(tag, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op); - - -template - OutputIterator exclusive_scan(tag, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/scan.inl b/compat/thrust/system/tbb/detail/scan.inl deleted file mode 100644 index 4887824..0000000 --- a/compat/thrust/system/tbb/detail/scan.inl +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace scan_detail -{ - -template -struct inclusive_body -{ - InputIterator input; - OutputIterator output; - thrust::detail::host_function binary_op; - ValueType sum; - bool first_call; - - inclusive_body(InputIterator input, OutputIterator output, BinaryFunction binary_op, ValueType dummy) - : input(input), output(output), binary_op(binary_op), sum(dummy), first_call(true) - {} - - inclusive_body(inclusive_body& b, ::tbb::split) - : input(b.input), output(b.output), binary_op(b.binary_op), sum(b.sum), first_call(true) - {} - - template - void operator()(const ::tbb::blocked_range& r, ::tbb::pre_scan_tag) - { - InputIterator iter = input + r.begin(); - - ValueType temp = *iter; - - ++iter; - - for (Size i = r.begin() + 1; i != r.end(); ++i, ++iter) - temp = binary_op(temp, *iter); - - if (first_call) - sum = temp; - else - sum = binary_op(sum, temp); - - first_call = false; - } - - template - void operator()(const ::tbb::blocked_range& r, ::tbb::final_scan_tag) - { - InputIterator iter1 = input + r.begin(); - OutputIterator iter2 = output + r.begin(); - - if (first_call) - { - *iter2 = sum = *iter1; - ++iter1; - ++iter2; - for (Size i = r.begin() + 1; i != r.end(); ++i, ++iter1, ++iter2) - *iter2 = sum = binary_op(sum, *iter1); - } - else - { - for (Size i = r.begin(); i != r.end(); ++i, ++iter1, ++iter2) - *iter2 = sum = binary_op(sum, *iter1); - } - - first_call = false; - } - - void reverse_join(inclusive_body& b) - { - sum = binary_op(b.sum, sum); - } - - void assign(inclusive_body& b) - { - sum = b.sum; - } -}; - - -template -struct exclusive_body -{ - InputIterator input; - OutputIterator output; - thrust::detail::host_function binary_op; - ValueType sum; - bool first_call; - - exclusive_body(InputIterator input, OutputIterator output, BinaryFunction binary_op, ValueType init) - : input(input), output(output), binary_op(binary_op), sum(init), first_call(true) - {} - - exclusive_body(exclusive_body& b, ::tbb::split) - : input(b.input), output(b.output), binary_op(b.binary_op), sum(b.sum), first_call(true) - {} - - template - void operator()(const ::tbb::blocked_range& r, ::tbb::pre_scan_tag) - { - InputIterator iter = input + r.begin(); - - ValueType temp = *iter; - - ++iter; - - for (Size i = r.begin() + 1; i != r.end(); ++i, ++iter) - temp = binary_op(temp, *iter); - - if (first_call && r.begin() > 0) - sum = temp; - else - sum = binary_op(sum, temp); - - first_call = false; - } - - template - void operator()(const ::tbb::blocked_range& r, ::tbb::final_scan_tag) - { - InputIterator iter1 = input + r.begin(); - OutputIterator iter2 = output + r.begin(); - - for (Size i = r.begin(); i != r.end(); ++i, ++iter1, ++iter2) - { - ValueType temp = binary_op(sum, *iter1); - *iter2 = sum; - sum = temp; - } - - first_call = false; - } - - void reverse_join(exclusive_body& b) - { - sum = binary_op(b.sum, sum); - } - - void assign(exclusive_body& b) - { - sum = b.sum; - } -}; - -} // end scan_detail - - - -template - OutputIterator inclusive_scan(tag, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryFunction binary_op) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - using namespace thrust::detail; - - typedef typename eval_if< - has_result_type::value, - result_type, - eval_if< - is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - typedef typename thrust::iterator_difference::type Size; - - Size n = thrust::distance(first, last); - - if (n != 0) - { - typedef typename scan_detail::inclusive_body Body; - Body scan_body(first, result, binary_op, *first); - ::tbb::parallel_scan(::tbb::blocked_range(0,n), scan_body); - } - - thrust::advance(result, n); - - return result; -} - - -template - OutputIterator exclusive_scan(tag, - InputIterator first, - InputIterator last, - OutputIterator result, - T init, - BinaryFunction binary_op) -{ - // the pseudocode for deducing the type of the temporary used below: - // - // if BinaryFunction is AdaptableBinaryFunction - // TemporaryType = AdaptableBinaryFunction::result_type - // else if OutputIterator is a "pure" output iterator - // TemporaryType = InputIterator::value_type - // else - // TemporaryType = OutputIterator::value_type - // - // XXX upon c++0x, TemporaryType needs to be: - // result_of::type - - using namespace thrust::detail; - - typedef typename eval_if< - has_result_type::value, - result_type, - eval_if< - is_output_iterator::value, - thrust::iterator_value, - thrust::iterator_value - > - >::type ValueType; - - typedef typename thrust::iterator_difference::type Size; - - Size n = thrust::distance(first, last); - - if (n != 0) - { - typedef typename scan_detail::exclusive_body Body; - Body scan_body(first, result, binary_op, init); - ::tbb::parallel_scan(::tbb::blocked_range(0,n), scan_body); - } - - thrust::advance(result, n); - - return result; -} - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/scan_by_key.h b/compat/thrust/system/tbb/detail/scan_by_key.h deleted file mode 100644 index cad4fc1..0000000 --- a/compat/thrust/system/tbb/detail/scan_by_key.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits scan_by_key -#include - diff --git a/compat/thrust/system/tbb/detail/scatter.h b/compat/thrust/system/tbb/detail/scatter.h deleted file mode 100644 index c48555d..0000000 --- a/compat/thrust/system/tbb/detail/scatter.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits this algorithm -#include - diff --git a/compat/thrust/system/tbb/detail/sequence.h b/compat/thrust/system/tbb/detail/sequence.h deleted file mode 100644 index 811d8f5..0000000 --- a/compat/thrust/system/tbb/detail/sequence.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits sequence -#include - diff --git a/compat/thrust/system/tbb/detail/set_operations.h b/compat/thrust/system/tbb/detail/set_operations.h deleted file mode 100644 index 687edb2..0000000 --- a/compat/thrust/system/tbb/detail/set_operations.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits set_operations -#include - diff --git a/compat/thrust/system/tbb/detail/sort.h b/compat/thrust/system/tbb/detail/sort.h deleted file mode 100644 index 3b6f630..0000000 --- a/compat/thrust/system/tbb/detail/sort.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - -template - void stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp); - -template - void stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 keys_first, - RandomAccessIterator1 keys_last, - RandomAccessIterator2 values_first, - StrictWeakOrdering comp); - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/sort.inl b/compat/thrust/system/tbb/detail/sort.inl deleted file mode 100644 index f292789..0000000 --- a/compat/thrust/system/tbb/detail/sort.inl +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ -namespace sort_detail -{ - -// TODO tune this based on data type and comp -const static int threshold = 128 * 1024; - -template -void merge_sort(execution_policy &exec, Iterator1 first1, Iterator1 last1, Iterator2 first2, StrictWeakOrdering comp, bool inplace); - -template -struct merge_sort_closure -{ - execution_policy &exec; - Iterator1 first1, last1; - Iterator2 first2; - StrictWeakOrdering comp; - bool inplace; - - merge_sort_closure(execution_policy &exec, Iterator1 first1, Iterator1 last1, Iterator2 first2, StrictWeakOrdering comp, bool inplace) - : exec(exec), first1(first1), last1(last1), first2(first2), comp(comp), inplace(inplace) - {} - - void operator()(void) const - { - merge_sort(exec, first1, last1, first2, comp, inplace); - } -}; - - -template -void merge_sort(execution_policy &exec, Iterator1 first1, Iterator1 last1, Iterator2 first2, StrictWeakOrdering comp, bool inplace) -{ - typedef typename thrust::iterator_difference::type difference_type; - - difference_type n = thrust::distance(first1, last1); - - if (n < threshold) - { - thrust::system::detail::internal::scalar::stable_sort(first1, last1, comp); - - if (!inplace) - thrust::system::detail::internal::scalar::copy(first1, last1, first2); - - return; - } - - Iterator1 mid1 = first1 + (n / 2); - Iterator2 mid2 = first2 + (n / 2); - Iterator2 last2 = first2 + n; - - typedef merge_sort_closure Closure; - - Closure left (exec, first1, mid1, first2, comp, !inplace); - Closure right(exec, mid1, last1, mid2, comp, !inplace); - - ::tbb::parallel_invoke(left, right); - - if (inplace) thrust::merge(exec, first2, mid2, mid2, last2, first1, comp); - else thrust::merge(exec, first1, mid1, mid1, last1, first2, comp); -} - -} // end namespace sort_detail - - -namespace sort_by_key_detail -{ - -// TODO tune this based on data type and comp -const static int threshold = 128 * 1024; - -template -void merge_sort_by_key(execution_policy &exec, - Iterator1 first1, - Iterator1 last1, - Iterator2 first2, - Iterator3 first3, - Iterator4 first4, - StrictWeakOrdering comp, - bool inplace); - -template -struct merge_sort_by_key_closure -{ - execution_policy &exec; - Iterator1 first1, last1; - Iterator2 first2; - Iterator3 first3; - Iterator4 first4; - StrictWeakOrdering comp; - bool inplace; - - merge_sort_by_key_closure(execution_policy &exec, - Iterator1 first1, - Iterator1 last1, - Iterator2 first2, - Iterator3 first3, - Iterator4 first4, - StrictWeakOrdering comp, - bool inplace) - : exec(exec), first1(first1), last1(last1), first2(first2), first3(first3), first4(first4), comp(comp), inplace(inplace) - {} - - void operator()(void) const - { - merge_sort_by_key(exec, first1, last1, first2, first3, first4, comp, inplace); - } -}; - - -template -void merge_sort_by_key(execution_policy &exec, - Iterator1 first1, - Iterator1 last1, - Iterator2 first2, - Iterator3 first3, - Iterator4 first4, - StrictWeakOrdering comp, - bool inplace) -{ - typedef typename thrust::iterator_difference::type difference_type; - - difference_type n = thrust::distance(first1, last1); - - Iterator1 mid1 = first1 + (n / 2); - Iterator2 mid2 = first2 + (n / 2); - Iterator3 mid3 = first3 + (n / 2); - Iterator4 mid4 = first4 + (n / 2); - Iterator2 last2 = first2 + n; - Iterator3 last3 = first3 + n; - - if (n < threshold) - { - thrust::system::detail::internal::scalar::stable_sort_by_key(first1, last1, first2, comp); - - if (!inplace) - { - thrust::system::detail::internal::scalar::copy(first1, last1, first3); - thrust::system::detail::internal::scalar::copy(first2, last2, first4); - } - - return; - } - - typedef merge_sort_by_key_closure Closure; - - Closure left (exec, first1, mid1, first2, first3, first4, comp, !inplace); - Closure right(exec, mid1, last1, mid2, mid3, mid4, comp, !inplace); - - ::tbb::parallel_invoke(left, right); - - if(inplace) - { - thrust::merge_by_key(exec, first3, mid3, mid3, last3, first4, mid4, first1, first2, comp); - } - else - { - thrust::merge_by_key(exec, first1, mid1, mid1, last1, first2, mid2, first3, first4, comp); - } -} - -} // end namespace sort_detail - -template -void stable_sort(execution_policy &exec, - RandomAccessIterator first, - RandomAccessIterator last, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_value::type key_type; - - thrust::detail::temporary_array temp(exec, first, last); - - sort_detail::merge_sort(exec, first, last, temp.begin(), comp, true); -} - -template - void stable_sort_by_key(execution_policy &exec, - RandomAccessIterator1 first1, - RandomAccessIterator1 last1, - RandomAccessIterator2 first2, - StrictWeakOrdering comp) -{ - typedef typename thrust::iterator_value::type key_type; - typedef typename thrust::iterator_value::type val_type; - - RandomAccessIterator2 last2 = first2 + thrust::distance(first1, last1); - - thrust::detail::temporary_array temp1(exec, first1, last1); - thrust::detail::temporary_array temp2(exec, first2, last2); - - sort_by_key_detail::merge_sort_by_key(exec, first1, last1, first2, temp1.begin(), temp2.begin(), comp, true); -} - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/swap_ranges.h b/compat/thrust/system/tbb/detail/swap_ranges.h deleted file mode 100644 index 15f8f55..0000000 --- a/compat/thrust/system/tbb/detail/swap_ranges.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// tbb inherits swap_ranges -#include - diff --git a/compat/thrust/system/tbb/detail/tabulate.h b/compat/thrust/system/tbb/detail/tabulate.h deleted file mode 100644 index da65d8e..0000000 --- a/compat/thrust/system/tbb/detail/tabulate.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits tabulate -#include - diff --git a/compat/thrust/system/tbb/detail/temporary_buffer.h b/compat/thrust/system/tbb/detail/temporary_buffer.h deleted file mode 100644 index 628bd75..0000000 --- a/compat/thrust/system/tbb/detail/temporary_buffer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system has no special temporary buffer functions - diff --git a/compat/thrust/system/tbb/detail/transform.h b/compat/thrust/system/tbb/detail/transform.h deleted file mode 100644 index 70ce1f4..0000000 --- a/compat/thrust/system/tbb/detail/transform.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// omp inherits transform -#include - diff --git a/compat/thrust/system/tbb/detail/transform_reduce.h b/compat/thrust/system/tbb/detail/transform_reduce.h deleted file mode 100644 index 23ed070..0000000 --- a/compat/thrust/system/tbb/detail/transform_reduce.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits transform_reduce -#include - diff --git a/compat/thrust/system/tbb/detail/transform_scan.h b/compat/thrust/system/tbb/detail/transform_scan.h deleted file mode 100644 index fc2e55d..0000000 --- a/compat/thrust/system/tbb/detail/transform_scan.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits transform_scan -#include - diff --git a/compat/thrust/system/tbb/detail/uninitialized_copy.h b/compat/thrust/system/tbb/detail/uninitialized_copy.h deleted file mode 100644 index 944f4ba..0000000 --- a/compat/thrust/system/tbb/detail/uninitialized_copy.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits uninitialized_copy -#include - diff --git a/compat/thrust/system/tbb/detail/uninitialized_fill.h b/compat/thrust/system/tbb/detail/uninitialized_fill.h deleted file mode 100644 index b9d6de2..0000000 --- a/compat/thrust/system/tbb/detail/uninitialized_fill.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -// this system inherits uninitialized_fill -#include - diff --git a/compat/thrust/system/tbb/detail/unique.h b/compat/thrust/system/tbb/detail/unique.h deleted file mode 100644 index 34538ca..0000000 --- a/compat/thrust/system/tbb/detail/unique.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - ForwardIterator unique(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred); - - -template - OutputIterator unique_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/unique.inl b/compat/thrust/system/tbb/detail/unique.inl deleted file mode 100644 index 06e6a30..0000000 --- a/compat/thrust/system/tbb/detail/unique.inl +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - ForwardIterator unique(execution_policy &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred) -{ - // tbb prefers generic::unique to cpp::unique - return thrust::system::detail::generic::unique(exec,first,last,binary_pred); -} // end unique() - - -template - OutputIterator unique_copy(execution_policy &exec, - InputIterator first, - InputIterator last, - OutputIterator output, - BinaryPredicate binary_pred) -{ - // tbb prefers generic::unique_copy to cpp::unique_copy - return thrust::system::detail::generic::unique_copy(exec,first,last,output,binary_pred); -} // end unique_copy() - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/unique_by_key.h b/compat/thrust/system/tbb/detail/unique_by_key.h deleted file mode 100644 index c6d0532..0000000 --- a/compat/thrust/system/tbb/detail/unique_by_key.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - thrust::pair - unique_by_key(execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred); - - -template - thrust::pair - unique_by_key_copy(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred); - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - -#include - diff --git a/compat/thrust/system/tbb/detail/unique_by_key.inl b/compat/thrust/system/tbb/detail/unique_by_key.inl deleted file mode 100644 index 7747ca4..0000000 --- a/compat/thrust/system/tbb/detail/unique_by_key.inl +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ -namespace detail -{ - - -template - thrust::pair - unique_by_key(execution_policy &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred) -{ - // tbb prefers generic::unique_by_key to cpp::unique_by_key - return thrust::system::detail::generic::unique_by_key(exec,keys_first,keys_last,values_first,binary_pred); -} // end unique_by_key() - - -template - thrust::pair - unique_by_key_copy(execution_policy &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_output, - OutputIterator2 values_output, - BinaryPredicate binary_pred) -{ - // tbb prefers generic::unique_by_key_copy to cpp::unique_by_key_copy - return thrust::system::detail::generic::unique_by_key_copy(exec,keys_first,keys_last,values_first,keys_output,values_output,binary_pred); -} // end unique_by_key_copy() - - -} // end namespace detail -} // end namespace tbb -} // end namespace system -} // end namespace thrust - diff --git a/compat/thrust/system/tbb/detail/vector.inl b/compat/thrust/system/tbb/detail/vector.inl deleted file mode 100644 index d87e670..0000000 --- a/compat/thrust/system/tbb/detail/vector.inl +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ - -template - vector - ::vector() - : super_t() -{} - -template - vector - ::vector(size_type n) - : super_t(n) -{} - -template - vector - ::vector(size_type n, const value_type &value) - : super_t(n,value) -{} - -template - vector - ::vector(const vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(const thrust::detail::vector_base &x) - : super_t(x) -{} - -template - template - vector - ::vector(const std::vector &x) - : super_t(x) -{} - -template - template - vector - ::vector(InputIterator first, InputIterator last) - : super_t(first,last) -{} - -template - template - vector & - vector - ::operator=(const std::vector &x) -{ - super_t::operator=(x); - return *this; -} - -template - template - vector & - vector - ::operator=(const thrust::detail::vector_base &x) -{ - super_t::operator=(x); - return *this; -} - -} // end tbb -} // end system -} // end thrust - diff --git a/compat/thrust/system/tbb/execution_policy.h b/compat/thrust/system/tbb/execution_policy.h deleted file mode 100644 index c462586..0000000 --- a/compat/thrust/system/tbb/execution_policy.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -/*! \file thrust/system/tbb/execution_policy.h - * \brief Execution policies for Thrust's TBB system. - */ - -#include - -// get the execution policies definitions first -#include - -// get the definition of par -#include - -// now get all the algorithm definitions - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// define these entities here for the purpose of Doxygenating them -// they are actually defined elsewhere -#if 0 -namespace thrust -{ -namespace system -{ -namespace tbb -{ - - -/*! \addtogroup execution_policies - * \{ - */ - - -/*! \p thrust::tbb::execution_policy is the base class for all Thrust parallel execution - * policies which are derived from Thrust's TBB backend system. - */ -template -struct execution_policy : thrust::execution_policy -{}; - - -/*! \p tbb::tag is a type representing Thrust's TBB backend system in C++'s type system. - * Iterators "tagged" with a type which is convertible to \p tbb::tag assert that they may be - * "dispatched" to algorithm implementations in the \p tbb system. - */ -struct tag : thrust::system::tbb::execution_policy { unspecified }; - - -/*! \p thrust::tbb::par is the parallel execution policy associated with Thrust's TBB - * backend system. - * - * Instead of relying on implicit algorithm dispatch through iterator system tags, users may - * directly target Thrust's TBB backend system by providing \p thrust::tbb::par as an algorithm - * parameter. - * - * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such - * as \p thrust::tbb::vector. - * - * The type of \p thrust::tbb::par is implementation-defined. - * - * The following code snippet demonstrates how to use \p thrust::tbb::par to explicitly dispatch an - * invocation of \p thrust::for_each to the TBB backend system: - * - * \code - * #include - * #include - * #include - * - * struct printf_functor - * { - * __host__ __device__ - * void operator()(int x) - * { - * printf("%d\n"); - * } - * }; - * ... - * int vec[3]; - * vec[0] = 0; vec[1] = 1; vec[2] = 2; - * - * thrust::for_each(thrust::tbb::par, vec.begin(), vec.end(), printf_functor()); - * - * // 0 1 2 is printed to standard output in some unspecified order - * \endcode - */ -static const unspecified par; - - -/*! \} - */ - - -} // end tbb -} // end system -} // end thrust -#endif - - diff --git a/compat/thrust/system/tbb/memory.h b/compat/thrust/system/tbb/memory.h deleted file mode 100644 index deea7ee..0000000 --- a/compat/thrust/system/tbb/memory.h +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/tbb/memory.h - * \brief Managing memory associated with Thrust's TBB system. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ - -template class pointer; - -} // end tbb -} // end system -} // end thrust - - -/*! \cond - */ - -// specialize std::iterator_traits to avoid problems with the name of -// pointer's constructor shadowing its nested pointer type -// do this before pointer is defined so the specialization is correctly -// used inside the definition -namespace std -{ - -template - struct iterator_traits > -{ - private: - typedef thrust::system::tbb::pointer ptr; - - public: - typedef typename ptr::iterator_category iterator_category; - typedef typename ptr::value_type value_type; - typedef typename ptr::difference_type difference_type; - typedef ptr pointer; - typedef typename ptr::reference reference; -}; // end iterator_traits - -} // end std - -/*! \endcond - */ - - -namespace thrust -{ -namespace system -{ - -/*! \addtogroup system_backends Systems - * \ingroup system - * \{ - */ - -/*! \namespace thrust::system::tbb - * \brief \p thrust::system::tbb is the namespace containing functionality for allocating, manipulating, - * and deallocating memory available to Thrust's TBB backend system. - * The identifiers are provided in a separate namespace underneath thrust::system - * for import convenience but are also aliased in the top-level thrust::tbb - * namespace for easy access. - * - */ -namespace tbb -{ - -// forward declaration of reference for pointer -template class reference; - -/*! \cond - */ - -// XXX nvcc + msvc have trouble instantiating reference below -// this is a workaround -namespace detail -{ - -template - struct reference_msvc_workaround -{ - typedef thrust::system::tbb::reference type; -}; // end reference_msvc_workaround - -} // end detail - -/*! \endcond - */ - - -/*! \p pointer stores a pointer to an object allocated in memory available to the tbb system. - * This type provides type safety when dispatching standard algorithms on ranges resident - * in tbb memory. - * - * \p pointer has pointer semantics: it may be dereferenced and manipulated with pointer arithmetic. - * - * \p pointer can be created with the function \p tbb::malloc, or by explicitly calling its constructor - * with a raw pointer. - * - * The raw pointer encapsulated by a \p pointer may be obtained by eiter its get member function - * or the \p raw_pointer_cast function. - * - * \note \p pointer is not a "smart" pointer; it is the programmer's responsibility to deallocate memory - * pointed to by \p pointer. - * - * \tparam T specifies the type of the pointee. - * - * \see tbb::malloc - * \see tbb::free - * \see raw_pointer_cast - */ -template - class pointer - : public thrust::pointer< - T, - thrust::system::tbb::tag, - thrust::system::tbb::reference, - thrust::system::tbb::pointer - > -{ - /*! \cond - */ - - private: - typedef thrust::pointer< - T, - thrust::system::tbb::tag, - //thrust::system::tbb::reference, - typename detail::reference_msvc_workaround::type, - thrust::system::tbb::pointer - > super_t; - - /*! \endcond - */ - - public: - // note that tbb::pointer's member functions need __host__ __device__ - // to interoperate with nvcc + iterators' dereference member function - - /*! \p pointer's no-argument constructor initializes its encapsulated pointer to \c 0. - */ - __host__ __device__ - pointer() : super_t() {} - - /*! This constructor allows construction of a pointer from a T*. - * - * \param ptr A raw pointer to copy from, presumed to point to a location in memory - * accessible by the \p tbb system. - * \tparam OtherT \p OtherT shall be convertible to \p T. - */ - template - __host__ __device__ - explicit pointer(OtherT *ptr) : super_t(ptr) {} - - /*! This constructor allows construction from another pointer-like object with related type. - * - * \param other The \p OtherPointer to copy. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::tbb::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - pointer(const OtherPointer &other, - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer - >::type * = 0) : super_t(other) {} - - /*! Assignment operator allows assigning from another pointer-like object with related type. - * - * \param other The other pointer-like object to assign from. - * \tparam OtherPointer The system tag associated with \p OtherPointer shall be convertible - * to \p thrust::system::tbb::tag and its element type shall be convertible to \p T. - */ - template - __host__ __device__ - typename thrust::detail::enable_if_pointer_is_convertible< - OtherPointer, - pointer, - pointer & - >::type - operator=(const OtherPointer &other) - { - return super_t::operator=(other); - } -}; // end pointer - - -/*! \p reference is a wrapped reference to an object stored in memory available to the \p tbb system. - * \p reference is the type of the result of dereferencing a \p tbb::pointer. - * - * \tparam T Specifies the type of the referenced object. - */ -template - class reference - : public thrust::reference< - T, - thrust::system::tbb::pointer, - thrust::system::tbb::reference - > -{ - /*! \cond - */ - - private: - typedef thrust::reference< - T, - thrust::system::tbb::pointer, - thrust::system::tbb::reference - > super_t; - - /*! \endcond - */ - - public: - /*! \cond - */ - - typedef typename super_t::value_type value_type; - typedef typename super_t::pointer pointer; - - /*! \endcond - */ - - /*! This constructor initializes this \p reference to refer to an object - * pointed to by the given \p pointer. After this \p reference is constructed, - * it shall refer to the object pointed to by \p ptr. - * - * \param ptr A \p pointer to copy from. - */ - __host__ __device__ - explicit reference(const pointer &ptr) - : super_t(ptr) - {} - - /*! This constructor accepts a const reference to another \p reference of related type. - * After this \p reference is constructed, it shall refer to the same object as \p other. - * - * \param other A \p reference to copy from. - * \tparam OtherT The element type of the other \p reference. - * - * \note This constructor is templated primarily to allow initialization of reference - * from reference. - */ - template - __host__ __device__ - reference(const reference &other, - typename thrust::detail::enable_if_convertible< - typename reference::pointer, - pointer - >::type * = 0) - : super_t(other) - {} - - /*! Copy assignment operator copy assigns from another \p reference of related type. - * - * \param other The other \p reference to assign from. - * \return *this - * \tparam OtherT The element type of the other \p reference. - */ - template - reference &operator=(const reference &other); - - /*! Assignment operator assigns from a \p value_type. - * - * \param x The \p value_type to assign from. - * \return *this - */ - reference &operator=(const value_type &x); -}; // end reference - -/*! Exchanges the values of two objects referred to by \p reference. - * \p x The first \p reference of interest. - * \p y The second \p reference ot interest. - */ -template -__host__ __device__ -void swap(reference x, reference y); - -/*! Allocates an area of memory available to Thrust's tbb system. - * \param n Number of bytes to allocate. - * \return A tbb::pointer pointing to the beginning of the newly - * allocated memory. A null tbb::pointer is returned if - * an error occurs. - * \note The tbb::pointer returned by this function must be - * deallocated with \p tbb::free. - * \see tbb::free - * \see std::malloc - */ -inline pointer malloc(std::size_t n); - -/*! Allocates a typed area of memory available to Thrust's tbb system. - * \param n Number of elements to allocate. - * \return A tbb::pointer pointing to the beginning of the newly - * allocated memory. A null tbb::pointer is returned if - * an error occurs. - * \note The tbb::pointer returned by this function must be - * deallocated with \p tbb::free. - * \see tbb::free - * \see std::malloc - */ -template -inline pointer malloc(std::size_t n); - -/*! Deallocates an area of memory previously allocated by tbb::malloc. - * \param ptr A tbb::pointer pointing to the beginning of an area - * of memory previously allocated with tbb::malloc. - * \see tbb::malloc - * \see std::free - */ -inline void free(pointer ptr); - -// XXX upon c++11 -// template using allocator = thrust::detail::malloc_allocator >; - -/*! \p tbb::allocator is the default allocator used by the \p tbb system's containers such as - * tbb::vector if no user-specified allocator is provided. \p tbb::allocator allocates - * (deallocates) storage with \p tbb::malloc (\p tbb::free). - */ -template - struct allocator - : thrust::detail::malloc_allocator< - T, - tag, - pointer - > -{ - /*! The \p rebind metafunction provides the type of an \p allocator - * instantiated with another type. - * - * \tparam U The other type to use for instantiation. - */ - template - struct rebind - { - /*! The typedef \p other gives the type of the rebound \p allocator. - */ - typedef allocator other; - }; - - /*! No-argument constructor has no effect. - */ - __host__ __device__ - inline allocator() {} - - /*! Copy constructor has no effect. - */ - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Constructor from other \p allocator has no effect. - */ - template - __host__ __device__ - inline allocator(const allocator &) {} - - /*! Destructor has no effect. - */ - __host__ __device__ - inline ~allocator() {} -}; // end allocator - -} // end tbb - -/*! \} - */ - -} // end system - -/*! \namespace thrust::tbb - * \brief \p thrust::tbb is a top-level alias for thrust::system::tbb. - */ -namespace tbb -{ - -using thrust::system::tbb::pointer; -using thrust::system::tbb::reference; -using thrust::system::tbb::malloc; -using thrust::system::tbb::free; -using thrust::system::tbb::allocator; - -} // end tbb - -} // end thrust - -#include - diff --git a/compat/thrust/system/tbb/vector.h b/compat/thrust/system/tbb/vector.h deleted file mode 100644 index 1c49c3f..0000000 --- a/compat/thrust/system/tbb/vector.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in ctbbliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system/tbb/vector.h - * \brief A dynamically-sizable array of elements which reside in memory available to - * Thrust's TBB system. - */ - -#pragma once - -#include -#include -#include -#include - -namespace thrust -{ -namespace system -{ -namespace tbb -{ - -// XXX upon c++11 -// template > using vector = thrust::detail::vector_base; - -/*! \p tbb::vector is a container that supports random access to elements, - * constant time removal of elements at the end, and linear time insertion - * and removal of elements at the beginning or in the middle. The number of - * elements in a \p tbb::vector may vary dynamically; memory management is - * automatic. The elements contained in a \p tbb::vector reside in memory - * available to the \p tbb system. - * - * \tparam T The element type of the \p tbb::vector. - * \tparam Allocator The allocator type of the \p tbb::vector. Defaults to \p tbb::allocator. - * - * \see http://www.sgi.com/tech/stl/Vector.html - * \see host_vector For the documentation of the complete interface which is - * shared by \p tbb::vector - * \see device_vector - */ -template > - class vector - : public thrust::detail::vector_base -{ - /*! \cond - */ - private: - typedef thrust::detail::vector_base super_t; - /*! \endcond - */ - - public: - - /*! \cond - */ - typedef typename super_t::size_type size_type; - typedef typename super_t::value_type value_type; - /*! \endcond - */ - - /*! This constructor creates an empty \p tbb::vector. - */ - vector(); - - /*! This constructor creates a \p tbb::vector with \p n default-constructed elements. - * \param n The size of the \p tbb::vector to create. - */ - explicit vector(size_type n); - - /*! This constructor creates a \p tbb::vector with \p n copies of \p value. - * \param n The size of the \p tbb::vector to create. - * \param value An element to copy. - */ - explicit vector(size_type n, const value_type &value); - - /*! Copy constructor copies from another \p tbb::vector. - * \param x The other \p tbb::vector to copy. - */ - vector(const vector &x); - - /*! This constructor copies from another Thrust vector-like object. - * \param x The other object to copy from. - */ - template - vector(const thrust::detail::vector_base &x); - - /*! This constructor copies from a \c std::vector. - * \param x The \c std::vector to copy from. - */ - template - vector(const std::vector &x); - - /*! This constructor creates a \p tbb::vector by copying from a range. - * \param first The beginning of the range. - * \param last The end of the range. - */ - template - vector(InputIterator first, InputIterator last); - - // XXX vector_base should take a Derived type so we don't have to define these superfluous assigns - - /*! Assignment operator assigns from a \c std::vector. - * \param x The \c std::vector to assign from. - * \return *this - */ - template - vector &operator=(const std::vector &x); - - /*! Assignment operator assigns from another Thrust vector-like object. - * \param x The other object to assign from. - * \return *this - */ - template - vector &operator=(const thrust::detail::vector_base &x); -}; // end vector - -} // end tbb -} // end system - -// alias system::tbb names at top-level -namespace tbb -{ - -using thrust::system::tbb::vector; - -} // end tbb - -} // end thrust - -#include - diff --git a/compat/thrust/system_error.h b/compat/thrust/system_error.h deleted file mode 100644 index ce88fe6..0000000 --- a/compat/thrust/system_error.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file thrust/system_error.h - * \brief System diagnostics - */ - -#pragma once - -#include - -namespace thrust -{ - -/*! \addtogroup system System Access - * \{ - */ - -/*! \namespace thrust::system - * \brief \p thrust::system is the namespace which contains functionality for manipulating - * memory specific to one of Thrust's backend systems. It also contains functionality - * for reporting error conditions originating from the operating system or other - * low-level application program interfaces such as the CUDA runtime. - * They are provided in a separate namespace for import convenience but are - * also aliased in the top-level \p thrust namespace for easy access. - */ -namespace system -{ -} // end system - -/*! \} // end system - */ - -} // end thrust - -#include -#include - diff --git a/compat/thrust/tabulate.h b/compat/thrust/tabulate.h deleted file mode 100644 index c87edf0..0000000 --- a/compat/thrust/tabulate.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file tabulate.h - * \brief Fills a range with the tabulation of a function - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup transformations - * \{ - */ - - -/*! \p tabulate fills the range [first, last) with the value of a function applied to each - * element's index. - * - * For each iterator \c i in the range [first, last), \p tabulate performs the assignment - * *i = unary_op(i - first). - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the range. - * \param last The end of the range. - * \param unary_op The unary operation to apply. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * \tparam UnaryOperation is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p tabulate to generate the first \c n non-positive integers - * using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::tabulate(thrust::host, A, A + 10, thrust::negate()); - * // A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9} - * \endcode - * - * \see thrust::fill - * \see thrust::generate - * \see thrust::sequence - */ -template - void tabulate(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - UnaryOperation unary_op); - - -/*! \p tabulate fills the range [first, last) with the value of a function applied to each - * element's index. - * - * For each iterator \c i in the range [first, last), \p tabulate performs the assignment - * *i = unary_op(i - first). - * - * \param first The beginning of the range. - * \param last The end of the range. - * \param unary_op The unary operation to apply. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and if \c x and \c y are objects of \c ForwardIterator's \c value_type, then x + y is defined, - * and if \c T is \p ForwardIterator's \c value_type, then T(0) is defined. - * \tparam UnaryOperation is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * The following code snippet demonstrates how to use \p tabulate to generate the first \c n non-positive integers: - * - * \code - * #include - * #include - * ... - * const int N = 10; - * int A[N]; - * thrust::tabulate(A, A + 10, thrust::negate()); - * // A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9} - * \endcode - * - * \see thrust::fill - * \see thrust::generate - * \see thrust::sequence - */ -template - void tabulate(ForwardIterator first, - ForwardIterator last, - UnaryOperation unary_op); - - -/*! \} // end transformations - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/transform.h b/compat/thrust/transform.h deleted file mode 100644 index 1ada105..0000000 --- a/compat/thrust/transform.h +++ /dev/null @@ -1,720 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file transform.h - * \brief Transforms input ranges using a function object - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - -/*! \addtogroup transformations - * \ingroup algorithms - * \{ - */ - - -/*! This version of \p transform applies a unary function to each element - * of an input sequence and stores the result in the corresponding - * position in an output sequence. Specifically, for each iterator - * i in the range [\p first, \p last) the operation - * op(*i) is performed and the result is assigned to *o, - * where o is the corresponding output iterator in the range - * [\p result, \p result + (\p last - \p first) ). The input and - * output sequences may coincide, resulting in an in-place transformation. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise. - * - * The following code snippet demonstrates how to use \p transform to negate a range in-place - * using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * thrust::negate op; - * - * thrust::transform(thrust::host, data, data + 10, data, op); // in-place transformation - * - * // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/transform.html - */ -template - OutputIterator transform(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - OutputIterator result, - UnaryFunction op); - - -/*! This version of \p transform applies a unary function to each element - * of an input sequence and stores the result in the corresponding - * position in an output sequence. Specifically, for each iterator - * i in the range [\p first, \p last) the operation - * op(*i) is performed and the result is assigned to *o, - * where o is the corresponding output iterator in the range - * [\p result, \p result + (\p last - \p first) ). The input and - * output sequences may coincide, resulting in an in-place transformation. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise. - * - * The following code snippet demonstrates how to use \p transform - * - * \code - * #include - * #include - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * thrust::negate op; - * - * thrust::transform(data, data + 10, data, op); // in-place transformation - * - * // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/transform.html - */ -template - OutputIterator transform(InputIterator first, InputIterator last, - OutputIterator result, - UnaryFunction op); - - -/*! This version of \p transform applies a binary function to each pair - * of elements from two input sequences and stores the result in the - * corresponding position in an output sequence. Specifically, for - * each iterator i in the range [\p first1, \p last1) and - * j = first + (i - first1) in the range [\p first2, \p last2) - * the operation op(*i,*j) is performed and the result is - * assigned to *o, where o is the corresponding - * output iterator in the range [\p result, \p result + (\p last - \p first) ). - * The input and output sequences may coincide, resulting in an - * in-place transformation. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input sequence. - * \param last1 The end of the first input sequence. - * \param first2 The beginning of the second input sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam BinaryFunction is a model of Binary Function - * and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * \pre \p first2 may equal \p result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * - * The following code snippet demonstrates how to use \p transform to compute the sum of two - * ranges using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int input1[6] = {-5, 0, 2, 3, 2, 4}; - * int input2[6] = { 3, 6, -2, 1, 2, 3}; - * int output[6]; - * - * thrust::plus op; - * - * thrust::transform(thrust::host, input1, input1 + 6, input2, output, op); - * - * // output is now {-2, 6, 0, 4, 4, 7}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/transform.html - */ -template - OutputIterator transform(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryFunction op); - - -/*! This version of \p transform applies a binary function to each pair - * of elements from two input sequences and stores the result in the - * corresponding position in an output sequence. Specifically, for - * each iterator i in the range [\p first1, \p last1) and - * j = first + (i - first1) in the range [\p first2, \p last2) - * the operation op(*i,*j) is performed and the result is - * assigned to *o, where o is the corresponding - * output iterator in the range [\p result, \p result + (\p last - \p first) ). - * The input and output sequences may coincide, resulting in an - * in-place transformation. - * - * \param first1 The beginning of the first input sequence. - * \param last1 The end of the first input sequence. - * \param first2 The beginning of the second input sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam BinaryFunction is a model of Binary Function - * and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * - * \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * \pre \p first2 may equal \p result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * - * The following code snippet demonstrates how to use \p transform - * - * \code - * #include - * #include - * - * int input1[6] = {-5, 0, 2, 3, 2, 4}; - * int input2[6] = { 3, 6, -2, 1, 2, 3}; - * int output[6]; - * - * thrust::plus op; - * - * thrust::transform(input1, input1 + 6, input2, output, op); - * - * // output is now {-2, 6, 0, 4, 4, 7}; - * \endcode - * - * \see http://www.sgi.com/tech/stl/transform.html - */ -template - OutputIterator transform(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - OutputIterator result, - BinaryFunction op); - - -/*! This version of \p transform_if conditionally applies a unary function - * to each element of an input sequence and stores the result in the corresponding - * position in an output sequence if the corresponding position in the input sequence - * satifies a predicate. Otherwise, the corresponding position in the - * output sequence is not modified. - * - * Specifically, for each iterator i in the range [first, last) the - * predicate pred(*i) is evaluated. If this predicate - * evaluates to \c true, the result of op(*i) is assigned to *o, - * where o is the corresponding output iterator in the range - * [result, result + (last - first) ). Otherwise, op(*i) is - * not evaluated and no assignment occurs. The input and output sequences may coincide, - * resulting in an in-place transformation. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \param pred The predicate operation. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \c InputIterator's \c value_type is convertible to \c Predicate's \c argument_type, - * and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * \tparam Predicate is a model of Predicate. - * - * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise. - * - * The following code snippet demonstrates how to use \p transform_if to negate the odd-valued - * elements of a range using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * struct is_odd - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x % 2; - * } - * }; - * - * thrust::negate op; - * thrust::identity identity; - * - * // negate odd elements - * thrust::transform_if(thrust::host, data, data + 10, data, op, is_odd()); // in-place transformation - * - * // data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8}; - * \endcode - * - * \see thrust::transform - */ -template - ForwardIterator transform_if(const thrust::detail::execution_policy_base &exec, - InputIterator first, InputIterator last, - ForwardIterator result, - UnaryFunction op, - Predicate pred); - - -/*! This version of \p transform_if conditionally applies a unary function - * to each element of an input sequence and stores the result in the corresponding - * position in an output sequence if the corresponding position in the input sequence - * satifies a predicate. Otherwise, the corresponding position in the - * output sequence is not modified. - * - * Specifically, for each iterator i in the range [first, last) the - * predicate pred(*i) is evaluated. If this predicate - * evaluates to \c true, the result of op(*i) is assigned to *o, - * where o is the corresponding output iterator in the range - * [result, result + (last - first) ). Otherwise, op(*i) is - * not evaluated and no assignment occurs. The input and output sequences may coincide, - * resulting in an in-place transformation. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \param pred The predicate operation. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator, - * and \c InputIterator's \c value_type is convertible to \c Predicate's \c argument_type, - * and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * \tparam Predicate is a model of Predicate. - * - * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise. - * - * The following code snippet demonstrates how to use \p transform_if: - * - * \code - * #include - * #include - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * - * struct is_odd - * { - * __host__ __device__ - * bool operator()(int x) - * { - * return x % 2; - * } - * }; - * - * thrust::negate op; - * thrust::identity identity; - * - * // negate odd elements - * thrust::transform_if(data, data + 10, data, op, is_odd()); // in-place transformation - * - * // data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8}; - * \endcode - * - * \see thrust::transform - */ -template - ForwardIterator transform_if(InputIterator first, InputIterator last, - ForwardIterator result, - UnaryFunction op, - Predicate pred); - - -/*! This version of \p transform_if conditionally applies a unary function - * to each element of an input sequence and stores the result in the corresponding - * position in an output sequence if the corresponding position in a stencil sequence - * satisfies a predicate. Otherwise, the corresponding position in the - * output sequence is not modified. - * - * Specifically, for each iterator i in the range [first, last) the - * predicate pred(*s) is evaluated, where s is the corresponding input - * iterator in the range [stencil, stencil + (last - first) ). If this predicate - * evaluates to \c true, the result of op(*i) is assigned to *o, - * where o is the corresponding output iterator in the range - * [result, result + (last - first) ). Otherwise, op(*i) is - * not evaluated and no assignment occurs. The input and output sequences may coincide, - * resulting in an in-place transformation. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \param pred The predicate operation. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * and \c InputIterator1's \c value_type is convertible to \c UnaryFunction's \c argument_type. - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c Predicate's \c argument_type. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * \tparam Predicate is a model of Predicate. - * - * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise. - * \pre \p stencil may equal \p result, but the range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)) otherwise. - * - * The following code snippet demonstrates how to use \p transform_if using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * - * thrust::negate op; - * thrust::identity identity; - * - * thrust::transform_if(thrust::host, data, data + 10, stencil, data, op, identity); // in-place transformation - * - * // data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8}; - * \endcode - * - * \see thrust::transform - */ -template - ForwardIterator transform_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - ForwardIterator result, - UnaryFunction op, - Predicate pred); - - -/*! This version of \p transform_if conditionally applies a unary function - * to each element of an input sequence and stores the result in the corresponding - * position in an output sequence if the corresponding position in a stencil sequence - * satisfies a predicate. Otherwise, the corresponding position in the - * output sequence is not modified. - * - * Specifically, for each iterator i in the range [first, last) the - * predicate pred(*s) is evaluated, where s is the corresponding input - * iterator in the range [stencil, stencil + (last - first) ). If this predicate - * evaluates to \c true, the result of op(*i) is assigned to *o, - * where o is the corresponding output iterator in the range - * [result, result + (last - first) ). Otherwise, op(*i) is - * not evaluated and no assignment occurs. The input and output sequences may coincide, - * resulting in an in-place transformation. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the output sequence. - * \param op The tranformation operation. - * \param pred The predicate operation. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * and \c InputIterator1's \c value_type is convertible to \c UnaryFunction's \c argument_type. - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c Predicate's \c argument_type. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * \tparam Predicate is a model of Predicate. - * - * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise. - * \pre \p stencil may equal \p result, but the range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)) otherwise. - * - * The following code snippet demonstrates how to use \p transform_if: - * - * \code - * #include - * #include - * - * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; - * int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; - * - * thrust::negate op; - * thrust::identity identity; - * - * thrust::transform_if(data, data + 10, stencil, data, op, identity); // in-place transformation - * - * // data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8}; - * \endcode - * - * \see thrust::transform - */ -template - ForwardIterator transform_if(InputIterator1 first, InputIterator1 last, - InputIterator2 stencil, - ForwardIterator result, - UnaryFunction op, - Predicate pred); - - -/*! This version of \p transform_if conditionally applies a binary function - * to each pair of elements from two input sequences and stores the result in the corresponding - * position in an output sequence if the corresponding position in a stencil sequence - * satifies a predicate. Otherwise, the corresponding position in the - * output sequence is not modified. - * - * Specifically, for each iterator i in the range [first1, last1) and - * j = first2 + (i - first1) in the range [first2, first2 + (last1 - first1) ), - * the predicate pred(*s) is evaluated, where s is the corresponding input - * iterator in the range [stencil, stencil + (last1 - first1) ). If this predicate - * evaluates to \c true, the result of binary_op(*i,*j) is assigned to *o, - * where o is the corresponding output iterator in the range - * [result, result + (last1 - first1) ). Otherwise, binary_op(*i,*j) is - * not evaluated and no assignment occurs. The input and output sequences may coincide, - * resulting in an in-place transformation. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first1 The beginning of the first input sequence. - * \param last1 The end of the first input sequence. - * \param first2 The beginning of the second input sequence. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the output sequence. - * \param binary_op The transformation operation. - * \param pred The predicate operation. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator - * and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam BinaryFunction is a model of Binary Function - * and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * \tparam Predicate is a model of Predicate. - * - * \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * \pre \p first2 may equal \p result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * \pre \p stencil may equal \p result, but the range [stencil, stencil + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * - * The following code snippet demonstrates how to use \p transform_if using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * ... - * - * int input1[6] = {-5, 0, 2, 3, 2, 4}; - * int input2[6] = { 3, 6, -2, 1, 2, 3}; - * int stencil[8] = { 1, 0, 1, 0, 1, 0}; - * int output[6]; - * - * thrust::plus op; - * thrust::identity identity; - * - * thrust::transform_if(thrust::host, input1, input1 + 6, input2, stencil, output, op, identity); - * - * // output is now {-2, 0, 0, 3, 4, 4}; - * \endcode - * - * \see thrust::transform - */ -template - ForwardIterator transform_if(const thrust::detail::execution_policy_base &exec, - InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - InputIterator3 stencil, - ForwardIterator result, - BinaryFunction binary_op, - Predicate pred); - - -/*! This version of \p transform_if conditionally applies a binary function - * to each pair of elements from two input sequences and stores the result in the corresponding - * position in an output sequence if the corresponding position in a stencil sequence - * satifies a predicate. Otherwise, the corresponding position in the - * output sequence is not modified. - * - * Specifically, for each iterator i in the range [first1, last1) and - * j = first2 + (i - first1) in the range [first2, first2 + (last1 - first1) ), - * the predicate pred(*s) is evaluated, where s is the corresponding input - * iterator in the range [stencil, stencil + (last1 - first1) ). If this predicate - * evaluates to \c true, the result of binary_op(*i,*j) is assigned to *o, - * where o is the corresponding output iterator in the range - * [result, result + (last1 - first1) ). Otherwise, binary_op(*i,*j) is - * not evaluated and no assignment occurs. The input and output sequences may coincide, - * resulting in an in-place transformation. - * - * \param first1 The beginning of the first input sequence. - * \param last1 The end of the first input sequence. - * \param first2 The beginning of the second input sequence. - * \param stencil The beginning of the stencil sequence. - * \param result The beginning of the output sequence. - * \param binary_op The transformation operation. - * \param pred The predicate operation. - * \return The end of the output sequence. - * - * \tparam InputIterator1 is a model of Input Iterator - * and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. - * \tparam InputIterator2 is a model of Input Iterator - * and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. - * \tparam ForwardIterator is a model of Forward Iterator. - * \tparam BinaryFunction is a model of Binary Function - * and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. - * \tparam Predicate is a model of Predicate. - * - * \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * \pre \p first2 may equal \p result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * \pre \p stencil may equal \p result, but the range [stencil, stencil + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. - * - * The following code snippet demonstrates how to use \p transform_if: - * - * \code - * #include - * #include - * - * int input1[6] = {-5, 0, 2, 3, 2, 4}; - * int input2[6] = { 3, 6, -2, 1, 2, 3}; - * int stencil[8] = { 1, 0, 1, 0, 1, 0}; - * int output[6]; - * - * thrust::plus op; - * thrust::identity identity; - * - * thrust::transform_if(input1, input1 + 6, input2, stencil, output, op, identity); - * - * // output is now {-2, 0, 0, 3, 4, 4}; - * \endcode - * - * \see thrust::transform - */ -template - ForwardIterator transform_if(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, - InputIterator3 stencil, - ForwardIterator result, - BinaryFunction binary_op, - Predicate pred); - - -/*! \} // end transformations - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/transform_reduce.h b/compat/thrust/transform_reduce.h deleted file mode 100644 index 3ef5efd..0000000 --- a/compat/thrust/transform_reduce.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file transform_reduce.h - * \brief Fused transform / reduction - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup reductions - * \{ - * \addtogroup transformed_reductions Transformed Reductions - * \ingroup reductions - * \{ - */ - - -/*! \p transform_reduce fuses the \p transform and \p reduce operations. - * \p transform_reduce is equivalent to performing a transformation defined by - * \p unary_op into a temporary sequence and then performing \p reduce on the - * transformed sequence. In most cases, fusing these two operations together is - * more efficient, since fewer memory reads and writes are required. - * - * \p transform_reduce performs a reduction on the transformation of the - * sequence [first, last) according to \p unary_op. Specifically, - * \p unary_op is applied to each element of the sequence and then the result - * is reduced to a single value with \p binary_op using the initial value - * \p init. Note that the transformation \p unary_op is not applied to - * the initial value \p init. The order of reduction is not specified, - * so \p binary_op must be both commutative and associative. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param unary_op The function to apply to each element of the input sequence. - * \param init The result is initialized to this value. - * \param binary_op The reduction operation. - * \return The result of the transformed reduction. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. - * \tparam UnaryFunction is a model of Unary Function, - * and \p UnaryFunction's \c result_type is convertible to \c OutputType. - * \tparam OutputType is a model of Assignable, - * and is convertible to \p BinaryFunction's \c first_argument_type and \c second_argument_type. - * \tparam BinaryFunction is a model of Binary Function, - * and \p BinaryFunction's \c result_type is convertible to \p OutputType. - * - * The following code snippet demonstrates how to use \p transform_reduce - * to compute the maximum value of the absolute value of the elements - * of a range using the \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * template - * struct absolute_value : public unary_function - * { - * __host__ __device__ T operator()(const T &x) const - * { - * return x < T(0) ? -x : x; - * } - * }; - * - * ... - * - * int data[6] = {-1, 0, -2, -2, 1, -3}; - * int result = thrust::transform_reduce(thrust::host, - * data, data + 6, - * absolute_value(), - * 0, - * thrust::maximum()); - * // result == 3 - * \endcode - * - * \see \c transform - * \see \c reduce - */ -template - OutputType transform_reduce(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op); - - -/*! \p transform_reduce fuses the \p transform and \p reduce operations. - * \p transform_reduce is equivalent to performing a transformation defined by - * \p unary_op into a temporary sequence and then performing \p reduce on the - * transformed sequence. In most cases, fusing these two operations together is - * more efficient, since fewer memory reads and writes are required. - * - * \p transform_reduce performs a reduction on the transformation of the - * sequence [first, last) according to \p unary_op. Specifically, - * \p unary_op is applied to each element of the sequence and then the result - * is reduced to a single value with \p binary_op using the initial value - * \p init. Note that the transformation \p unary_op is not applied to - * the initial value \p init. The order of reduction is not specified, - * so \p binary_op must be both commutative and associative. - * - * \param first The beginning of the sequence. - * \param last The end of the sequence. - * \param unary_op The function to apply to each element of the input sequence. - * \param init The result is initialized to this value. - * \param binary_op The reduction operation. - * \return The result of the transformed reduction. - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. - * \tparam UnaryFunction is a model of Unary Function, - * and \p UnaryFunction's \c result_type is convertible to \c OutputType. - * \tparam OutputType is a model of Assignable, - * and is convertible to \p BinaryFunction's \c first_argument_type and \c second_argument_type. - * \tparam BinaryFunction is a model of Binary Function, - * and \p BinaryFunction's \c result_type is convertible to \p OutputType. - * - * The following code snippet demonstrates how to use \p transform_reduce - * to compute the maximum value of the absolute value of the elements - * of a range. - * - * \code - * #include - * #include - * - * template - * struct absolute_value : public unary_function - * { - * __host__ __device__ T operator()(const T &x) const - * { - * return x < T(0) ? -x : x; - * } - * }; - * - * ... - * - * int data[6] = {-1, 0, -2, -2, 1, -3}; - * int result = thrust::transform_reduce(data, data + 6, - * absolute_value(), - * 0, - * thrust::maximum()); - * // result == 3 - * \endcode - * - * \see \c transform - * \see \c reduce - */ -template - OutputType transform_reduce(InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op); - - -/*! \} // end transformed_reductions - * \} // end reductions - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/transform_scan.h b/compat/thrust/transform_scan.h deleted file mode 100644 index e9943e4..0000000 --- a/compat/thrust/transform_scan.h +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file transform_scan.h - * \brief Fused transform / prefix-sum - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup algorithms - */ - -/*! \addtogroup prefixsums Prefix Sums - * \ingroup algorithms - * \{ - */ - -/*! \addtogroup transformed_prefixsums Transformed Prefix Sums - * \ingroup prefixsums - * \{ - */ - - -/*! \p transform_inclusive_scan fuses the \p transform and \p inclusive_scan - * operations. \p transform_inclusive_scan is equivalent to performing a - * tranformation defined by \p unary_op into a temporary sequence and then - * performing an \p inclusive_scan on the tranformed sequence. In most - * cases, fusing these two operations together is more efficient, since - * fewer memory reads and writes are required. In \p transform_inclusive_scan, - * unary_op(\*first) is assigned to \*result and the result - * of binary_op(unary_op(\*first), unary_op(\*(first + 1))) is - * assigned to \*(result + 1), and so on. The transform scan - * operation is permitted to be in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param unary_op The function used to tranform the input sequence. - * \param binary_op The associatve operator used to 'sum' transformed values. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c unary_op's input type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type - * is convertable to \c OutputIterator's \c value_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p transform_inclusive_scan using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::negate unary_op; - * thrust::plus binary_op; - * - * thrust::transform_inclusive_scan(thrust::host, data, data + 6, data, unary_op, binary_op); // in-place scan - * - * // data is now {-1, -1, -3, -5, -6, -9} - * \endcode - * - * \see \p transform - * \see \p inclusive_scan - * - */ -template - OutputIterator transform_inclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - AssociativeOperator binary_op); - - -/*! \p transform_inclusive_scan fuses the \p transform and \p inclusive_scan - * operations. \p transform_inclusive_scan is equivalent to performing a - * tranformation defined by \p unary_op into a temporary sequence and then - * performing an \p inclusive_scan on the tranformed sequence. In most - * cases, fusing these two operations together is more efficient, since - * fewer memory reads and writes are required. In \p transform_inclusive_scan, - * unary_op(\*first) is assigned to \*result and the result - * of binary_op(unary_op(\*first), unary_op(\*(first + 1))) is - * assigned to \*(result + 1), and so on. The transform scan - * operation is permitted to be in-place. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param unary_op The function used to tranform the input sequence. - * \param binary_op The associatve operator used to 'sum' transformed values. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c unary_op's input type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type - * is convertable to \c OutputIterator's \c value_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p transform_inclusive_scan - * - * \code - * #include - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::negate unary_op; - * thrust::plus binary_op; - * - * thrust::transform_inclusive_scan(data, data + 6, data, unary_op, binary_op); // in-place scan - * - * // data is now {-1, -1, -3, -5, -6, -9} - * \endcode - * - * \see \p transform - * \see \p inclusive_scan - * - */ -template - OutputIterator transform_inclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - AssociativeOperator binary_op); - - -/*! \p transform_exclusive_scan fuses the \p transform and \p exclusive_scan - * operations. \p transform_exclusive_scan is equivalent to performing a - * tranformation defined by \p unary_op into a temporary sequence and then - * performing an \p exclusive_scan on the tranformed sequence. In most - * cases, fusing these two operations together is more efficient, since - * fewer memory reads and writes are required. In - * \p transform_exclusive_scan, \p init is assigned to \*result - * and the result of binary_op(init, unary_op(\*first)) is assigned - * to \*(result + 1), and so on. The transform scan operation is - * permitted to be in-place. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param unary_op The function used to tranform the input sequence. - * \param init The initial value of the \p exclusive_scan - * \param binary_op The associatve operator used to 'sum' transformed values. - * \return The end of the output sequence. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c unary_op's input type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type - * is convertable to \c OutputIterator's \c value_type. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p transform_exclusive_scan using the - * \p thrust::host execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::negate unary_op; - * thrust::plus binary_op; - * - * thrust::transform_exclusive_scan(thrust::host, data, data + 6, data, unary_op, 4, binary_op); // in-place scan - * - * // data is now {4, 3, 3, 1, -1, -2} - * \endcode - * - * \see \p transform - * \see \p exclusive_scan - * - */ -template - OutputIterator transform_exclusive_scan(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - T init, - AssociativeOperator binary_op); - - -/*! \p transform_exclusive_scan fuses the \p transform and \p exclusive_scan - * operations. \p transform_exclusive_scan is equivalent to performing a - * tranformation defined by \p unary_op into a temporary sequence and then - * performing an \p exclusive_scan on the tranformed sequence. In most - * cases, fusing these two operations together is more efficient, since - * fewer memory reads and writes are required. In - * \p transform_exclusive_scan, \p init is assigned to \*result - * and the result of binary_op(init, unary_op(\*first)) is assigned - * to \*(result + 1), and so on. The transform scan operation is - * permitted to be in-place. - * - * \param first The beginning of the input sequence. - * \param last The end of the input sequence. - * \param result The beginning of the output sequence. - * \param unary_op The function used to tranform the input sequence. - * \param init The initial value of the \p exclusive_scan - * \param binary_op The associatve operator used to 'sum' transformed values. - * \return The end of the output sequence. - * - * \tparam InputIterator is a model of Input Iterator - * and \c InputIterator's \c value_type is convertible to \c unary_op's input type. - * \tparam OutputIterator is a model of Output Iterator. - * \tparam UnaryFunction is a model of Unary Function - * and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type - * is convertable to \c OutputIterator's \c value_type. - * \tparam T is convertible to \c OutputIterator's \c value_type. - * \tparam AssociativeOperator is a model of Binary Function - * and \c AssociativeOperator's \c result_type is - * convertible to \c OutputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p transform_exclusive_scan - * - * \code - * #include - * - * int data[6] = {1, 0, 2, 2, 1, 3}; - * - * thrust::negate unary_op; - * thrust::plus binary_op; - * - * thrust::transform_exclusive_scan(data, data + 6, data, unary_op, 4, binary_op); // in-place scan - * - * // data is now {4, 3, 3, 1, -1, -2} - * \endcode - * - * \see \p transform - * \see \p exclusive_scan - * - */ -template - OutputIterator transform_exclusive_scan(InputIterator first, - InputIterator last, - OutputIterator result, - UnaryFunction unary_op, - T init, - AssociativeOperator binary_op); - - -/*! \} // end transformed_prefixsums - */ - - -/*! \} // end prefixsums - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/tuple.h b/compat/thrust/tuple.h deleted file mode 100644 index 3961d98..0000000 --- a/compat/thrust/tuple.h +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file tuple.h - * \brief A type encapsulating a heterogeneous collection of elements - */ - -/* - * Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) - * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying NOTICE file for the complete license) - * - * For more information, see http://www.boost.org - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - -/*! \addtogroup utility - * \{ - */ - -/*! \addtogroup tuple - * \{ - */ - -/*! \cond - */ - -struct null_type; - -/*! \endcond - */ - -/*! This metafunction returns the type of a - * \p tuple's Nth element. - * - * \tparam N This parameter selects the element of interest. - * \tparam T A \c tuple type of interest. - * - * \see pair - * \see tuple - */ -template - struct tuple_element -{ - private: - typedef typename T::tail_type Next; - - public: - /*! The result of this metafunction is returned in \c type. - */ - typedef typename tuple_element::type type; -}; // end tuple_element - -/*! This metafunction returns the number of elements - * of a \p tuple type of interest. - * - * \tparam T A \c tuple type of interest. - * - * \see pair - * \see tuple - */ -template - struct tuple_size -{ - /*! The result of this metafunction is returned in \c value. - */ - static const int value = 1 + tuple_size::value; -}; // end tuple_size - -// get function for non-const cons-lists, returns a reference to the element - -/*! The \p get function returns a reference to a \p tuple element of - * interest. - * - * \param t A reference to a \p tuple of interest. - * \return A reference to \p t's Nth element. - * - * \tparam N The index of the element of interest. - * - * The following code snippet demonstrates how to use \p get to print - * the value of a \p tuple element. - * - * \code - * #include - * #include - * ... - * thrust::tuple t(13, "thrust"); - * - * std::cout << "The 1st value of t is " << thrust::get<1>(t) << std::endl; - * \endcode - * - * \see pair - * \see tuple - */ -template -__host__ __device__ -inline typename access_traits< - typename tuple_element >::type - >::non_const_type -get(detail::cons& t); - - -/*! The \p get function returns a \c const reference to a \p tuple element of - * interest. - * - * \param t A reference to a \p tuple of interest. - * \return A \c const reference to \p t's Nth element. - * - * \tparam N The index of the element of interest. - * - * The following code snippet demonstrates how to use \p get to print - * the value of a \p tuple element. - * - * \code - * #include - * #include - * ... - * thrust::tuple t(13, "thrust"); - * - * std::cout << "The 1st value of t is " << thrust::get<1>(t) << std::endl; - * \endcode - * - * \see pair - * \see tuple - */ -template -__host__ __device__ -inline typename access_traits< - typename tuple_element >::type - >::const_type -get(const detail::cons& t); - - - -/*! \p tuple is a class template that can be instantiated with up to ten arguments. - * Each template argument specifies the type of element in the \p tuple. - * Consequently, tuples are heterogeneous, fixed-size collections of values. An - * instantiation of \p tuple with two arguments is similar to an instantiation - * of \p pair with the same two arguments. Individual elements of a \p tuple may - * be accessed with the \p get function. - * - * \tparam TN The type of the N \c tuple element. Thrust's \p tuple - * type currently supports up to ten elements. - * - * The following code snippet demonstrates how to create a new \p tuple object - * and inspect and modify the value of its elements. - * - * \code - * #include - * #include - * ... - * // create a tuple containing an int, a float, and a string - * thrust::tuple t(13, 0.1f, "thrust"); - * - * // individual members are accessed with the free function get - * std::cout << "The first element's value is " << thrust::get<0>(t) << std::endl; - * - * // or the member function get - * std::cout << "The second element's value is " << t.get<1>() << std::endl; - * - * // we can also modify elements with the same function - * thrust::get<0>(t) += 10; - * \endcode - * - * \see pair - * \see get - * \see make_tuple - * \see tuple_element - * \see tuple_size - * \see tie - */ -template - class tuple : - public detail::map_tuple_to_cons::type -{ - /*! \cond - */ - - private: - typedef typename detail::map_tuple_to_cons::type inherited; - - /*! \endcond - */ - - public: - /*! \p tuple's no-argument constructor initializes each element. - */ - inline __host__ __device__ - tuple(void) {} - - /*! \p tuple's one-argument constructor copy constructs the first element from the given parameter - * and intializes all other elements. - * \param t0 The value to assign to this \p tuple's first element. - */ - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0) - : inherited(t0, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - /*! \p tuple's one-argument constructor copy constructs the first two elements from the given parameters - * and intializes all other elements. - * \param t0 The value to assign to this \p tuple's first element. - * \param t1 The value to assign to this \p tuple's second element. - * \note \p tuple's constructor has ten variants of this form, the rest of which are ommitted here for brevity. - */ - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1) - : inherited(t0, t1, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - /*! \cond - */ - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2) - : inherited(t0, t1, t2, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3) - : inherited(t0, t1, t2, t3, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4) - : inherited(t0, t1, t2, t3, t4, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5) - : inherited(t0, t1, t2, t3, t4, t5, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6) - : inherited(t0, t1, t2, t3, t4, t5, t6, - static_cast(null_type()), - static_cast(null_type()), - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6, - typename access_traits::parameter_type t7) - : inherited(t0, t1, t2, t3, t4, t5, t6, t7, - static_cast(null_type()), - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6, - typename access_traits::parameter_type t7, - typename access_traits::parameter_type t8) - : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, - static_cast(null_type())) {} - - inline __host__ __device__ - tuple(typename access_traits::parameter_type t0, - typename access_traits::parameter_type t1, - typename access_traits::parameter_type t2, - typename access_traits::parameter_type t3, - typename access_traits::parameter_type t4, - typename access_traits::parameter_type t5, - typename access_traits::parameter_type t6, - typename access_traits::parameter_type t7, - typename access_traits::parameter_type t8, - typename access_traits::parameter_type t9) - : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {} - - - template - inline __host__ __device__ - tuple(const detail::cons& p) : inherited(p) {} - - template - inline __host__ __device__ - tuple& operator=(const detail::cons& k) - { - inherited::operator=(k); - return *this; - } - - /*! \endcond - */ - - /*! This assignment operator allows assigning the first two elements of this \p tuple from a \p pair. - * \param k A \p pair to assign from. - */ - template - __host__ __device__ inline - tuple& operator=(const thrust::pair& k) { - //BOOST_STATIC_ASSERT(length::value == 2);// check_length = 2 - this->head = k.first; - this->tail.head = k.second; - return *this; - } - - /*! \p swap swaps the elements of two tuples. - * - * \param t The other tuple with which to swap. - */ - inline __host__ __device__ - void swap(tuple &t) - { - inherited::swap(t); - } -}; - -/*! \cond - */ - -template <> -class tuple : - public null_type -{ -public: - typedef null_type inherited; -}; - -/*! \endcond - */ - - -/*! This version of \p make_tuple creates a new \c tuple object from a - * single object. - * - * \param t0 The object to copy from. - * \return A \p tuple object with a single member which is a copy of \p t0. - */ -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0); - -/*! This version of \p make_tuple creates a new \c tuple object from two - * objects. - * - * \param t0 The first object to copy from. - * \param t1 The second object to copy from. - * \return A \p tuple object with two members which are copies of \p t0 - * and \p t1. - * - * \note \p make_tuple has ten variants, the rest of which are omitted here - * for brevity. - */ -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1); - -/*! This version of \p tie creates a new \c tuple whose single element is - * a reference which refers to this function's argument. - * - * \param t0 The object to reference. - * \return A \p tuple object with one member which is a reference to \p t0. - */ -template -__host__ __device__ inline -tuple tie(T0& t0); - -/*! This version of \p tie creates a new \c tuple of references object which - * refers to this function's arguments. - * - * \param t0 The first object to reference. - * \param t1 The second object to reference. - * \return A \p tuple object with two members which are references to \p t0 - * and \p t1. - * - * \note \p tie has ten variants, the rest of which are omitted here for - * brevity. - */ -template -__host__ __device__ inline -tuple tie(T0& t0, T1& t1); - -/*! \p swap swaps the contents of two tuples. - * - * \param x The first \p tuple to swap. - * \param y The second \p tuple to swap. - */ -template< - typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, - typename U0, typename U1, typename U2, typename U3, typename U4, typename U5, typename U6, typename U7, typename U8, typename U9 -> -inline __host__ __device__ -void swap(tuple &x, - tuple &y); - - - -/*! \cond - */ - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8); - -template -__host__ __device__ inline - typename detail::make_tuple_mapper::type - make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8); - -template -__host__ __device__ inline -tuple tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9); - - -__host__ __device__ inline -bool operator==(const null_type&, const null_type&); - -__host__ __device__ inline -bool operator>=(const null_type&, const null_type&); - -__host__ __device__ inline -bool operator<=(const null_type&, const null_type&); - -__host__ __device__ inline -bool operator!=(const null_type&, const null_type&); - -__host__ __device__ inline -bool operator<(const null_type&, const null_type&); - -__host__ __device__ inline -bool operator>(const null_type&, const null_type&); - -/*! \endcond - */ - -/*! \} // tuple - */ - -/*! \} // utility - */ - -} // end thrust - diff --git a/compat/thrust/uninitialized_copy.h b/compat/thrust/uninitialized_copy.h deleted file mode 100644 index 77b673c..0000000 --- a/compat/thrust/uninitialized_copy.h +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file uninitialized_copy.h - * \brief Copy construction into a range of uninitialized elements from a source range - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup copying - * \{ - */ - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a constructor. - * Occasionally, however, it is useful to separate those two operations. - * If each iterator in the range [result, result + (last - first)) points - * to uninitialized memory, then \p uninitialized_copy creates a copy of - * [first, last) in that range. That is, for each iterator \c i in - * the input, \p uninitialized_copy creates a copy of \c *i in the location pointed - * to by the corresponding iterator in the output range by \p ForwardIterator's - * \c value_type's copy constructor with *i as its argument. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the input range to copy from. - * \param last The last element of the input range to copy from. - * \param result The first element of the output range to copy to. - * \return An iterator pointing to the last element of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes - * a single argument whose type is \p InputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p uninitialized_copy to initialize - * a range of uninitialized memory using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_vector input(N, val); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_copy(thrust::device, input.begin(), input.end(), array); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_copy.html - * \see \c copy - * \see \c uninitialized_fill - * \see \c device_new - * \see \c device_malloc - */ -template - ForwardIterator uninitialized_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - ForwardIterator result); - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a constructor. - * Occasionally, however, it is useful to separate those two operations. - * If each iterator in the range [result, result + (last - first)) points - * to uninitialized memory, then \p uninitialized_copy creates a copy of - * [first, last) in that range. That is, for each iterator \c i in - * the input, \p uninitialized_copy creates a copy of \c *i in the location pointed - * to by the corresponding iterator in the output range by \p ForwardIterator's - * \c value_type's copy constructor with *i as its argument. - * - * \param first The first element of the input range to copy from. - * \param last The last element of the input range to copy from. - * \param result The first element of the output range to copy to. - * \return An iterator pointing to the last element of the output range. - * - * \tparam InputIterator is a model of Input Iterator. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes - * a single argument whose type is \p InputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p uninitialized_copy to initialize - * a range of uninitialized memory. - * - * \code - * #include - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_vector input(N, val); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_copy(input.begin(), input.end(), array); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_copy.html - * \see \c copy - * \see \c uninitialized_fill - * \see \c device_new - * \see \c device_malloc - */ -template - ForwardIterator uninitialized_copy(InputIterator first, - InputIterator last, - ForwardIterator result); - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a constructor. - * Occasionally, however, it is useful to separate those two operations. - * If each iterator in the range [result, result + n) points - * to uninitialized memory, then \p uninitialized_copy_n creates a copy of - * [first, first + n) in that range. That is, for each iterator \c i in - * the input, \p uninitialized_copy_n creates a copy of \c *i in the location pointed - * to by the corresponding iterator in the output range by \p InputIterator's - * \c value_type's copy constructor with *i as its argument. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the input range to copy from. - * \param n The number of elements to copy. - * \param result The first element of the output range to copy to. - * \return An iterator pointing to the last element of the output range. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator. - * \tparam Size is an integral type. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes - * a single argument whose type is \p InputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, first + n) and the range [result, result + n) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p uninitialized_copy to initialize - * a range of uninitialized memory using the \p thrust::device execution policy for - * parallelization: - * - * \code - * #include - * #include - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_vector input(N, val); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_copy_n(thrust::device, input.begin(), N, array); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_copy.html - * \see \c uninitialized_copy - * \see \c copy - * \see \c uninitialized_fill - * \see \c device_new - * \see \c device_malloc - */ -template - ForwardIterator uninitialized_copy_n(const thrust::detail::execution_policy_base &exec, - InputIterator first, - Size n, - ForwardIterator result); - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a constructor. - * Occasionally, however, it is useful to separate those two operations. - * If each iterator in the range [result, result + n) points - * to uninitialized memory, then \p uninitialized_copy_n creates a copy of - * [first, first + n) in that range. That is, for each iterator \c i in - * the input, \p uninitialized_copy_n creates a copy of \c *i in the location pointed - * to by the corresponding iterator in the output range by \p InputIterator's - * \c value_type's copy constructor with *i as its argument. - * - * \param first The first element of the input range to copy from. - * \param n The number of elements to copy. - * \param result The first element of the output range to copy to. - * \return An iterator pointing to the last element of the output range. - * - * \tparam InputIterator is a model of Input Iterator. - * \tparam Size is an integral type. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes - * a single argument whose type is \p InputIterator's \c value_type. - * - * \pre \p first may equal \p result, but the range [first, first + n) and the range [result, result + n) shall not overlap otherwise. - * - * The following code snippet demonstrates how to use \p uninitialized_copy to initialize - * a range of uninitialized memory. - * - * \code - * #include - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_vector input(N, val); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_copy_n(input.begin(), N, array); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_copy.html - * \see \c uninitialized_copy - * \see \c copy - * \see \c uninitialized_fill - * \see \c device_new - * \see \c device_malloc - */ -template - ForwardIterator uninitialized_copy_n(InputIterator first, - Size n, - ForwardIterator result); - - -/*! \} // copying - */ - - -} // end thrust - -#include - diff --git a/compat/thrust/uninitialized_fill.h b/compat/thrust/uninitialized_fill.h deleted file mode 100644 index c726241..0000000 --- a/compat/thrust/uninitialized_fill.h +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file uninitialized_fill.h - * \brief Copy construction into a range of uninitialized elements from a source value - */ - -#pragma once - -#include -#include - -namespace thrust -{ - - -/*! \addtogroup filling - * \ingroup transformations - * \{ - */ - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a - * constructor. Occasionally, however, it is useful to separate those two - * operations. If each iterator in the range [first, last) points - * to unitialized memory, then \p unitialized_fill creates copies of \c x - * in that range. That is, for each iterator \c i in the range [first, last), - * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by - * calling \p ForwardIterator's \c value_type's copy constructor. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the range of interest. - * \param last The last element of the range of interest. - * \param x The value to use as the exemplar of the copy constructor. - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that - * takes a single argument of type \p T. - * - * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of - * uninitialized memory using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_fill(thrust::device, array, array + N, val); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_fill.html - * \see \c uninitialized_fill_n - * \see \c fill - * \see \c uninitialized_copy - * \see \c device_new - * \see \c device_malloc - */ -template - void uninitialized_fill(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - const T &x); - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a - * constructor. Occasionally, however, it is useful to separate those two - * operations. If each iterator in the range [first, last) points - * to unitialized memory, then \p unitialized_fill creates copies of \c x - * in that range. That is, for each iterator \c i in the range [first, last), - * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by - * calling \p ForwardIterator's \c value_type's copy constructor. - * - * \param first The first element of the range of interest. - * \param last The last element of the range of interest. - * \param x The value to use as the exemplar of the copy constructor. - * - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that - * takes a single argument of type \p T. - * - * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of - * uninitialized memory. - * - * \code - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_fill(array, array + N, val); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_fill.html - * \see \c uninitialized_fill_n - * \see \c fill - * \see \c uninitialized_copy - * \see \c device_new - * \see \c device_malloc - */ -template - void uninitialized_fill(ForwardIterator first, - ForwardIterator last, - const T &x); - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a - * constructor. Occasionally, however, it is useful to separate those two - * operations. If each iterator in the range [first, first+n) points - * to unitialized memory, then \p unitialized_fill creates copies of \c x - * in that range. That is, for each iterator \c i in the range [first, first+n), - * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by - * calling \p ForwardIterator's \c value_type's copy constructor. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The first element of the range of interest. - * \param n The size of the range of interest. - * \param x The value to use as the exemplar of the copy constructor. - * \return first+n - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that - * takes a single argument of type \p T. - * - * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of - * uninitialized memory using the \p thrust::device execution policy for parallelization: - * - * \code - * #include - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_fill_n(thrust::device, array, N, val); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_fill.html - * \see \c uninitialized_fill - * \see \c fill - * \see \c uninitialized_copy_n - * \see \c device_new - * \see \c device_malloc - */ -template - ForwardIterator uninitialized_fill_n(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - Size n, - const T &x); - - -/*! In \c thrust, the function \c thrust::device_new allocates memory for - * an object and then creates an object at that location by calling a - * constructor. Occasionally, however, it is useful to separate those two - * operations. If each iterator in the range [first, first+n) points - * to unitialized memory, then \p unitialized_fill creates copies of \c x - * in that range. That is, for each iterator \c i in the range [first, first+n), - * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by - * calling \p ForwardIterator's \c value_type's copy constructor. - * - * \param first The first element of the range of interest. - * \param n The size of the range of interest. - * \param x The value to use as the exemplar of the copy constructor. - * \return first+n - * - * \tparam ForwardIterator is a model of Forward Iterator, - * \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that - * takes a single argument of type \p T. - * - * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of - * uninitialized memory. - * - * \code - * #include - * #include - * - * struct Int - * { - * __host__ __device__ - * Int(int x) : val(x) {} - * int val; - * }; - * ... - * const int N = 137; - * - * Int val(46); - * thrust::device_ptr array = thrust::device_malloc(N); - * thrust::uninitialized_fill_n(array, N, val); - * - * // Int x = array[i]; - * // x.val == 46 for all 0 <= i < N - * \endcode - * - * \see http://www.sgi.com/tech/stl/uninitialized_fill.html - * \see \c uninitialized_fill - * \see \c fill - * \see \c uninitialized_copy_n - * \see \c device_new - * \see \c device_malloc - */ -template - ForwardIterator uninitialized_fill_n(ForwardIterator first, - Size n, - const T &x); - -/*! \} // end filling - * \} // transformations - */ - -} // end thrust - -#include - diff --git a/compat/thrust/unique.h b/compat/thrust/unique.h deleted file mode 100644 index 98150f3..0000000 --- a/compat/thrust/unique.h +++ /dev/null @@ -1,960 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/*! \file unique.h - * \brief Move unique elements to the front of a range - */ - -#pragma once - -#include -#include -#include - -namespace thrust -{ - - -/*! \addtogroup stream_compaction - * \{ - */ - - -/*! For each group of consecutive elements in the range [first, last) - * with the same value, \p unique removes all but the first element of - * the group. The return value is an iterator \c new_last such that - * no two consecutive elements in the range [first, new_last) are - * equal. The iterators in the range [new_last, last) are all still - * dereferenceable, but the elements that they point to are unspecified. - * \p unique is stable, meaning that the relative order of elements that are - * not removed is unchanged. - * - * This version of \p unique uses \c operator== to test for equality. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input range. - * \param last The end of the input range. - * \return The end of the unique range [first, new_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is a model of Equality Comparable. - * - * The following code snippet demonstrates how to use \p unique to - * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution policy - * for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int *new_end = thrust::unique(thrust::host, A, A + N); - * // The first four values of A are now {1, 3, 2, 1} - * // Values beyond new_end are unspecified. - * \endcode - * - * \see http://www.sgi.com/tech/stl/unique.html - * \see unique_copy - */ -template -ForwardIterator unique(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last); - - -/*! For each group of consecutive elements in the range [first, last) - * with the same value, \p unique removes all but the first element of - * the group. The return value is an iterator \c new_last such that - * no two consecutive elements in the range [first, new_last) are - * equal. The iterators in the range [new_last, last) are all still - * dereferenceable, but the elements that they point to are unspecified. - * \p unique is stable, meaning that the relative order of elements that are - * not removed is unchanged. - * - * This version of \p unique uses \c operator== to test for equality. - * - * \param first The beginning of the input range. - * \param last The end of the input range. - * \return The end of the unique range [first, new_last). - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is a model of Equality Comparable. - * - * The following code snippet demonstrates how to use \p unique to - * compact a sequence of numbers to remove consecutive duplicates. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int *new_end = thrust::unique(A, A + N); - * // The first four values of A are now {1, 3, 2, 1} - * // Values beyond new_end are unspecified. - * \endcode - * - * \see http://www.sgi.com/tech/stl/unique.html - * \see unique_copy - */ -template -ForwardIterator unique(ForwardIterator first, - ForwardIterator last); - - -/*! For each group of consecutive elements in the range [first, last) - * with the same value, \p unique removes all but the first element of - * the group. The return value is an iterator \c new_last such that - * no two consecutive elements in the range [first, new_last) are - * equal. The iterators in the range [new_last, last) are all still - * dereferenceable, but the elements that they point to are unspecified. - * \p unique is stable, meaning that the relative order of elements that are - * not removed is unchanged. - * - * This version of \p unique uses the function object \p binary_pred to test - * for equality. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param binary_pred The binary predicate used to determine equality. - * \return The end of the unique range [first, new_last) - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type and to \p BinaryPredicate's \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p unique to - * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution policy - * for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int *new_end = thrust::unique(thrust::host, A, A + N, thrust::equal_to()); - * // The first four values of A are now {1, 3, 2, 1} - * // Values beyond new_end are unspecified. - * \endcode - * - * \see http://www.sgi.com/tech/stl/unique.html - * \see unique_copy - */ -template -ForwardIterator unique(const thrust::detail::execution_policy_base &exec, - ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred); - - -/*! For each group of consecutive elements in the range [first, last) - * with the same value, \p unique removes all but the first element of - * the group. The return value is an iterator \c new_last such that - * no two consecutive elements in the range [first, new_last) are - * equal. The iterators in the range [new_last, last) are all still - * dereferenceable, but the elements that they point to are unspecified. - * \p unique is stable, meaning that the relative order of elements that are - * not removed is unchanged. - * - * This version of \p unique uses the function object \p binary_pred to test - * for equality. - * - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param binary_pred The binary predicate used to determine equality. - * \return The end of the unique range [first, new_last) - * - * \tparam ForwardIterator is a model of Forward Iterator, - * and \p ForwardIterator is mutable, - * and \p ForwardIterator's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type and to \p BinaryPredicate's \c second_argument_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * The following code snippet demonstrates how to use \p unique to - * compact a sequence of numbers to remove consecutive duplicates. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int *new_end = thrust::unique(A, A + N, thrust::equal_to()); - * // The first four values of A are now {1, 3, 2, 1} - * // Values beyond new_end are unspecified. - * \endcode - * - * \see http://www.sgi.com/tech/stl/unique.html - * \see unique_copy - */ -template -ForwardIterator unique(ForwardIterator first, - ForwardIterator last, - BinaryPredicate binary_pred); - - -/*! \p unique_copy copies elements from the range [first, last) - * to a range beginning with \p result, except that in a consecutive group - * of duplicate elements only the first one is copied. The return value - * is the end of the range to which the elements are copied. - * - * The reason there are two different versions of unique_copy is that there - * are two different definitions of what it means for a consecutive group of - * elements to be duplicates. In the first version, the test is simple - * equality: the elements in a range [f, l) are duplicates if, - * for every iterator \p i in the range, either i == f or else - * *i == *(i-1). In the second, the test is an arbitrary - * \p BinaryPredicate \p binary_pred: the elements in [f, l) are - * duplicates if, for every iterator \p i in the range, either i == f - * or else binary_pred(*i, *(i-1)) is \p true. - * - * This version of \p unique_copy uses \c operator== to test for equality. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \return The end of the unique range [result, result_end). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is a model of Equality Comparable. - * \tparam OutputIterator is a model of Output Iterator and - * and \p InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. - * - * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_copy to - * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int B[N]; - * int *result_end = thrust::unique_copy(thrust::host, A, A + N, B); - * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 - * // Values beyond result_end are unspecified - * \endcode - * - * \see unique - * \see http://www.sgi.com/tech/stl/unique_copy.html - */ -template -OutputIterator unique_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p unique_copy copies elements from the range [first, last) - * to a range beginning with \p result, except that in a consecutive group - * of duplicate elements only the first one is copied. The return value - * is the end of the range to which the elements are copied. - * - * The reason there are two different versions of unique_copy is that there - * are two different definitions of what it means for a consecutive group of - * elements to be duplicates. In the first version, the test is simple - * equality: the elements in a range [f, l) are duplicates if, - * for every iterator \p i in the range, either i == f or else - * *i == *(i-1). In the second, the test is an arbitrary - * \p BinaryPredicate \p binary_pred: the elements in [f, l) are - * duplicates if, for every iterator \p i in the range, either i == f - * or else binary_pred(*i, *(i-1)) is \p true. - * - * This version of \p unique_copy uses \c operator== to test for equality. - * - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \return The end of the unique range [result, result_end). - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is a model of Equality Comparable. - * \tparam OutputIterator is a model of Output Iterator and - * and \p InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. - * - * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_copy to - * compact a sequence of numbers to remove consecutive duplicates. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int B[N]; - * int *result_end = thrust::unique_copy(A, A + N, B); - * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 - * // Values beyond result_end are unspecified - * \endcode - * - * \see unique - * \see http://www.sgi.com/tech/stl/unique_copy.html - */ -template -OutputIterator unique_copy(InputIterator first, - InputIterator last, - OutputIterator result); - - -/*! \p unique_copy copies elements from the range [first, last) - * to a range beginning with \p result, except that in a consecutive group - * of duplicate elements only the first one is copied. The return value - * is the end of the range to which the elements are copied. - * - * This version of \p unique_copy uses the function object \c binary_pred - * to test for equality. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \param binary_pred The binary predicate used to determine equality. - * \return The end of the unique range [result, result_end). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is a model of Equality Comparable. - * \tparam OutputIterator is a model of Output Iterator and - * and \p InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_copy to - * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution - * policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int B[N]; - * int *result_end = thrust::unique_copy(thrust::host, A, A + N, B, thrust::equal_to()); - * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 - * // Values beyond result_end are unspecified. - * \endcode - * - * \see unique - * \see http://www.sgi.com/tech/stl/unique_copy.html - */ -template -OutputIterator unique_copy(const thrust::detail::execution_policy_base &exec, - InputIterator first, - InputIterator last, - OutputIterator result, - BinaryPredicate binary_pred); - - -/*! \p unique_copy copies elements from the range [first, last) - * to a range beginning with \p result, except that in a consecutive group - * of duplicate elements only the first one is copied. The return value - * is the end of the range to which the elements are copied. - * - * This version of \p unique_copy uses the function object \c binary_pred - * to test for equality. - * - * \param first The beginning of the input range. - * \param last The end of the input range. - * \param result The beginning of the output range. - * \param binary_pred The binary predicate used to determine equality. - * \return The end of the unique range [result, result_end). - * - * \tparam InputIterator is a model of Input Iterator, - * and \p InputIterator's \c value_type is a model of Equality Comparable. - * \tparam OutputIterator is a model of Output Iterator and - * and \p InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_copy to - * compact a sequence of numbers to remove consecutive duplicates. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; - * int B[N]; - * int *result_end = thrust::unique_copy(A, A + N, B, thrust::equal_to()); - * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 - * // Values beyond result_end are unspecified. - * \endcode - * - * \see unique - * \see http://www.sgi.com/tech/stl/unique_copy.html - */ -template -OutputIterator unique_copy(InputIterator first, - InputIterator last, - OutputIterator result, - BinaryPredicate binary_pred); - - -/*! \p unique_by_key is a generalization of \p unique to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key removes all but the first element of - * the group. Similarly, the corresponding values in the range - * [values_first, values_first + (keys_last - keys_first)) - * are also removed. - * - * The return value is a \p pair of iterators (new_keys_last,new_values_last) - * such that no two consecutive elements in the range [keys_first, new_keys_last) - * are equal. - * - * This version of \p unique_by_key uses \c operator== to test for equality and - * \c project1st to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the key range. - * \param keys_last The end of the key range. - * \param values_first The beginning of the value range. - * \return A pair of iterators at end of the ranges [key_first, keys_new_last) and [values_first, values_new_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator1 is a model of Forward Iterator, - * and \p ForwardIterator1 is mutable, - * and \p ForwardIterator's \c value_type is a model of Equality Comparable. - * \tparam ForwardIterator2 is a model of Forward Iterator, - * and \p ForwardIterator2 is mutable. - * - * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - keys_first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_by_key to - * compact a sequence of key/value pairs to remove consecutive duplicates using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values - * - * thrust::pair new_end; - * new_end = thrust::unique_by_key(thrust::host, A, A + N, B); - * - * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. - * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. - * \endcode - * - * \see unique - * \see unique_by_key_copy - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key(const thrust::detail::execution_policy_base &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first); - - -/*! \p unique_by_key is a generalization of \p unique to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key removes all but the first element of - * the group. Similarly, the corresponding values in the range - * [values_first, values_first + (keys_last - keys_first)) - * are also removed. - * - * The return value is a \p pair of iterators (new_keys_last,new_values_last) - * such that no two consecutive elements in the range [keys_first, new_keys_last) - * are equal. - * - * This version of \p unique_by_key uses \c operator== to test for equality and - * \c project1st to reduce values with equal keys. - * - * \param keys_first The beginning of the key range. - * \param keys_last The end of the key range. - * \param values_first The beginning of the value range. - * \return A pair of iterators at end of the ranges [key_first, keys_new_last) and [values_first, values_new_last). - * - * \tparam ForwardIterator1 is a model of Forward Iterator, - * and \p ForwardIterator1 is mutable, - * and \p ForwardIterator's \c value_type is a model of Equality Comparable. - * \tparam ForwardIterator2 is a model of Forward Iterator, - * and \p ForwardIterator2 is mutable. - * - * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - keys_first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_by_key to - * compact a sequence of key/value pairs to remove consecutive duplicates. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values - * - * thrust::pair new_end; - * new_end = thrust::unique_by_key(A, A + N, B); - * - * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. - * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. - * \endcode - * - * \see unique - * \see unique_by_key_copy - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key(ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first); - - -/*! \p unique_by_key is a generalization of \p unique to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key removes all but the first element of - * the group. Similarly, the corresponding values in the range - * [values_first, values_first + (keys_last - keys_first)) - * are also removed. - * - * This version of \p unique_by_key uses the function object \c binary_pred - * to test for equality and \c project1st to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the key range. - * \param keys_last The end of the key range. - * \param values_first The beginning of the value range. - * \param binary_pred The binary predicate used to determine equality. - * \return The end of the unique range [first, new_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam ForwardIterator1 is a model of Forward Iterator, - * and \p ForwardIterator1 is mutable, - * and \p ForwardIterator's \c value_type is a model of Equality Comparable. - * \tparam ForwardIterator2 is a model of Forward Iterator, - * and \p ForwardIterator2 is mutable. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - keys_first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_by_key to - * compact a sequence of key/value pairs to remove consecutive duplicates using the \p thrust::host - * execution policy for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * new_end = thrust::unique_by_key(thrust::host, keys, keys + N, values, binary_pred); - * - * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. - * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. - * \endcode - * - * \see unique - * \see unique_by_key_copy - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key(const thrust::detail::execution_policy_base &exec, - ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred); - - -/*! \p unique_by_key is a generalization of \p unique to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key removes all but the first element of - * the group. Similarly, the corresponding values in the range - * [values_first, values_first + (keys_last - keys_first)) - * are also removed. - * - * This version of \p unique_by_key uses the function object \c binary_pred - * to test for equality and \c project1st to reduce values with equal keys. - * - * \param keys_first The beginning of the key range. - * \param keys_last The end of the key range. - * \param values_first The beginning of the value range. - * \param binary_pred The binary predicate used to determine equality. - * \return The end of the unique range [first, new_last). - * - * \tparam ForwardIterator1 is a model of Forward Iterator, - * and \p ForwardIterator1 is mutable, - * and \p ForwardIterator's \c value_type is a model of Equality Comparable. - * \tparam ForwardIterator2 is a model of Forward Iterator, - * and \p ForwardIterator2 is mutable. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - keys_first)) shall not overlap. - * - * The following code snippet demonstrates how to use \p unique_by_key to - * compact a sequence of key/value pairs to remove consecutive duplicates. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * new_end = thrust::unique_by_key(keys, keys + N, values, binary_pred); - * - * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. - * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. - * \endcode - * - * \see unique - * \see unique_by_key_copy - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key(ForwardIterator1 keys_first, - ForwardIterator1 keys_last, - ForwardIterator2 values_first, - BinaryPredicate binary_pred); - - -/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key_copy copies the first element of the group to - * a range beginning with \c keys_result and the corresponding values from the range - * [values_first, values_first + (keys_last - keys_first)) are copied to a range - * beginning with \c values_result. - * - * This version of \p unique_by_key_copy uses \c operator== to test for equality and - * \c project1st to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_result The beginning of the output key range. - * \param values_result The beginning of the output value range. - * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, values_result_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p unique_by_key_copy to - * compact a sequence of key/value pairs and with equal keys using the \p thrust::host execution policy - * for parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * new_end = thrust::unique_by_key_copy(thrust::host, A, A + N, B, C, D); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. - * \endcode - * - * \see unique_copy - * \see unique_by_key - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key_copy copies the first element of the group to - * a range beginning with \c keys_result and the corresponding values from the range - * [values_first, values_first + (keys_last - keys_first)) are copied to a range - * beginning with \c values_result. - * - * This version of \p unique_by_key_copy uses \c operator== to test for equality and - * \c project1st to reduce values with equal keys. - * - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_result The beginning of the output key range. - * \param values_result The beginning of the output value range. - * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, values_result_last). - * - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p unique_by_key_copy to - * compact a sequence of key/value pairs and with equal keys. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * new_end = thrust::unique_by_key_copy(A, A + N, B, C, D); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. - * \endcode - * - * \see unique_copy - * \see unique_by_key - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key_copy(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_result, - OutputIterator2 values_result); - - -/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key_copy copies the first element of the group to - * a range beginning with \c keys_result and the corresponding values from the range - * [values_first, values_first + (keys_last - keys_first)) are copied to a range - * beginning with \c values_result. - * - * This version of \p unique_by_key_copy uses the function object \c binary_pred - * to test for equality and \c project1st to reduce values with equal keys. - * - * The algorithm's execution is parallelized as determined by \p exec. - * - * \param exec The execution policy to use for parallelization. - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_result The beginning of the output key range. - * \param values_result The beginning of the output value range. - * \param binary_pred The binary predicate used to determine equality. - * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, values_result_last). - * - * \tparam DerivedPolicy The name of the derived execution policy. - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p unique_by_key_copy to - * compact a sequence of key/value pairs and with equal keys using the \p thrust::host execution policy for - * parallelization: - * - * \code - * #include - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * new_end = thrust::unique_by_key_copy(thrust::host, A, A + N, B, C, D, binary_pred); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. - * \endcode - * - * \see unique_copy - * \see unique_by_key - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key_copy(const thrust::detail::execution_policy_base &exec, - InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_result, - OutputIterator2 values_result, - BinaryPredicate binary_pred); - - -/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. - * For each group of consecutive keys in the range [keys_first, keys_last) - * that are equal, \p unique_by_key_copy copies the first element of the group to - * a range beginning with \c keys_result and the corresponding values from the range - * [values_first, values_first + (keys_last - keys_first)) are copied to a range - * beginning with \c values_result. - * - * This version of \p unique_by_key_copy uses the function object \c binary_pred - * to test for equality and \c project1st to reduce values with equal keys. - * - * \param keys_first The beginning of the input key range. - * \param keys_last The end of the input key range. - * \param values_first The beginning of the input value range. - * \param keys_result The beginning of the output key range. - * \param values_result The beginning of the output value range. - * \param binary_pred The binary predicate used to determine equality. - * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, values_result_last). - * - * \tparam InputIterator1 is a model of Input Iterator, - * \tparam InputIterator2 is a model of Input Iterator, - * \tparam OutputIterator1 is a model of Output Iterator and - * and \p InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. - * \tparam OutputIterator2 is a model of Output Iterator and - * and \p InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. - * \tparam BinaryPredicate is a model of Binary Predicate. - * - * \pre The input ranges shall not overlap either output range. - * - * The following code snippet demonstrates how to use \p unique_by_key_copy to - * compact a sequence of key/value pairs and with equal keys. - * - * \code - * #include - * ... - * const int N = 7; - * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys - * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values - * int C[N]; // output keys - * int D[N]; // output values - * - * thrust::pair new_end; - * thrust::equal_to binary_pred; - * new_end = thrust::unique_by_key_copy(A, A + N, B, C, D, binary_pred); - * - * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. - * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. - * \endcode - * - * \see unique_copy - * \see unique_by_key - * \see reduce_by_key - */ -template - thrust::pair - unique_by_key_copy(InputIterator1 keys_first, - InputIterator1 keys_last, - InputIterator2 values_first, - OutputIterator1 keys_result, - OutputIterator2 values_result, - BinaryPredicate binary_pred); - - -/*! \} // end stream_compaction - */ - - -} // end namespace thrust - -#include - diff --git a/compat/thrust/version.h b/compat/thrust/version.h deleted file mode 100644 index 730997e..0000000 --- a/compat/thrust/version.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2008-2012 NVIDIA Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*! \file version.h - * \brief Compile-time macros encoding Thrust release version - * - * is the only Thrust header that is guaranteed to - * change with every thrust release. - */ - -#pragma once - -#include - -// This is the only thrust header that is guaranteed to -// change with every thrust release. -// -// THRUST_VERSION % 100 is the sub-minor version -// THRUST_VERSION / 100 % 1000 is the minor version -// THRUST_VERSION / 100000 is the major version - -/*! \def THRUST_VERSION - * \brief The preprocessor macro \p THRUST_VERSION encodes the version - * number of the Thrust library. - * - * THRUST_VERSION % 100 is the sub-minor version. - * THRUST_VERSION / 100 % 1000 is the minor version. - * THRUST_VERSION / 100000 is the major version. - */ -#define THRUST_VERSION 100700 - -/*! \def THRUST_MAJOR_VERSION - * \brief The preprocessor macro \p THRUST_MAJOR_VERSION encodes the - * major version number of the Thrust library. - */ -#define THRUST_MAJOR_VERSION (THRUST_VERSION / 100000) - -/*! \def THRUST_MINOR_VERSION - * \brief The preprocessor macro \p THRUST_MINOR_VERSION encodes the - * minor version number of the Thrust library. - */ -#define THRUST_MINOR_VERSION (THRUST_VERSION / 100 % 1000) - -/*! \def THRUST_SUBMINOR_VERSION - * \brief The preprocessor macro \p THRUST_SUBMINOR_VERSION encodes the - * sub-minor version number of the Thrust library. - */ -#define THRUST_SUBMINOR_VERSION (THRUST_VERSION % 100) - -// Declare these namespaces here for the purpose of Doxygenating them - -/*! \namespace thrust - * \brief \p thrust is the top-level namespace which contains all Thrust - * functions and types. - */ -namespace thrust -{ - -} - diff --git a/config.guess b/config.guess index f32079a..ba7abeb 100644 --- a/config.guess +++ b/config.guess @@ -1524,3 +1524,4 @@ exit 1 # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: + diff --git a/config.sub b/config.sub index 6759825..d60a830 100644 --- a/config.sub +++ b/config.sub @@ -1656,3 +1656,4 @@ exit # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: + diff --git a/configure b/configure deleted file mode 100755 index f7b8197..0000000 --- a/configure +++ /dev/null @@ -1,8048 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for ccminer 2014.05.03. -# -# -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software -# Foundation, Inc. -# -# -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. -## -------------------- ## -## M4sh Initialization. ## -## -------------------- ## - -# Be more Bourne compatible -DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in #( - *posix*) : - set -o posix ;; #( - *) : - ;; -esac -fi - - -as_nl=' -' -export as_nl -# Printing a long string crashes Solaris 7 /usr/bin/printf. -as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -# Prefer a ksh shell builtin over an external printf program on Solaris, -# but without wasting forks for bash or zsh. -if test -z "$BASH_VERSION$ZSH_VERSION" \ - && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='print -r --' - as_echo_n='print -rn --' -elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='printf %s\n' - as_echo_n='printf %s' -else - if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then - as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' - as_echo_n='/usr/ucb/echo -n' - else - as_echo_body='eval expr "X$1" : "X\\(.*\\)"' - as_echo_n_body='eval - arg=$1; - case $arg in #( - *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; - esac; - expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" - ' - export as_echo_n_body - as_echo_n='sh -c $as_echo_n_body as_echo' - fi - export as_echo_body - as_echo='sh -c $as_echo_body as_echo' -fi - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - PATH_SEPARATOR=: - (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { - (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || - PATH_SEPARATOR=';' - } -fi - - -# IFS -# We need space, tab and new line, in precisely that order. Quoting is -# there to prevent editors from complaining about space-tab. -# (If _AS_PATH_WALK were called with IFS unset, it would disable word -# splitting by setting IFS to empty value.) -IFS=" "" $as_nl" - -# Find who we are. Look in the path if we contain no directory separator. -as_myself= -case $0 in #(( - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break - done -IFS=$as_save_IFS - - ;; -esac -# We did not find ourselves, most probably we were run as `sh COMMAND' -# in which case we are not to be found in the path. -if test "x$as_myself" = x; then - as_myself=$0 -fi -if test ! -f "$as_myself"; then - $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 - exit 1 -fi - -# Unset variables that we do not need and which cause bugs (e.g. in -# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" -# suppresses any "Segmentation fault" message there. '((' could -# trigger a bug in pdksh 5.2.14. -for as_var in BASH_ENV ENV MAIL MAILPATH -do eval test x\${$as_var+set} = xset \ - && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : -done -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# CDPATH. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -if test "x$CONFIG_SHELL" = x; then - as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which - # is contrary to our usage. Disable this feature. - alias -g '\${1+\"\$@\"}'='\"\$@\"' - setopt NO_GLOB_SUBST -else - case \`(set -o) 2>/dev/null\` in #( - *posix*) : - set -o posix ;; #( - *) : - ;; -esac -fi -" - as_required="as_fn_return () { (exit \$1); } -as_fn_success () { as_fn_return 0; } -as_fn_failure () { as_fn_return 1; } -as_fn_ret_success () { return 0; } -as_fn_ret_failure () { return 1; } - -exitcode=0 -as_fn_success || { exitcode=1; echo as_fn_success failed.; } -as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } -as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } -as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } -if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : - -else - exitcode=1; echo positional parameters were not saved. -fi -test x\$exitcode = x0 || exit 1" - as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO - as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO - eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && - test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 -test \$(( 1 + 1 )) = 2 || exit 1" - if (eval "$as_required") 2>/dev/null; then : - as_have_required=yes -else - as_have_required=no -fi - if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : - -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -as_found=false -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - as_found=: - case $as_dir in #( - /*) - for as_base in sh bash ksh sh5; do - # Try only shells that exist, to save several forks. - as_shell=$as_dir/$as_base - if { test -f "$as_shell" || test -f "$as_shell.exe"; } && - { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : - CONFIG_SHELL=$as_shell as_have_required=yes - if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : - break 2 -fi -fi - done;; - esac - as_found=false -done -$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && - { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : - CONFIG_SHELL=$SHELL as_have_required=yes -fi; } -IFS=$as_save_IFS - - - if test "x$CONFIG_SHELL" != x; then : - # We cannot yet assume a decent shell, so we have to provide a - # neutralization value for shells without unset; and this also - # works around shells that cannot unset nonexistent variables. - # Preserve -v and -x to the replacement shell. - BASH_ENV=/dev/null - ENV=/dev/null - (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV - export CONFIG_SHELL - case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; - esac - exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} -fi - - if test x$as_have_required = xno; then : - $as_echo "$0: This script requires a shell more modern than all" - $as_echo "$0: the shells that I found on your system." - if test x${ZSH_VERSION+set} = xset ; then - $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" - $as_echo "$0: be upgraded to zsh 4.3.4 or later." - else - $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, -$0: including any error possibly output before this -$0: message. Then install a modern shell, or manually run -$0: the script under such a shell if you do have one." - fi - exit 1 -fi -fi -fi -SHELL=${CONFIG_SHELL-/bin/sh} -export SHELL -# Unset more variables known to interfere with behavior of common tools. -CLICOLOR_FORCE= GREP_OPTIONS= -unset CLICOLOR_FORCE GREP_OPTIONS - -## --------------------- ## -## M4sh Shell Functions. ## -## --------------------- ## -# as_fn_unset VAR -# --------------- -# Portably unset VAR. -as_fn_unset () -{ - { eval $1=; unset $1;} -} -as_unset=as_fn_unset - -# as_fn_set_status STATUS -# ----------------------- -# Set $? to STATUS, without forking. -as_fn_set_status () -{ - return $1 -} # as_fn_set_status - -# as_fn_exit STATUS -# ----------------- -# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. -as_fn_exit () -{ - set +e - as_fn_set_status $1 - exit $1 -} # as_fn_exit - -# as_fn_mkdir_p -# ------------- -# Create "$as_dir" as a directory, including parents if necessary. -as_fn_mkdir_p () -{ - - case $as_dir in #( - -*) as_dir=./$as_dir;; - esac - test -d "$as_dir" || eval $as_mkdir_p || { - as_dirs= - while :; do - case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( - *) as_qdir=$as_dir;; - esac - as_dirs="'$as_qdir' $as_dirs" - as_dir=`$as_dirname -- "$as_dir" || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - test -d "$as_dir" && break - done - test -z "$as_dirs" || eval "mkdir $as_dirs" - } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" - - -} # as_fn_mkdir_p -# as_fn_append VAR VALUE -# ---------------------- -# Append the text in VALUE to the end of the definition contained in VAR. Take -# advantage of any shell optimizations that allow amortized linear growth over -# repeated appends, instead of the typical quadratic growth present in naive -# implementations. -if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : - eval 'as_fn_append () - { - eval $1+=\$2 - }' -else - as_fn_append () - { - eval $1=\$$1\$2 - } -fi # as_fn_append - -# as_fn_arith ARG... -# ------------------ -# Perform arithmetic evaluation on the ARGs, and store the result in the -# global $as_val. Take advantage of shells that can avoid forks. The arguments -# must be portable across $(()) and expr. -if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : - eval 'as_fn_arith () - { - as_val=$(( $* )) - }' -else - as_fn_arith () - { - as_val=`expr "$@" || test $? -eq 1` - } -fi # as_fn_arith - - -# as_fn_error STATUS ERROR [LINENO LOG_FD] -# ---------------------------------------- -# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are -# provided, also output the error to LOG_FD, referencing LINENO. Then exit the -# script with STATUS, using 1 if that was 0. -as_fn_error () -{ - as_status=$1; test $as_status -eq 0 && as_status=1 - if test "$4"; then - as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 - fi - $as_echo "$as_me: error: $2" >&2 - as_fn_exit $as_status -} # as_fn_error - -if expr a : '\(a\)' >/dev/null 2>&1 && - test "X`expr 00001 : '.*\(...\)'`" = X001; then - as_expr=expr -else - as_expr=false -fi - -if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - -if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then - as_dirname=dirname -else - as_dirname=false -fi - -as_me=`$as_basename -- "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ - s//\1/ - q - } - /^X\/\(\/\/\)$/{ - s//\1/ - q - } - /^X\/\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - - - as_lineno_1=$LINENO as_lineno_1a=$LINENO - as_lineno_2=$LINENO as_lineno_2a=$LINENO - eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && - test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { - # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) - sed -n ' - p - /[$]LINENO/= - ' <$as_myself | - sed ' - s/[$]LINENO.*/&-/ - t lineno - b - :lineno - N - :loop - s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ - t loop - s/-\n.*// - ' >$as_me.lineno && - chmod +x "$as_me.lineno" || - { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensitive to this). - . "./$as_me.lineno" - # Exit status is that of the last command. - exit -} - -ECHO_C= ECHO_N= ECHO_T= -case `echo -n x` in #((((( --n*) - case `echo 'xy\c'` in - *c*) ECHO_T=' ';; # ECHO_T is single tab character. - xy) ECHO_C='\c';; - *) echo `echo ksh88 bug on AIX 6.1` > /dev/null - ECHO_T=' ';; - esac;; -*) - ECHO_N='-n';; -esac - -rm -f conf$$ conf$$.exe conf$$.file -if test -d conf$$.dir; then - rm -f conf$$.dir/conf$$.file -else - rm -f conf$$.dir - mkdir conf$$.dir 2>/dev/null -fi -if (echo >conf$$.file) 2>/dev/null; then - if ln -s conf$$.file conf$$ 2>/dev/null; then - as_ln_s='ln -s' - # ... but there are two gotchas: - # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. - # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. - ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' - elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln - else - as_ln_s='cp -p' - fi -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file -rmdir conf$$.dir 2>/dev/null - -if mkdir -p . 2>/dev/null; then - as_mkdir_p='mkdir -p "$as_dir"' -else - test -d ./-p && rmdir ./-p - as_mkdir_p=false -fi - -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" - - -test -n "$DJDIR" || exec 7<&0 &1 - -# Name of the host. -# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -# -# Initializations. -# -ac_default_prefix=/usr/local -ac_clean_files= -ac_config_libobj_dir=. -LIBOBJS= -cross_compiling=no -subdirs= -MFLAGS= -MAKEFLAGS= - -# Identity of this package. -PACKAGE_NAME='ccminer' -PACKAGE_TARNAME='ccminer' -PACKAGE_VERSION='2014.05.03' -PACKAGE_STRING='ccminer 2014.05.03' -PACKAGE_BUGREPORT='' -PACKAGE_URL='' - -ac_unique_file="cpu-miner.c" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif -#endif -#ifdef HAVE_STRING_H -# if !defined STDC_HEADERS && defined HAVE_MEMORY_H -# include -# endif -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif -#ifdef HAVE_INTTYPES_H -# include -#endif -#ifdef HAVE_STDINT_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif" - -ac_subst_vars='am__EXEEXT_FALSE -am__EXEEXT_TRUE -LTLIBOBJS -LIBOBJS -NVCC -CUDA_LDFLAGS -CUDA_LIBS -CUDA_CFLAGS -WS2_LIBS -PTHREAD_LIBS -PTHREAD_FLAGS -JANSSON_LIBS -LIBCURL -LIBCURL_CPPFLAGS -_libcurl_config -ARCH_x86_64_FALSE -ARCH_x86_64_TRUE -ARCH_x86_FALSE -ARCH_x86_TRUE -HAVE_WINDOWS_FALSE -HAVE_WINDOWS_TRUE -WANT_JANSSON_FALSE -WANT_JANSSON_TRUE -ALLOCA -OPENMP_CFLAGS -am__fastdepCXX_FALSE -am__fastdepCXX_TRUE -CXXDEPMODE -ac_ct_CXX -CXXFLAGS -CXX -RANLIB -am__fastdepCCAS_FALSE -am__fastdepCCAS_TRUE -CCASDEPMODE -CCASFLAGS -CCAS -EGREP -GREP -CPP -am__fastdepCC_FALSE -am__fastdepCC_TRUE -CCDEPMODE -am__nodep -AMDEPBACKSLASH -AMDEP_FALSE -AMDEP_TRUE -am__quote -am__include -DEPDIR -OBJEXT -EXEEXT -ac_ct_CC -CPPFLAGS -LDFLAGS -CFLAGS -CC -MAINT -MAINTAINER_MODE_FALSE -MAINTAINER_MODE_TRUE -am__untar -am__tar -AMTAR -am__leading_dot -SET_MAKE -AWK -mkdir_p -MKDIR_P -INSTALL_STRIP_PROGRAM -STRIP -install_sh -MAKEINFO -AUTOHEADER -AUTOMAKE -AUTOCONF -ACLOCAL -VERSION -PACKAGE -CYGPATH_W -am__isrc -INSTALL_DATA -INSTALL_SCRIPT -INSTALL_PROGRAM -target_os -target_vendor -target_cpu -target -host_os -host_vendor -host_cpu -host -build_os -build_vendor -build_cpu -build -target_alias -host_alias -build_alias -LIBS -ECHO_T -ECHO_N -ECHO_C -DEFS -mandir -localedir -libdir -psdir -pdfdir -dvidir -htmldir -infodir -docdir -oldincludedir -includedir -localstatedir -sharedstatedir -sysconfdir -datadir -datarootdir -libexecdir -sbindir -bindir -program_transform_name -prefix -exec_prefix -PACKAGE_URL -PACKAGE_BUGREPORT -PACKAGE_STRING -PACKAGE_VERSION -PACKAGE_TARNAME -PACKAGE_NAME -PATH_SEPARATOR -SHELL' -ac_subst_files='' -ac_user_opts=' -enable_option_checking -enable_maintainer_mode -enable_dependency_tracking -enable_openmp -with_libcurl -with_cuda -' - ac_precious_vars='build_alias -host_alias -target_alias -CC -CFLAGS -LDFLAGS -LIBS -CPPFLAGS -CPP -CCAS -CCASFLAGS -CXX -CXXFLAGS -CCC' - - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -ac_unrecognized_opts= -ac_unrecognized_sep= -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -# (The list follows the same order as the GNU Coding Standards.) -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datarootdir='${prefix}/share' -datadir='${datarootdir}' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -includedir='${prefix}/include' -oldincludedir='/usr/include' -docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' -infodir='${datarootdir}/info' -htmldir='${docdir}' -dvidir='${docdir}' -pdfdir='${docdir}' -psdir='${docdir}' -libdir='${exec_prefix}/lib' -localedir='${datarootdir}/locale' -mandir='${datarootdir}/man' - -ac_prev= -ac_dashdash= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval $ac_prev=\$ac_option - ac_prev= - continue - fi - - case $ac_option in - *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; - *=) ac_optarg= ;; - *) ac_optarg=yes ;; - esac - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_dashdash$ac_option in - --) - ac_dashdash=yes ;; - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=*) - datadir=$ac_optarg ;; - - -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ - | --dataroo | --dataro | --datar) - ac_prev=datarootdir ;; - -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ - | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) - datarootdir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: $ac_useropt" - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"enable_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval enable_$ac_useropt=no ;; - - -docdir | --docdir | --docdi | --doc | --do) - ac_prev=docdir ;; - -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) - docdir=$ac_optarg ;; - - -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) - ac_prev=dvidir ;; - -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) - dvidir=$ac_optarg ;; - - -enable-* | --enable-*) - ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: $ac_useropt" - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"enable_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval enable_$ac_useropt=\$ac_optarg ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) - ac_prev=htmldir ;; - -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ - | --ht=*) - htmldir=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localedir | --localedir | --localedi | --localed | --locale) - ac_prev=localedir ;; - -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) - localedir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst | --locals) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c | -n) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) - ac_prev=pdfdir ;; - -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) - pdfdir=$ac_optarg ;; - - -psdir | --psdir | --psdi | --psd | --ps) - ac_prev=psdir ;; - -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) - psdir=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: $ac_useropt" - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"with_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval with_$ac_useropt=\$ac_optarg ;; - - -without-* | --without-*) - ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: $ac_useropt" - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"with_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval with_$ac_useropt=no ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) as_fn_error $? "unrecognized option: \`$ac_option' -Try \`$0 --help' for more information" - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - case $ac_envvar in #( - '' | [0-9]* | *[!_$as_cr_alnum]* ) - as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; - esac - eval $ac_envvar=\$ac_optarg - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && - $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - as_fn_error $? "missing argument to $ac_option" -fi - -if test -n "$ac_unrecognized_opts"; then - case $enable_option_checking in - no) ;; - fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; - *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; - esac -fi - -# Check all directory arguments for consistency. -for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ - datadir sysconfdir sharedstatedir localstatedir includedir \ - oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir -do - eval ac_val=\$$ac_var - # Remove trailing slashes. - case $ac_val in - */ ) - ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` - eval $ac_var=\$ac_val;; - esac - # Be sure to have absolute directory names. - case $ac_val in - [\\/$]* | ?:[\\/]* ) continue;; - NONE | '' ) case $ac_var in *prefix ) continue;; esac;; - esac - as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -# FIXME: To remove some day. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: To remove some day. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used" >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - - -ac_pwd=`pwd` && test -n "$ac_pwd" && -ac_ls_di=`ls -di .` && -ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || - as_fn_error $? "working directory cannot be determined" -test "X$ac_ls_di" = "X$ac_pwd_ls_di" || - as_fn_error $? "pwd does not report name of working directory" - - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then the parent directory. - ac_confdir=`$as_dirname -- "$as_myself" || -$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_myself" : 'X\(//\)[^/]' \| \ - X"$as_myself" : 'X\(//\)$' \| \ - X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_myself" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - srcdir=$ac_confdir - if test ! -r "$srcdir/$ac_unique_file"; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r "$srcdir/$ac_unique_file"; then - test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." - as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" -fi -ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" -ac_abs_confdir=`( - cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" - pwd)` -# When building in place, set srcdir=. -if test "$ac_abs_confdir" = "$ac_pwd"; then - srcdir=. -fi -# Remove unnecessary trailing slashes from srcdir. -# Double slashes in file names in object file debugging info -# mess up M-x gdb in Emacs. -case $srcdir in -*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; -esac -for ac_var in $ac_precious_vars; do - eval ac_env_${ac_var}_set=\${${ac_var}+set} - eval ac_env_${ac_var}_value=\$${ac_var} - eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} - eval ac_cv_env_${ac_var}_value=\$${ac_var} -done - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat <<_ACEOF -\`configure' configures ccminer 2014.05.03 to adapt to many kinds of systems. - -Usage: $0 [OPTION]... [VAR=VALUE]... - -To assign environment variables (e.g., CC, CFLAGS...), specify them as -VAR=VALUE. See below for descriptions of some of the useful variables. - -Defaults for the options are specified in brackets. - -Configuration: - -h, --help display this help and exit - --help=short display options specific to this package - --help=recursive display the short help of all the included packages - -V, --version display version information and exit - -q, --quiet, --silent do not print \`checking ...' messages - --cache-file=FILE cache test results in FILE [disabled] - -C, --config-cache alias for \`--cache-file=config.cache' - -n, --no-create do not create output files - --srcdir=DIR find the sources in DIR [configure dir or \`..'] - -Installation directories: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [PREFIX] - -By default, \`make install' will install all the files in -\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify -an installation prefix other than \`$ac_default_prefix' using \`--prefix', -for instance \`--prefix=\$HOME'. - -For better control, use the options below. - -Fine tuning of the installation directories: - --bindir=DIR user executables [EPREFIX/bin] - --sbindir=DIR system admin executables [EPREFIX/sbin] - --libexecdir=DIR program executables [EPREFIX/libexec] - --sysconfdir=DIR read-only single-machine data [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] - --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --libdir=DIR object code libraries [EPREFIX/lib] - --includedir=DIR C header files [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc [/usr/include] - --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] - --datadir=DIR read-only architecture-independent data [DATAROOTDIR] - --infodir=DIR info documentation [DATAROOTDIR/info] - --localedir=DIR locale-dependent data [DATAROOTDIR/locale] - --mandir=DIR man documentation [DATAROOTDIR/man] - --docdir=DIR documentation root [DATAROOTDIR/doc/ccminer] - --htmldir=DIR html documentation [DOCDIR] - --dvidir=DIR dvi documentation [DOCDIR] - --pdfdir=DIR pdf documentation [DOCDIR] - --psdir=DIR ps documentation [DOCDIR] -_ACEOF - - cat <<\_ACEOF - -Program names: - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM run sed PROGRAM on installed program names - -System types: - --build=BUILD configure for building on BUILD [guessed] - --host=HOST cross-compile to build programs to run on HOST [BUILD] - --target=TARGET configure for building compilers for TARGET [HOST] -_ACEOF -fi - -if test -n "$ac_init_help"; then - case $ac_init_help in - short | recursive ) echo "Configuration of ccminer 2014.05.03:";; - esac - cat <<\_ACEOF - -Optional Features: - --disable-option-checking ignore unrecognized --enable/--with options - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --enable-maintainer-mode enable make rules and dependencies not useful - (and sometimes confusing) to the casual installer - --disable-dependency-tracking speeds up one-time build - --enable-dependency-tracking do not reject slow dependency extractors - --disable-openmp do not use OpenMP - -Optional Packages: - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --with-libcurl=PREFIX look for the curl library in PREFIX/lib and headers - in PREFIX/include - --with-cuda=PATH prefix where cuda is installed default=/usr/local/cuda - -Some influential environment variables: - CC C compiler command - CFLAGS C compiler flags - LDFLAGS linker flags, e.g. -L if you have libraries in a - nonstandard directory - LIBS libraries to pass to the linker, e.g. -l - CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if - you have headers in a nonstandard directory - CPP C preprocessor - CCAS assembler compiler command (defaults to CC) - CCASFLAGS assembler compiler flags (defaults to CFLAGS) - CXX C++ compiler command - CXXFLAGS C++ compiler flags - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -Report bugs to the package provider. -_ACEOF -ac_status=$? -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue - test -d "$ac_dir" || - { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || - continue - ac_builddir=. - -case "$ac_dir" in -.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; -*) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` - # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` - case $ac_top_builddir_sub in - "") ac_top_builddir_sub=. ac_top_build_prefix= ;; - *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; - esac ;; -esac -ac_abs_top_builddir=$ac_pwd -ac_abs_builddir=$ac_pwd$ac_dir_suffix -# for backward compatibility: -ac_top_builddir=$ac_top_build_prefix - -case $srcdir in - .) # We are building in place. - ac_srcdir=. - ac_top_srcdir=$ac_top_builddir_sub - ac_abs_top_srcdir=$ac_pwd ;; - [\\/]* | ?:[\\/]* ) # Absolute name. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir - ac_abs_top_srcdir=$srcdir ;; - *) # Relative name. - ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_build_prefix$srcdir - ac_abs_top_srcdir=$ac_pwd/$srcdir ;; -esac -ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix - - cd "$ac_dir" || { ac_status=$?; continue; } - # Check for guested configure. - if test -f "$ac_srcdir/configure.gnu"; then - echo && - $SHELL "$ac_srcdir/configure.gnu" --help=recursive - elif test -f "$ac_srcdir/configure"; then - echo && - $SHELL "$ac_srcdir/configure" --help=recursive - else - $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 - fi || ac_status=$? - cd "$ac_pwd" || { ac_status=$?; break; } - done -fi - -test -n "$ac_init_help" && exit $ac_status -if $ac_init_version; then - cat <<\_ACEOF -ccminer configure 2014.05.03 -generated by GNU Autoconf 2.68 - -Copyright (C) 2010 Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -_ACEOF - exit -fi - -## ------------------------ ## -## Autoconf initialization. ## -## ------------------------ ## - -# ac_fn_c_try_compile LINENO -# -------------------------- -# Try to compile conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_compile () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext - if { { ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_compile") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_compile - -# ac_fn_c_try_cpp LINENO -# ---------------------- -# Try to preprocess conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_cpp () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } > conftest.i && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_cpp - -# ac_fn_cxx_try_compile LINENO -# ---------------------------- -# Try to compile conftest.$ac_ext, and return whether this succeeded. -ac_fn_cxx_try_compile () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext - if { { ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_compile") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { - test -z "$ac_cxx_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_cxx_try_compile - -# ac_fn_c_try_link LINENO -# ----------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_link () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest$ac_exeext - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information - # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would - # interfere with the next link command; also delete a directory that is - # left behind by Apple's compiler. We do this before executing the actions. - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_link - -# ac_fn_c_try_run LINENO -# ---------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes -# that executables *can* be run. -ac_fn_c_try_run () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then : - ac_retval=0 -else - $as_echo "$as_me: program exited with status $ac_status" >&5 - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=$ac_status -fi - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_run - -# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES -# ------------------------------------------------------- -# Tests whether HEADER exists, giving a warning if it cannot be compiled using -# the include files in INCLUDES and setting the cache variable VAR -# accordingly. -ac_fn_c_check_header_mongrel () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if eval \${$3+:} false; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 -$as_echo_n "checking $2 usability... " >&6; } -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -#include <$2> -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_header_compiler=yes -else - ac_header_compiler=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 -$as_echo_n "checking $2 presence... " >&6; } -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <$2> -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - ac_header_preproc=yes -else - ac_header_preproc=no -fi -rm -f conftest.err conftest.i conftest.$ac_ext -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( - yes:no: ) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} - ;; - no:yes:* ) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} - ;; -esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - eval "$3=\$ac_header_compiler" -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -fi - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_header_mongrel - -# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES -# ------------------------------------------------------- -# Tests whether HEADER exists and can be compiled using the include files in -# INCLUDES, setting the cache variable VAR accordingly. -ac_fn_c_check_header_compile () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -#include <$2> -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - eval "$3=yes" -else - eval "$3=no" -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_header_compile - -# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES -# --------------------------------------------- -# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR -# accordingly. -ac_fn_c_check_decl () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - as_decl_name=`echo $2|sed 's/ *(.*//'` - as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 -$as_echo_n "checking whether $as_decl_name is declared... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -#ifndef $as_decl_name -#ifdef __cplusplus - (void) $as_decl_use; -#else - (void) $as_decl_name; -#endif -#endif - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - eval "$3=yes" -else - eval "$3=no" -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_decl - -# ac_fn_c_check_type LINENO TYPE VAR INCLUDES -# ------------------------------------------- -# Tests whether TYPE exists after having included INCLUDES, setting cache -# variable VAR accordingly. -ac_fn_c_check_type () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - eval "$3=no" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -if (sizeof ($2)) - return 0; - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -if (sizeof (($2))) - return 0; - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - -else - eval "$3=yes" -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_type - -# ac_fn_c_check_func LINENO FUNC VAR -# ---------------------------------- -# Tests whether FUNC exists, setting the cache variable VAR accordingly -ac_fn_c_check_func () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -/* Define $2 to an innocuous variant, in case declares $2. - For example, HP-UX 11i declares gettimeofday. */ -#define $2 innocuous_$2 - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $2 (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $2 - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $2 (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$2 || defined __stub___$2 -choke me -#endif - -int -main () -{ -return $2 (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - eval "$3=yes" -else - eval "$3=no" -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_func -cat >config.log <<_ACEOF -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. - -It was created by ccminer $as_me 2014.05.03, which was -generated by GNU Autoconf 2.68. Invocation command line was - - $ $0 $@ - -_ACEOF -exec 5>>config.log -{ -cat <<_ASUNAME -## --------- ## -## Platform. ## -## --------- ## - -hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -_ASUNAME - -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - $as_echo "PATH: $as_dir" - done -IFS=$as_save_IFS - -} >&5 - -cat >&5 <<_ACEOF - - -## ----------- ## -## Core tests. ## -## ----------- ## - -_ACEOF - - -# Keep a trace of the command line. -# Strip out --no-create and --no-recursion so they do not pile up. -# Strip out --silent because we don't want to record it for future runs. -# Also quote any args containing shell meta-characters. -# Make two passes to allow for proper duplicate-argument suppression. -ac_configure_args= -ac_configure_args0= -ac_configure_args1= -ac_must_keep_next=false -for ac_pass in 1 2 -do - for ac_arg - do - case $ac_arg in - -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - continue ;; - *\'*) - ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - case $ac_pass in - 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; - 2) - as_fn_append ac_configure_args1 " '$ac_arg'" - if test $ac_must_keep_next = true; then - ac_must_keep_next=false # Got value, back to normal. - else - case $ac_arg in - *=* | --config-cache | -C | -disable-* | --disable-* \ - | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ - | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ - | -with-* | --with-* | -without-* | --without-* | --x) - case "$ac_configure_args0 " in - "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; - esac - ;; - -* ) ac_must_keep_next=true ;; - esac - fi - as_fn_append ac_configure_args " '$ac_arg'" - ;; - esac - done -done -{ ac_configure_args0=; unset ac_configure_args0;} -{ ac_configure_args1=; unset ac_configure_args1;} - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -# WARNING: Use '\'' to represent an apostrophe within the trap. -# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - { - echo - - $as_echo "## ---------------- ## -## Cache variables. ## -## ---------------- ##" - echo - # The following way of writing the cache mishandles newlines in values, -( - for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do - eval ac_val=\$$ac_var - case $ac_val in #( - *${as_nl}*) - case $ac_var in #( - *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 -$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; - esac - case $ac_var in #( - _ | IFS | as_nl) ;; #( - BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( - *) { eval $ac_var=; unset $ac_var;} ;; - esac ;; - esac - done - (set) 2>&1 | - case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( - *${as_nl}ac_space=\ *) - sed -n \ - "s/'\''/'\''\\\\'\'''\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" - ;; #( - *) - sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" - ;; - esac | - sort -) - echo - - $as_echo "## ----------------- ## -## Output variables. ## -## ----------------- ##" - echo - for ac_var in $ac_subst_vars - do - eval ac_val=\$$ac_var - case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; - esac - $as_echo "$ac_var='\''$ac_val'\''" - done | sort - echo - - if test -n "$ac_subst_files"; then - $as_echo "## ------------------- ## -## File substitutions. ## -## ------------------- ##" - echo - for ac_var in $ac_subst_files - do - eval ac_val=\$$ac_var - case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; - esac - $as_echo "$ac_var='\''$ac_val'\''" - done | sort - echo - fi - - if test -s confdefs.h; then - $as_echo "## ----------- ## -## confdefs.h. ## -## ----------- ##" - echo - cat confdefs.h - echo - fi - test "$ac_signal" != 0 && - $as_echo "$as_me: caught signal $ac_signal" - $as_echo "$as_me: exit $exit_status" - } >&5 - rm -f core *.core core.conftest.* && - rm -f -r conftest* confdefs* conf$$* $ac_clean_files && - exit $exit_status -' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -f -r conftest* confdefs.h - -$as_echo "/* confdefs.h */" > confdefs.h - -# Predefined preprocessor variables. - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_URL "$PACKAGE_URL" -_ACEOF - - -# Let the site file select an alternate cache file if it wants to. -# Prefer an explicitly selected file to automatically selected ones. -ac_site_file1=NONE -ac_site_file2=NONE -if test -n "$CONFIG_SITE"; then - # We do not want a PATH search for config.site. - case $CONFIG_SITE in #(( - -*) ac_site_file1=./$CONFIG_SITE;; - */*) ac_site_file1=$CONFIG_SITE;; - *) ac_site_file1=./$CONFIG_SITE;; - esac -elif test "x$prefix" != xNONE; then - ac_site_file1=$prefix/share/config.site - ac_site_file2=$prefix/etc/config.site -else - ac_site_file1=$ac_default_prefix/share/config.site - ac_site_file2=$ac_default_prefix/etc/config.site -fi -for ac_site_file in "$ac_site_file1" "$ac_site_file2" -do - test "x$ac_site_file" = xNONE && continue - if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 -$as_echo "$as_me: loading site script $ac_site_file" >&6;} - sed 's/^/| /' "$ac_site_file" >&5 - . "$ac_site_file" \ - || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "failed to load site script $ac_site_file -See \`config.log' for more details" "$LINENO" 5; } - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special files - # actually), so we avoid doing that. DJGPP emulates it as a regular file. - if test /dev/null != "$cache_file" && test -f "$cache_file"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 -$as_echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . "$cache_file";; - *) . "./$cache_file";; - esac - fi -else - { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 -$as_echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_cache_corrupted=false -for ac_var in $ac_precious_vars; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val=\$ac_cv_env_${ac_var}_value - eval ac_new_val=\$ac_env_${ac_var}_value - case $ac_old_set,$ac_new_set in - set,) - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,set) - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 -$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - # differences in whitespace do not lead to failure. - ac_old_val_w=`echo x $ac_old_val` - ac_new_val_w=`echo x $ac_new_val` - if test "$ac_old_val_w" != "$ac_new_val_w"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 -$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} - ac_cache_corrupted=: - else - { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 -$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} - eval $ac_var=\$ac_old_val - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 -$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 -$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} - fi;; - esac - # Pass precious variables to config.status. - if test "$ac_new_set" = set; then - case $ac_new_val in - *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; - *) ac_arg=$ac_var=$ac_new_val ;; - esac - case " $ac_configure_args " in - *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. - *) as_fn_append ac_configure_args " '$ac_arg'" ;; - esac - fi -done -if $ac_cache_corrupted; then - { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 -$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} - as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 -fi -## -------------------- ## -## Main body of script. ## -## -------------------- ## - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - - -ac_aux_dir= -for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do - if test -f "$ac_dir/install-sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f "$ac_dir/install.sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f "$ac_dir/shtool"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 -fi - -# These three variables are undocumented and unsupported, -# and are intended to be withdrawn in a future Autoconf release. -# They can cause serious problems if a builder's source tree is in a directory -# whose full name contains unusual characters. -ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. -ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. -ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. - - -# Make sure we can run config.sub. -$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || - as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 -$as_echo_n "checking build system type... " >&6; } -if ${ac_cv_build+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_build_alias=$build_alias -test "x$ac_build_alias" = x && - ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` -test "x$ac_build_alias" = x && - as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 -ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || - as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 -$as_echo "$ac_cv_build" >&6; } -case $ac_cv_build in -*-*-*) ;; -*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; -esac -build=$ac_cv_build -ac_save_IFS=$IFS; IFS='-' -set x $ac_cv_build -shift -build_cpu=$1 -build_vendor=$2 -shift; shift -# Remember, the first character of IFS is used to create $*, -# except with old shells: -build_os=$* -IFS=$ac_save_IFS -case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 -$as_echo_n "checking host system type... " >&6; } -if ${ac_cv_host+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "x$host_alias" = x; then - ac_cv_host=$ac_cv_build -else - ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || - as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 -$as_echo "$ac_cv_host" >&6; } -case $ac_cv_host in -*-*-*) ;; -*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; -esac -host=$ac_cv_host -ac_save_IFS=$IFS; IFS='-' -set x $ac_cv_host -shift -host_cpu=$1 -host_vendor=$2 -shift; shift -# Remember, the first character of IFS is used to create $*, -# except with old shells: -host_os=$* -IFS=$ac_save_IFS -case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5 -$as_echo_n "checking target system type... " >&6; } -if ${ac_cv_target+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "x$target_alias" = x; then - ac_cv_target=$ac_cv_host -else - ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` || - as_fn_error $? "$SHELL $ac_aux_dir/config.sub $target_alias failed" "$LINENO" 5 -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_target" >&5 -$as_echo "$ac_cv_target" >&6; } -case $ac_cv_target in -*-*-*) ;; -*) as_fn_error $? "invalid value of canonical target" "$LINENO" 5;; -esac -target=$ac_cv_target -ac_save_IFS=$IFS; IFS='-' -set x $ac_cv_target -shift -target_cpu=$1 -target_vendor=$2 -shift; shift -# Remember, the first character of IFS is used to create $*, -# except with old shells: -target_os=$* -IFS=$ac_save_IFS -case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac - - -# The aliases save the names the user supplied, while $host etc. -# will get canonicalized. -test -n "$target_alias" && - test "$program_prefix$program_suffix$program_transform_name" = \ - NONENONEs,x,x, && - program_prefix=${target_alias}- - - -am__api_version='1.11' - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# OS/2's system install, which has a completely different semantic -# ./install, which can be erroneously created by make from ./install.sh. -# Reject install programs that cannot install multiple files. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 -$as_echo_n "checking for a BSD-compatible install... " >&6; } -if test -z "$INSTALL"; then -if ${ac_cv_path_install+:} false; then : - $as_echo_n "(cached) " >&6 -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - # Account for people who put trailing slashes in PATH elements. -case $as_dir/ in #(( - ./ | .// | /[cC]/* | \ - /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ - ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ - /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then - if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - rm -rf conftest.one conftest.two conftest.dir - echo one > conftest.one - echo two > conftest.two - mkdir conftest.dir - if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && - test -s conftest.one && test -s conftest.two && - test -s conftest.dir/conftest.one && - test -s conftest.dir/conftest.two - then - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" - break 3 - fi - fi - fi - done - done - ;; -esac - - done -IFS=$as_save_IFS - -rm -rf conftest.one conftest.two conftest.dir - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. Don't cache a - # value for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the value is a relative name. - INSTALL=$ac_install_sh - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 -$as_echo "$INSTALL" >&6; } - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 -$as_echo_n "checking whether build environment is sane... " >&6; } -# Just in case -sleep 1 -echo timestamp > conftest.file -# Reject unsafe characters in $srcdir or the absolute working directory -# name. Accept space and tab only in the latter. -am_lf=' -' -case `pwd` in - *[\\\"\#\$\&\'\`$am_lf]*) - as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; -esac -case $srcdir in - *[\\\"\#\$\&\'\`$am_lf\ \ ]*) - as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; -esac - -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - rm -f conftest.file - if test "$*" != "X $srcdir/configure conftest.file" \ - && test "$*" != "X conftest.file $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - as_fn_error $? "ls -t appears to fail. Make sure there is not a broken -alias in your environment" "$LINENO" 5 - fi - - test "$2" = conftest.file - ) -then - # Ok. - : -else - as_fn_error $? "newly created file is older than distributed files! -Check your system clock" "$LINENO" 5 -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -test "$program_prefix" != NONE && - program_transform_name="s&^&$program_prefix&;$program_transform_name" -# Use a double $ so make ignores it. -test "$program_suffix" != NONE && - program_transform_name="s&\$&$program_suffix&;$program_transform_name" -# Double any \ or $. -# By default was `s,x,x', remove it if useless. -ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' -program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` - -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` - -if test x"${MISSING+set}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; - *) - MISSING="\${SHELL} $am_aux_dir/missing" ;; - esac -fi -# Use eval to expand $SHELL -if eval "$MISSING --run true"; then - am_missing_run="$MISSING --run " -else - am_missing_run= - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5 -$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} -fi - -if test x"${install_sh}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; - *) - install_sh="\${SHELL} $am_aux_dir/install-sh" - esac -fi - -# Installed binaries are usually stripped using `strip' when the user -# run `make install-strip'. However `strip' might not be the right -# tool to use in cross-compilation environments, therefore Automake -# will honor the `STRIP' environment variable to overrule this program. -if test "$cross_compiling" != no; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. -set dummy ${ac_tool_prefix}strip; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_STRIP+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$STRIP"; then - ac_cv_prog_STRIP="$STRIP" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_STRIP="${ac_tool_prefix}strip" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -STRIP=$ac_cv_prog_STRIP -if test -n "$STRIP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 -$as_echo "$STRIP" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$ac_cv_prog_STRIP"; then - ac_ct_STRIP=$STRIP - # Extract the first word of "strip", so it can be a program name with args. -set dummy strip; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_STRIP+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_STRIP"; then - ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_STRIP="strip" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP -if test -n "$ac_ct_STRIP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 -$as_echo "$ac_ct_STRIP" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - if test "x$ac_ct_STRIP" = x; then - STRIP=":" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - STRIP=$ac_ct_STRIP - fi -else - STRIP="$ac_cv_prog_STRIP" -fi - -fi -INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 -$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } -if test -z "$MKDIR_P"; then - if ${ac_cv_path_mkdir+:} false; then : - $as_echo_n "(cached) " >&6 -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in mkdir gmkdir; do - for ac_exec_ext in '' $ac_executable_extensions; do - { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue - case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( - 'mkdir (GNU coreutils) '* | \ - 'mkdir (coreutils) '* | \ - 'mkdir (fileutils) '4.1*) - ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext - break 3;; - esac - done - done - done -IFS=$as_save_IFS - -fi - - test -d ./--version && rmdir ./--version - if test "${ac_cv_path_mkdir+set}" = set; then - MKDIR_P="$ac_cv_path_mkdir -p" - else - # As a last resort, use the slow shell script. Don't cache a - # value for MKDIR_P within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the value is a relative name. - MKDIR_P="$ac_install_sh -d" - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 -$as_echo "$MKDIR_P" >&6; } - -mkdir_p="$MKDIR_P" -case $mkdir_p in - [\\/$]* | ?:[\\/]*) ;; - */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; -esac - -for ac_prog in gawk mawk nawk awk -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_AWK+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$AWK"; then - ac_cv_prog_AWK="$AWK" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_AWK="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -AWK=$ac_cv_prog_AWK -if test -n "$AWK"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 -$as_echo "$AWK" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$AWK" && break -done - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 -$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } -set x ${MAKE-make} -ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` -if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat >conftest.make <<\_ACEOF -SHELL = /bin/sh -all: - @echo '@@@%%%=$(MAKE)=@@@%%%' -_ACEOF -# GNU make sometimes prints "make[1]: Entering ...", which would confuse us. -case `${MAKE-make} -f conftest.make 2>/dev/null` in - *@@@%%%=?*=@@@%%%*) - eval ac_cv_prog_make_${ac_make}_set=yes;; - *) - eval ac_cv_prog_make_${ac_make}_set=no;; -esac -rm -f conftest.make -fi -if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - SET_MAKE= -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - SET_MAKE="MAKE=${MAKE-make}" -fi - -rm -rf .tst 2>/dev/null -mkdir .tst 2>/dev/null -if test -d .tst; then - am__leading_dot=. -else - am__leading_dot=_ -fi -rmdir .tst 2>/dev/null - -if test "`cd $srcdir && pwd`" != "`pwd`"; then - # Use -I$(srcdir) only when $(srcdir) != ., so that make's output - # is not polluted with repeated "-I." - am__isrc=' -I$(srcdir)' - # test to see if srcdir already configured - if test -f $srcdir/config.status; then - as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 - fi -fi - -# test whether we have cygpath -if test -z "$CYGPATH_W"; then - if (cygpath --version) >/dev/null 2>/dev/null; then - CYGPATH_W='cygpath -w' - else - CYGPATH_W=echo - fi -fi - - -# Define the identity of the package. - PACKAGE='ccminer' - VERSION='2014.05.03' - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE "$PACKAGE" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define VERSION "$VERSION" -_ACEOF - -# Some tools Automake needs. - -ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} - - -AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} - - -AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} - - -AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} - - -MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} - -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. -# Always define AMTAR for backward compatibility. Yes, it's still used -# in the wild :-( We should find a proper way to deprecate it ... -AMTAR='$${TAR-tar}' - -am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' - - - - - -ac_config_headers="$ac_config_headers cpuminer-config.h" - - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 -$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } - # Check whether --enable-maintainer-mode was given. -if test "${enable_maintainer_mode+set}" = set; then : - enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval -else - USE_MAINTAINER_MODE=no -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 -$as_echo "$USE_MAINTAINER_MODE" >&6; } - if test $USE_MAINTAINER_MODE = yes; then - MAINTAINER_MODE_TRUE= - MAINTAINER_MODE_FALSE='#' -else - MAINTAINER_MODE_TRUE='#' - MAINTAINER_MODE_FALSE= -fi - - MAINT=$MAINTAINER_MODE_TRUE - - - -DEPDIR="${am__leading_dot}deps" - -ac_config_commands="$ac_config_commands depfiles" - - -am_make=${MAKE-make} -cat > confinc << 'END' -am__doit: - @echo this is the am__doit target -.PHONY: am__doit -END -# If we don't find an include directive, just comment out the code. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 -$as_echo_n "checking for style of include used by $am_make... " >&6; } -am__include="#" -am__quote= -_am_result=none -# First try GNU make style include. -echo "include confinc" > confmf -# Ignore all kinds of additional output from `make'. -case `$am_make -s -f confmf 2> /dev/null` in #( -*the\ am__doit\ target*) - am__include=include - am__quote= - _am_result=GNU - ;; -esac -# Now try BSD make style include. -if test "$am__include" = "#"; then - echo '.include "confinc"' > confmf - case `$am_make -s -f confmf 2> /dev/null` in #( - *the\ am__doit\ target*) - am__include=.include - am__quote="\"" - _am_result=BSD - ;; - esac -fi - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 -$as_echo "$_am_result" >&6; } -rm -f confinc confmf - -# Check whether --enable-dependency-tracking was given. -if test "${enable_dependency_tracking+set}" = set; then : - enableval=$enable_dependency_tracking; -fi - -if test "x$enable_dependency_tracking" != xno; then - am_depcomp="$ac_aux_dir/depcomp" - AMDEPBACKSLASH='\' - am__nodep='_no' -fi - if test "x$enable_dependency_tracking" != xno; then - AMDEP_TRUE= - AMDEP_FALSE='#' -else - AMDEP_TRUE='#' - AMDEP_FALSE= -fi - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CC="${ac_tool_prefix}gcc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_CC="gcc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - if test "x$ac_ct_CC" = x; then - CC="" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - CC=$ac_ct_CC - fi -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CC="${ac_tool_prefix}cc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - fi -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl.exe - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl.exe -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_CC="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$ac_ct_CC" && break -done - - if test "x$ac_ct_CC" = x; then - CC="" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - CC=$ac_ct_CC - fi -fi - -fi - - -test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "no acceptable C compiler found in \$PATH -See \`config.log' for more details" "$LINENO" 5; } - -# Provide some information about the compiler. -$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 -set X $ac_compile -ac_compiler=$2 -for ac_option in --version -v -V -qversion; do - { { ac_try="$ac_compiler $ac_option >&5" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_compiler $ac_option >&5") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - sed '10a\ -... rest of stderr output deleted ... - 10q' conftest.err >conftest.er1 - cat conftest.er1 >&5 - fi - rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } -done - -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compilers, and finding out an intuition -# of exeext. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 -$as_echo_n "checking whether the C compiler works... " >&6; } -ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` - -# The possible output files: -ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" - -ac_rmfiles= -for ac_file in $ac_files -do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; - * ) ac_rmfiles="$ac_rmfiles $ac_file";; - esac -done -rm -f $ac_rmfiles - -if { { ac_try="$ac_link_default" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link_default") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then : - # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. -# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' -# in a Makefile. We should not override ac_cv_exeext if it was cached, -# so that the user can short-circuit this test for compilers unknown to -# Autoconf. -for ac_file in $ac_files '' -do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) - ;; - [ab].out ) - # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) - if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; - then :; else - ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - fi - # We set ac_cv_exeext here because the later test for it is not - # safe: cross compilers may not add the suffix if given an `-o' - # argument, so we may need to know it at that point already. - # Even if this section looks crufty: it has the advantage of - # actually working. - break;; - * ) - break;; - esac -done -test "$ac_cv_exeext" = no && ac_cv_exeext= - -else - ac_file='' -fi -if test -z "$ac_file"; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error 77 "C compiler cannot create executables -See \`config.log' for more details" "$LINENO" 5; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 -$as_echo_n "checking for C compiler default output file name... " >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 -$as_echo "$ac_file" >&6; } -ac_exeext=$ac_cv_exeext - -rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out -ac_clean_files=$ac_clean_files_save -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 -$as_echo_n "checking for suffix of executables... " >&6; } -if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then : - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in conftest.exe conftest conftest.*; do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - break;; - * ) break;; - esac -done -else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details" "$LINENO" 5; } -fi -rm -f conftest conftest$ac_cv_exeext -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 -$as_echo "$ac_cv_exeext" >&6; } - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -FILE *f = fopen ("conftest.out", "w"); - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -ac_clean_files="$ac_clean_files conftest.out" -# Check that the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 -$as_echo_n "checking whether we are cross compiling... " >&6; } -if test "$cross_compiling" != yes; then - { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } - if { ac_try='./conftest$ac_cv_exeext' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "cannot run C compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details" "$LINENO" 5; } - fi - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 -$as_echo "$cross_compiling" >&6; } - -rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out -ac_clean_files=$ac_clean_files_save -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 -$as_echo_n "checking for suffix of object files... " >&6; } -if ${ac_cv_objext+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { { ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_compile") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then : - for ac_file in conftest.o conftest.obj conftest.*; do - test -f "$ac_file" || continue; - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "cannot compute suffix of object files: cannot compile -See \`config.log' for more details" "$LINENO" 5; } -fi -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 -$as_echo "$ac_cv_objext" >&6; } -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 -$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } -if ${ac_cv_c_compiler_gnu+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_compiler_gnu=yes -else - ac_compiler_gnu=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 -$as_echo "$ac_cv_c_compiler_gnu" >&6; } -if test $ac_compiler_gnu = yes; then - GCC=yes -else - GCC= -fi -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 -$as_echo_n "checking whether $CC accepts -g... " >&6; } -if ${ac_cv_prog_cc_g+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_save_c_werror_flag=$ac_c_werror_flag - ac_c_werror_flag=yes - ac_cv_prog_cc_g=no - CFLAGS="-g" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_prog_cc_g=yes -else - CFLAGS="" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - -else - ac_c_werror_flag=$ac_save_c_werror_flag - CFLAGS="-g" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_prog_cc_g=yes -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_c_werror_flag=$ac_save_c_werror_flag -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 -$as_echo "$ac_cv_prog_cc_g" >&6; } -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 -$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } -if ${ac_cv_prog_cc_c89+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_cv_prog_cc_c89=no -ac_save_CC=$CC -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} - -/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has - function prototypes and stuff, but not '\xHH' hex character constants. - These don't provoke an error unfortunately, instead are silently treated - as 'x'. The following induces an error, until -std is added to get - proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an - array size at least. It's necessary to write '\x00'==0 to get something - that's true only with -std. */ -int osf4_cc_array ['\x00' == 0 ? 1 : -1]; - -/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters - inside strings and character constants. */ -#define FOO(x) 'x' -int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; - -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_prog_cc_c89=$ac_arg -fi -rm -f core conftest.err conftest.$ac_objext - test "x$ac_cv_prog_cc_c89" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC - -fi -# AC_CACHE_VAL -case "x$ac_cv_prog_cc_c89" in - x) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -$as_echo "none needed" >&6; } ;; - xno) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -$as_echo "unsupported" >&6; } ;; - *) - CC="$CC $ac_cv_prog_cc_c89" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 -$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; -esac -if test "x$ac_cv_prog_cc_c89" != xno; then : - -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -depcc="$CC" am_compiler_list= - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 -$as_echo_n "checking dependency style of $depcc... " >&6; } -if ${am_cv_CC_dependencies_compiler_type+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then - # We make a subdir and do the tests there. Otherwise we can end up - # making bogus files that we don't know about and never remove. For - # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. - rm -rf conftest.dir - mkdir conftest.dir - # Copy depcomp to subdir because otherwise we won't find it if we're - # using a relative directory. - cp "$am_depcomp" conftest.dir - cd conftest.dir - # We will build objects and dependencies in a subdirectory because - # it helps to detect inapplicable dependency modes. For instance - # both Tru64's cc and ICC support -MD to output dependencies as a - # side effect of compilation, but ICC will put the dependencies in - # the current directory while Tru64 will put them in the object - # directory. - mkdir sub - - am_cv_CC_dependencies_compiler_type=none - if test "$am_compiler_list" = ""; then - am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` - fi - am__universal=false - case " $depcc " in #( - *\ -arch\ *\ -arch\ *) am__universal=true ;; - esac - - for depmode in $am_compiler_list; do - # Setup a source with many dependencies, because some compilers - # like to wrap large dependency lists on column 80 (with \), and - # we should not choose a depcomp mode which is confused by this. - # - # We need to recreate these files for each test, as the compiler may - # overwrite some of them when testing with obscure command lines. - # This happens at least with the AIX C compiler. - : > sub/conftest.c - for i in 1 2 3 4 5 6; do - echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with - # Solaris 8's {/usr,}/bin/sh. - touch sub/conftst$i.h - done - echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - - # We check with `-c' and `-o' for the sake of the "dashmstdout" - # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs - am__obj=sub/conftest.${OBJEXT-o} - am__minus_obj="-o $am__obj" - case $depmode in - gcc) - # This depmode causes a compiler race in universal mode. - test "$am__universal" = false || continue - ;; - nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested - if test "x$enable_dependency_tracking" = xyes; then - continue - else - break - fi - ;; - msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok `-c -o', but also, the minuso test has - # not run yet. These depmodes are late enough in the game, and - # so weak that their functioning should not be impacted. - am__obj=conftest.${OBJEXT-o} - am__minus_obj= - ;; - none) break ;; - esac - if depmode=$depmode \ - source=sub/conftest.c object=$am__obj \ - depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ - $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ - >/dev/null 2>conftest.err && - grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && - grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && - grep $am__obj sub/conftest.Po > /dev/null 2>&1 && - ${MAKE-make} -s -f confmf > /dev/null 2>&1; then - # icc doesn't choke on unknown options, it will just issue warnings - # or remarks (even with -Werror). So we grep stderr for any message - # that says an option was ignored or not supported. - # When given -MP, icc 7.0 and 7.1 complain thusly: - # icc: Command line warning: ignoring option '-M'; no argument required - # The diagnosis changed in icc 8.0: - # icc: Command line remark: option '-MP' not supported - if (grep 'ignoring option' conftest.err || - grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else - am_cv_CC_dependencies_compiler_type=$depmode - break - fi - fi - done - - cd .. - rm -rf conftest.dir -else - am_cv_CC_dependencies_compiler_type=none -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 -$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } -CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type - - if - test "x$enable_dependency_tracking" != xno \ - && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then - am__fastdepCC_TRUE= - am__fastdepCC_FALSE='#' -else - am__fastdepCC_TRUE='#' - am__fastdepCC_FALSE= -fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C99" >&5 -$as_echo_n "checking for $CC option to accept ISO C99... " >&6; } -if ${ac_cv_prog_cc_c99+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_cv_prog_cc_c99=no -ac_save_CC=$CC -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#include -#include -#include - -// Check varargs macros. These examples are taken from C99 6.10.3.5. -#define debug(...) fprintf (stderr, __VA_ARGS__) -#define showlist(...) puts (#__VA_ARGS__) -#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) -static void -test_varargs_macros (void) -{ - int x = 1234; - int y = 5678; - debug ("Flag"); - debug ("X = %d\n", x); - showlist (The first, second, and third items.); - report (x>y, "x is %d but y is %d", x, y); -} - -// Check long long types. -#define BIG64 18446744073709551615ull -#define BIG32 4294967295ul -#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) -#if !BIG_OK - your preprocessor is broken; -#endif -#if BIG_OK -#else - your preprocessor is broken; -#endif -static long long int bignum = -9223372036854775807LL; -static unsigned long long int ubignum = BIG64; - -struct incomplete_array -{ - int datasize; - double data[]; -}; - -struct named_init { - int number; - const wchar_t *name; - double average; -}; - -typedef const char *ccp; - -static inline int -test_restrict (ccp restrict text) -{ - // See if C++-style comments work. - // Iterate through items via the restricted pointer. - // Also check for declarations in for loops. - for (unsigned int i = 0; *(text+i) != '\0'; ++i) - continue; - return 0; -} - -// Check varargs and va_copy. -static void -test_varargs (const char *format, ...) -{ - va_list args; - va_start (args, format); - va_list args_copy; - va_copy (args_copy, args); - - const char *str; - int number; - float fnumber; - - while (*format) - { - switch (*format++) - { - case 's': // string - str = va_arg (args_copy, const char *); - break; - case 'd': // int - number = va_arg (args_copy, int); - break; - case 'f': // float - fnumber = va_arg (args_copy, double); - break; - default: - break; - } - } - va_end (args_copy); - va_end (args); -} - -int -main () -{ - - // Check bool. - _Bool success = false; - - // Check restrict. - if (test_restrict ("String literal") == 0) - success = true; - char *restrict newvar = "Another string"; - - // Check varargs. - test_varargs ("s, d' f .", "string", 65, 34.234); - test_varargs_macros (); - - // Check flexible array members. - struct incomplete_array *ia = - malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); - ia->datasize = 10; - for (int i = 0; i < ia->datasize; ++i) - ia->data[i] = i * 1.234; - - // Check named initializers. - struct named_init ni = { - .number = 34, - .name = L"Test wide string", - .average = 543.34343, - }; - - ni.number = 58; - - int dynamic_array[ni.number]; - dynamic_array[ni.number - 1] = 543; - - // work around unused variable warnings - return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x' - || dynamic_array[ni.number - 1] != 543); - - ; - return 0; -} -_ACEOF -for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99 -do - CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_prog_cc_c99=$ac_arg -fi -rm -f core conftest.err conftest.$ac_objext - test "x$ac_cv_prog_cc_c99" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC - -fi -# AC_CACHE_VAL -case "x$ac_cv_prog_cc_c99" in - x) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -$as_echo "none needed" >&6; } ;; - xno) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -$as_echo "unsupported" >&6; } ;; - *) - CC="$CC $ac_cv_prog_cc_c99" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 -$as_echo "$ac_cv_prog_cc_c99" >&6; } ;; -esac -if test "x$ac_cv_prog_cc_c99" != xno; then : - -fi - - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 -$as_echo_n "checking how to run the C preprocessor... " >&6; } -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if ${ac_cv_prog_CPP+:} false; then : - $as_echo_n "(cached) " >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue -else - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.i conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 -$as_echo "$CPP" >&6; } -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue -else - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.i conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : - -else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details" "$LINENO" 5; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 -$as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if ${ac_cv_path_GREP+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$GREP"; then - ac_path_GREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in grep ggrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue -# Check for GNU ac_path_GREP and select it if it is found. - # Check for GNU $ac_path_GREP -case `"$ac_path_GREP" --version 2>&1` in -*GNU*) - ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'GREP' >> "conftest.nl" - "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - as_fn_arith $ac_count + 1 && ac_count=$as_val - if test $ac_count -gt ${ac_path_GREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_GREP="$ac_path_GREP" - ac_path_GREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_GREP_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_GREP"; then - as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 - fi -else - ac_cv_path_GREP=$GREP -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } - GREP="$ac_cv_path_GREP" - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 -$as_echo_n "checking for egrep... " >&6; } -if ${ac_cv_path_EGREP+:} false; then : - $as_echo_n "(cached) " >&6 -else - if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 - then ac_cv_path_EGREP="$GREP -E" - else - if test -z "$EGREP"; then - ac_path_EGREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in egrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue -# Check for GNU ac_path_EGREP and select it if it is found. - # Check for GNU $ac_path_EGREP -case `"$ac_path_EGREP" --version 2>&1` in -*GNU*) - ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'EGREP' >> "conftest.nl" - "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - as_fn_arith $ac_count + 1 && ac_count=$as_val - if test $ac_count -gt ${ac_path_EGREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_EGREP="$ac_path_EGREP" - ac_path_EGREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_EGREP_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_EGREP"; then - as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 - fi -else - ac_cv_path_EGREP=$EGREP -fi - - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } - EGREP="$ac_cv_path_EGREP" - - -if test $ac_cv_c_compiler_gnu = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC needs -traditional" >&5 -$as_echo_n "checking whether $CC needs -traditional... " >&6; } -if ${ac_cv_prog_gcc_traditional+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_pattern="Autoconf.*'x'" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -Autoconf TIOCGETP -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "$ac_pattern" >/dev/null 2>&1; then : - ac_cv_prog_gcc_traditional=yes -else - ac_cv_prog_gcc_traditional=no -fi -rm -f conftest* - - - if test $ac_cv_prog_gcc_traditional = no; then - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -Autoconf TCGETA -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "$ac_pattern" >/dev/null 2>&1; then : - ac_cv_prog_gcc_traditional=yes -fi -rm -f conftest* - - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_gcc_traditional" >&5 -$as_echo "$ac_cv_prog_gcc_traditional" >&6; } - if test $ac_cv_prog_gcc_traditional = yes; then - CC="$CC -traditional" - fi -fi - -if test "x$CC" != xcc; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC and cc understand -c and -o together" >&5 -$as_echo_n "checking whether $CC and cc understand -c and -o together... " >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cc understands -c and -o together" >&5 -$as_echo_n "checking whether cc understands -c and -o together... " >&6; } -fi -set dummy $CC; ac_cc=`$as_echo "$2" | - sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'` -if eval \${ac_cv_prog_cc_${ac_cc}_c_o+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -# Make sure it works both with $CC and with simple cc. -# We do the test twice because some compilers refuse to overwrite an -# existing .o file with -o, though they will create one. -ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&5' -rm -f conftest2.* -if { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && - test -f conftest2.$ac_objext && { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; -then - eval ac_cv_prog_cc_${ac_cc}_c_o=yes - if test "x$CC" != xcc; then - # Test first that cc exists at all. - if { ac_try='cc -c conftest.$ac_ext >&5' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then - ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5' - rm -f conftest2.* - if { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && - test -f conftest2.$ac_objext && { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; - then - # cc works too. - : - else - # cc exists but doesn't like -o. - eval ac_cv_prog_cc_${ac_cc}_c_o=no - fi - fi - fi -else - eval ac_cv_prog_cc_${ac_cc}_c_o=no -fi -rm -f core conftest* - -fi -if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -$as_echo "#define NO_MINUS_C_MINUS_O 1" >>confdefs.h - -fi - -# FIXME: we rely on the cache variable name because -# there is no other way. -set dummy $CC -am_cc=`echo $2 | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'` -eval am_t=\$ac_cv_prog_cc_${am_cc}_c_o -if test "$am_t" != yes; then - # Losing compiler, so override with the script. - # FIXME: It is wrong to rewrite CC. - # But if we don't then we get into trouble of one sort or another. - # A longer-term fix would be to have automake use am__CC in this case, - # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" - CC="$am_aux_dir/compile $CC" -fi - - -# By default we simply use the C compiler to build assembly code. - -test "${CCAS+set}" = set || CCAS=$CC -test "${CCASFLAGS+set}" = set || CCASFLAGS=$CFLAGS - - - -depcc="$CCAS" am_compiler_list= - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 -$as_echo_n "checking dependency style of $depcc... " >&6; } -if ${am_cv_CCAS_dependencies_compiler_type+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then - # We make a subdir and do the tests there. Otherwise we can end up - # making bogus files that we don't know about and never remove. For - # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. - rm -rf conftest.dir - mkdir conftest.dir - # Copy depcomp to subdir because otherwise we won't find it if we're - # using a relative directory. - cp "$am_depcomp" conftest.dir - cd conftest.dir - # We will build objects and dependencies in a subdirectory because - # it helps to detect inapplicable dependency modes. For instance - # both Tru64's cc and ICC support -MD to output dependencies as a - # side effect of compilation, but ICC will put the dependencies in - # the current directory while Tru64 will put them in the object - # directory. - mkdir sub - - am_cv_CCAS_dependencies_compiler_type=none - if test "$am_compiler_list" = ""; then - am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` - fi - am__universal=false - - - for depmode in $am_compiler_list; do - # Setup a source with many dependencies, because some compilers - # like to wrap large dependency lists on column 80 (with \), and - # we should not choose a depcomp mode which is confused by this. - # - # We need to recreate these files for each test, as the compiler may - # overwrite some of them when testing with obscure command lines. - # This happens at least with the AIX C compiler. - : > sub/conftest.c - for i in 1 2 3 4 5 6; do - echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with - # Solaris 8's {/usr,}/bin/sh. - touch sub/conftst$i.h - done - echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - - # We check with `-c' and `-o' for the sake of the "dashmstdout" - # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs - am__obj=sub/conftest.${OBJEXT-o} - am__minus_obj="-o $am__obj" - case $depmode in - gcc) - # This depmode causes a compiler race in universal mode. - test "$am__universal" = false || continue - ;; - nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested - if test "x$enable_dependency_tracking" = xyes; then - continue - else - break - fi - ;; - msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok `-c -o', but also, the minuso test has - # not run yet. These depmodes are late enough in the game, and - # so weak that their functioning should not be impacted. - am__obj=conftest.${OBJEXT-o} - am__minus_obj= - ;; - none) break ;; - esac - if depmode=$depmode \ - source=sub/conftest.c object=$am__obj \ - depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ - $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ - >/dev/null 2>conftest.err && - grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && - grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && - grep $am__obj sub/conftest.Po > /dev/null 2>&1 && - ${MAKE-make} -s -f confmf > /dev/null 2>&1; then - # icc doesn't choke on unknown options, it will just issue warnings - # or remarks (even with -Werror). So we grep stderr for any message - # that says an option was ignored or not supported. - # When given -MP, icc 7.0 and 7.1 complain thusly: - # icc: Command line warning: ignoring option '-M'; no argument required - # The diagnosis changed in icc 8.0: - # icc: Command line remark: option '-MP' not supported - if (grep 'ignoring option' conftest.err || - grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else - am_cv_CCAS_dependencies_compiler_type=$depmode - break - fi - fi - done - - cd .. - rm -rf conftest.dir -else - am_cv_CCAS_dependencies_compiler_type=none -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CCAS_dependencies_compiler_type" >&5 -$as_echo "$am_cv_CCAS_dependencies_compiler_type" >&6; } -CCASDEPMODE=depmode=$am_cv_CCAS_dependencies_compiler_type - - if - test "x$enable_dependency_tracking" != xno \ - && test "$am_cv_CCAS_dependencies_compiler_type" = gcc3; then - am__fastdepCCAS_TRUE= - am__fastdepCCAS_FALSE='#' -else - am__fastdepCCAS_TRUE='#' - am__fastdepCCAS_FALSE= -fi - - -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_RANLIB+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 -$as_echo "$RANLIB" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_RANLIB="ranlib" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 -$as_echo "$ac_ct_RANLIB" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - if test "x$ac_ct_RANLIB" = x; then - RANLIB=":" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - RANLIB=$ac_ct_RANLIB - fi -else - RANLIB="$ac_cv_prog_RANLIB" -fi - -ac_ext=cpp -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -if test -z "$CXX"; then - if test -n "$CCC"; then - CXX=$CCC - else - if test -n "$ac_tool_prefix"; then - for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CXX"; then - ac_cv_prog_CXX="$CXX" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -CXX=$ac_cv_prog_CXX -if test -n "$CXX"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 -$as_echo "$CXX" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$CXX" && break - done -fi -if test -z "$CXX"; then - ac_ct_CXX=$CXX - for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_CXX"; then - ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_CXX="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_CXX=$ac_cv_prog_ac_ct_CXX -if test -n "$ac_ct_CXX"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 -$as_echo "$ac_ct_CXX" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$ac_ct_CXX" && break -done - - if test "x$ac_ct_CXX" = x; then - CXX="g++" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - CXX=$ac_ct_CXX - fi -fi - - fi -fi -# Provide some information about the compiler. -$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 -set X $ac_compile -ac_compiler=$2 -for ac_option in --version -v -V -qversion; do - { { ac_try="$ac_compiler $ac_option >&5" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_compiler $ac_option >&5") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - sed '10a\ -... rest of stderr output deleted ... - 10q' conftest.err >conftest.er1 - cat conftest.er1 >&5 - fi - rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } -done - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 -$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } -if ${ac_cv_cxx_compiler_gnu+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - ac_compiler_gnu=yes -else - ac_compiler_gnu=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -ac_cv_cxx_compiler_gnu=$ac_compiler_gnu - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 -$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } -if test $ac_compiler_gnu = yes; then - GXX=yes -else - GXX= -fi -ac_test_CXXFLAGS=${CXXFLAGS+set} -ac_save_CXXFLAGS=$CXXFLAGS -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 -$as_echo_n "checking whether $CXX accepts -g... " >&6; } -if ${ac_cv_prog_cxx_g+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_save_cxx_werror_flag=$ac_cxx_werror_flag - ac_cxx_werror_flag=yes - ac_cv_prog_cxx_g=no - CXXFLAGS="-g" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - ac_cv_prog_cxx_g=yes -else - CXXFLAGS="" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - -else - ac_cxx_werror_flag=$ac_save_cxx_werror_flag - CXXFLAGS="-g" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - ac_cv_prog_cxx_g=yes -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_cxx_werror_flag=$ac_save_cxx_werror_flag -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 -$as_echo "$ac_cv_prog_cxx_g" >&6; } -if test "$ac_test_CXXFLAGS" = set; then - CXXFLAGS=$ac_save_CXXFLAGS -elif test $ac_cv_prog_cxx_g = yes; then - if test "$GXX" = yes; then - CXXFLAGS="-g -O2" - else - CXXFLAGS="-g" - fi -else - if test "$GXX" = yes; then - CXXFLAGS="-O2" - else - CXXFLAGS= - fi -fi -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -depcc="$CXX" am_compiler_list= - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 -$as_echo_n "checking dependency style of $depcc... " >&6; } -if ${am_cv_CXX_dependencies_compiler_type+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then - # We make a subdir and do the tests there. Otherwise we can end up - # making bogus files that we don't know about and never remove. For - # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. - rm -rf conftest.dir - mkdir conftest.dir - # Copy depcomp to subdir because otherwise we won't find it if we're - # using a relative directory. - cp "$am_depcomp" conftest.dir - cd conftest.dir - # We will build objects and dependencies in a subdirectory because - # it helps to detect inapplicable dependency modes. For instance - # both Tru64's cc and ICC support -MD to output dependencies as a - # side effect of compilation, but ICC will put the dependencies in - # the current directory while Tru64 will put them in the object - # directory. - mkdir sub - - am_cv_CXX_dependencies_compiler_type=none - if test "$am_compiler_list" = ""; then - am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` - fi - am__universal=false - case " $depcc " in #( - *\ -arch\ *\ -arch\ *) am__universal=true ;; - esac - - for depmode in $am_compiler_list; do - # Setup a source with many dependencies, because some compilers - # like to wrap large dependency lists on column 80 (with \), and - # we should not choose a depcomp mode which is confused by this. - # - # We need to recreate these files for each test, as the compiler may - # overwrite some of them when testing with obscure command lines. - # This happens at least with the AIX C compiler. - : > sub/conftest.c - for i in 1 2 3 4 5 6; do - echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with - # Solaris 8's {/usr,}/bin/sh. - touch sub/conftst$i.h - done - echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - - # We check with `-c' and `-o' for the sake of the "dashmstdout" - # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs - am__obj=sub/conftest.${OBJEXT-o} - am__minus_obj="-o $am__obj" - case $depmode in - gcc) - # This depmode causes a compiler race in universal mode. - test "$am__universal" = false || continue - ;; - nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested - if test "x$enable_dependency_tracking" = xyes; then - continue - else - break - fi - ;; - msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok `-c -o', but also, the minuso test has - # not run yet. These depmodes are late enough in the game, and - # so weak that their functioning should not be impacted. - am__obj=conftest.${OBJEXT-o} - am__minus_obj= - ;; - none) break ;; - esac - if depmode=$depmode \ - source=sub/conftest.c object=$am__obj \ - depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ - $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ - >/dev/null 2>conftest.err && - grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && - grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && - grep $am__obj sub/conftest.Po > /dev/null 2>&1 && - ${MAKE-make} -s -f confmf > /dev/null 2>&1; then - # icc doesn't choke on unknown options, it will just issue warnings - # or remarks (even with -Werror). So we grep stderr for any message - # that says an option was ignored or not supported. - # When given -MP, icc 7.0 and 7.1 complain thusly: - # icc: Command line warning: ignoring option '-M'; no argument required - # The diagnosis changed in icc 8.0: - # icc: Command line remark: option '-MP' not supported - if (grep 'ignoring option' conftest.err || - grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else - am_cv_CXX_dependencies_compiler_type=$depmode - break - fi - fi - done - - cd .. - rm -rf conftest.dir -else - am_cv_CXX_dependencies_compiler_type=none -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5 -$as_echo "$am_cv_CXX_dependencies_compiler_type" >&6; } -CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type - - if - test "x$enable_dependency_tracking" != xno \ - && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then - am__fastdepCXX_TRUE= - am__fastdepCXX_FALSE='#' -else - am__fastdepCXX_TRUE='#' - am__fastdepCXX_FALSE= -fi - - - - OPENMP_CFLAGS= - # Check whether --enable-openmp was given. -if test "${enable_openmp+set}" = set; then : - enableval=$enable_openmp; -fi - - if test "$enable_openmp" != no; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to support OpenMP" >&5 -$as_echo_n "checking for $CC option to support OpenMP... " >&6; } -if ${ac_cv_prog_c_openmp+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#ifndef _OPENMP - choke me -#endif -#include -int main () { return omp_get_num_threads (); } - -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_prog_c_openmp='none needed' -else - ac_cv_prog_c_openmp='unsupported' - for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do - ac_save_CFLAGS=$CFLAGS - CFLAGS="$CFLAGS $ac_option" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#ifndef _OPENMP - choke me -#endif -#include -int main () { return omp_get_num_threads (); } - -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_prog_c_openmp=$ac_option -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext - CFLAGS=$ac_save_CFLAGS - if test "$ac_cv_prog_c_openmp" != unsupported; then - break - fi - done -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_c_openmp" >&5 -$as_echo "$ac_cv_prog_c_openmp" >&6; } - case $ac_cv_prog_c_openmp in #( - "none needed" | unsupported) - ;; #( - *) - OPENMP_CFLAGS=$ac_cv_prog_c_openmp ;; - esac - fi - - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 -$as_echo_n "checking for ANSI C header files... " >&6; } -if ${ac_cv_header_stdc+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_header_stdc=yes -else - ac_cv_header_stdc=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then : - : -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - return 2; - return 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - -else - ac_cv_header_stdc=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 -$as_echo "$ac_cv_header_stdc" >&6; } -if test $ac_cv_header_stdc = yes; then - -$as_echo "#define STDC_HEADERS 1" >>confdefs.h - -fi - -# On IRIX 5.3, sys/types and inttypes.h are conflicting. -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default -" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in sys/endian.h sys/param.h syslog.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - -# sys/sysctl.h requires sys/types.h on FreeBSD -# sys/sysctl.h requires sys/param.h on OpenBSD -for ac_header in sys/sysctl.h -do : - ac_fn_c_check_header_compile "$LINENO" "sys/sysctl.h" "ac_cv_header_sys_sysctl_h" "#include -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -" -if test "x$ac_cv_header_sys_sysctl_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SYS_SYSCTL_H 1 -_ACEOF - -fi - -done - - -ac_fn_c_check_decl "$LINENO" "be32dec" "ac_cv_have_decl_be32dec" "$ac_includes_default -#ifdef HAVE_SYS_ENDIAN_H -#include -#endif - -" -if test "x$ac_cv_have_decl_be32dec" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_BE32DEC $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "le32dec" "ac_cv_have_decl_le32dec" "$ac_includes_default -#ifdef HAVE_SYS_ENDIAN_H -#include -#endif - -" -if test "x$ac_cv_have_decl_le32dec" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_LE32DEC $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "be32enc" "ac_cv_have_decl_be32enc" "$ac_includes_default -#ifdef HAVE_SYS_ENDIAN_H -#include -#endif - -" -if test "x$ac_cv_have_decl_be32enc" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_BE32ENC $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "le32enc" "ac_cv_have_decl_le32enc" "$ac_includes_default -#ifdef HAVE_SYS_ENDIAN_H -#include -#endif - -" -if test "x$ac_cv_have_decl_le32enc" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_LE32ENC $ac_have_decl -_ACEOF - - -ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" -if test "x$ac_cv_type_size_t" = xyes; then : - -else - -cat >>confdefs.h <<_ACEOF -#define size_t unsigned int -_ACEOF - -fi - -# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works -# for constant arguments. Useless! -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5 -$as_echo_n "checking for working alloca.h... " >&6; } -if ${ac_cv_working_alloca_h+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -char *p = (char *) alloca (2 * sizeof (int)); - if (p) return 0; - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_working_alloca_h=yes -else - ac_cv_working_alloca_h=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5 -$as_echo "$ac_cv_working_alloca_h" >&6; } -if test $ac_cv_working_alloca_h = yes; then - -$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h - -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5 -$as_echo_n "checking for alloca... " >&6; } -if ${ac_cv_func_alloca_works+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __GNUC__ -# define alloca __builtin_alloca -#else -# ifdef _MSC_VER -# include -# define alloca _alloca -# else -# ifdef HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -void *alloca (size_t); -# endif -# endif -# endif -# endif -#endif - -int -main () -{ -char *p = (char *) alloca (1); - if (p) return 0; - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_func_alloca_works=yes -else - ac_cv_func_alloca_works=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5 -$as_echo "$ac_cv_func_alloca_works" >&6; } - -if test $ac_cv_func_alloca_works = yes; then - -$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h - -else - # The SVR3 libPW and SVR4 libucb both contain incompatible functions -# that cause trouble. Some versions do not even contain alloca or -# contain a buggy version. If you still want to use their alloca, -# use ar to extract alloca.o from them instead of compiling alloca.c. - -ALLOCA=\${LIBOBJDIR}alloca.$ac_objext - -$as_echo "#define C_ALLOCA 1" >>confdefs.h - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5 -$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; } -if ${ac_cv_os_cray+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#if defined CRAY && ! defined CRAY2 -webecray -#else -wenotbecray -#endif - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "webecray" >/dev/null 2>&1; then : - ac_cv_os_cray=yes -else - ac_cv_os_cray=no -fi -rm -f conftest* - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5 -$as_echo "$ac_cv_os_cray" >&6; } -if test $ac_cv_os_cray = yes; then - for ac_func in _getb67 GETB67 getb67; do - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" -if eval test \"x\$"$as_ac_var"\" = x"yes"; then : - -cat >>confdefs.h <<_ACEOF -#define CRAY_STACKSEG_END $ac_func -_ACEOF - - break -fi - - done -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5 -$as_echo_n "checking stack direction for C alloca... " >&6; } -if ${ac_cv_c_stack_direction+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : - ac_cv_c_stack_direction=0 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$ac_includes_default -int -find_stack_direction () -{ - static char *addr = 0; - auto char dummy; - if (addr == 0) - { - addr = &dummy; - return find_stack_direction (); - } - else - return (&dummy > addr) ? 1 : -1; -} - -int -main () -{ - return find_stack_direction () < 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - ac_cv_c_stack_direction=1 -else - ac_cv_c_stack_direction=-1 -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5 -$as_echo "$ac_cv_c_stack_direction" >&6; } -cat >>confdefs.h <<_ACEOF -#define STACK_DIRECTION $ac_cv_c_stack_direction -_ACEOF - - -fi - -for ac_func in getopt_long -do : - ac_fn_c_check_func "$LINENO" "getopt_long" "ac_cv_func_getopt_long" -if test "x$ac_cv_func_getopt_long" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_GETOPT_LONG 1 -_ACEOF - -fi -done - - -case $target in - i*86-*-*) - have_x86=true - ;; - x86_64-*-*) - have_x86=true - have_x86_64=true - ;; - amd64-*-*) - have_x86=true - have_x86_64=true - ;; -esac - -PTHREAD_FLAGS="-pthread" -WS2_LIBS="" - -case $target in - *-*-mingw*) - have_win32=true - PTHREAD_FLAGS="" - WS2_LIBS="-lws2_32" - ;; -esac - -if test x$have_x86 = xtrue -then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can compile AVX code" >&5 -$as_echo_n "checking whether we can compile AVX code... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -asm ("vmovdqa %ymm0, %ymm1"); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - -$as_echo "#define USE_AVX 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can compile XOP code" >&5 -$as_echo_n "checking whether we can compile XOP code... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -asm ("vprotd \$7, %xmm0, %xmm1"); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - -$as_echo "#define USE_XOP 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: The assembler does not support the XOP instruction set." >&5 -$as_echo "$as_me: WARNING: The assembler does not support the XOP instruction set." >&2;} - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can compile AVX2 code" >&5 -$as_echo_n "checking whether we can compile AVX2 code... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -asm ("vpaddd %ymm0, %ymm1, %ymm2"); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - -$as_echo "#define USE_AVX2 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: The assembler does not support the AVX2 instruction set." >&5 -$as_echo "$as_me: WARNING: The assembler does not support the AVX2 instruction set." >&2;} - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: The assembler does not support the AVX instruction set." >&5 -$as_echo "$as_me: WARNING: The assembler does not support the AVX instruction set." >&2;} - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for json_loads in -ljansson" >&5 -$as_echo_n "checking for json_loads in -ljansson... " >&6; } -if ${ac_cv_lib_jansson_json_loads+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-ljansson $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char json_loads (); -int -main () -{ -return json_loads (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_jansson_json_loads=yes -else - ac_cv_lib_jansson_json_loads=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jansson_json_loads" >&5 -$as_echo "$ac_cv_lib_jansson_json_loads" >&6; } -if test "x$ac_cv_lib_jansson_json_loads" = xyes; then : - request_jansson=false -else - request_jansson=true -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 -$as_echo_n "checking for pthread_create in -lpthread... " >&6; } -if ${ac_cv_lib_pthread_pthread_create+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lpthread $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char pthread_create (); -int -main () -{ -return pthread_create (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_pthread_pthread_create=yes -else - ac_cv_lib_pthread_pthread_create=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 -$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; } -if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then : - PTHREAD_LIBS="-lpthread" -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthreadGC2" >&5 -$as_echo_n "checking for pthread_create in -lpthreadGC2... " >&6; } -if ${ac_cv_lib_pthreadGC2_pthread_create+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lpthreadGC2 $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char pthread_create (); -int -main () -{ -return pthread_create (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_pthreadGC2_pthread_create=yes -else - ac_cv_lib_pthreadGC2_pthread_create=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreadGC2_pthread_create" >&5 -$as_echo "$ac_cv_lib_pthreadGC2_pthread_create" >&6; } -if test "x$ac_cv_lib_pthreadGC2_pthread_create" = xyes; then : - PTHREAD_LIBS="-lpthreadGC2" -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthreadGC1" >&5 -$as_echo_n "checking for pthread_create in -lpthreadGC1... " >&6; } -if ${ac_cv_lib_pthreadGC1_pthread_create+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lpthreadGC1 $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char pthread_create (); -int -main () -{ -return pthread_create (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_pthreadGC1_pthread_create=yes -else - ac_cv_lib_pthreadGC1_pthread_create=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreadGC1_pthread_create" >&5 -$as_echo "$ac_cv_lib_pthreadGC1_pthread_create" >&6; } -if test "x$ac_cv_lib_pthreadGC1_pthread_create" = xyes; then : - PTHREAD_LIBS="-lpthreadGC1" -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthreadGC" >&5 -$as_echo_n "checking for pthread_create in -lpthreadGC... " >&6; } -if ${ac_cv_lib_pthreadGC_pthread_create+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lpthreadGC $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char pthread_create (); -int -main () -{ -return pthread_create (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_pthreadGC_pthread_create=yes -else - ac_cv_lib_pthreadGC_pthread_create=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreadGC_pthread_create" >&5 -$as_echo "$ac_cv_lib_pthreadGC_pthread_create" >&6; } -if test "x$ac_cv_lib_pthreadGC_pthread_create" = xyes; then : - PTHREAD_LIBS="-lpthreadGC" - -fi - -fi - -fi - -fi - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_library_init in -lssl" >&5 -$as_echo_n "checking for SSL_library_init in -lssl... " >&6; } -if ${ac_cv_lib_ssl_SSL_library_init+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lssl $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char SSL_library_init (); -int -main () -{ -return SSL_library_init (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_ssl_SSL_library_init=yes -else - ac_cv_lib_ssl_SSL_library_init=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ssl_SSL_library_init" >&5 -$as_echo "$ac_cv_lib_ssl_SSL_library_init" >&6; } -if test "x$ac_cv_lib_ssl_SSL_library_init" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBSSL 1 -_ACEOF - - LIBS="-lssl $LIBS" - -else - as_fn_error $? "OpenSSL library required" "$LINENO" 5 -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for EVP_DigestFinal_ex in -lcrypto" >&5 -$as_echo_n "checking for EVP_DigestFinal_ex in -lcrypto... " >&6; } -if ${ac_cv_lib_crypto_EVP_DigestFinal_ex+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lcrypto $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char EVP_DigestFinal_ex (); -int -main () -{ -return EVP_DigestFinal_ex (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_crypto_EVP_DigestFinal_ex=yes -else - ac_cv_lib_crypto_EVP_DigestFinal_ex=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_EVP_DigestFinal_ex" >&5 -$as_echo "$ac_cv_lib_crypto_EVP_DigestFinal_ex" >&6; } -if test "x$ac_cv_lib_crypto_EVP_DigestFinal_ex" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBCRYPTO 1 -_ACEOF - - LIBS="-lcrypto $LIBS" - -else - as_fn_error $? "OpenSSL library required" "$LINENO" 5 -fi - - - if test x$request_jansson = xtrue; then - WANT_JANSSON_TRUE= - WANT_JANSSON_FALSE='#' -else - WANT_JANSSON_TRUE='#' - WANT_JANSSON_FALSE= -fi - - if test x$have_win32 = xtrue; then - HAVE_WINDOWS_TRUE= - HAVE_WINDOWS_FALSE='#' -else - HAVE_WINDOWS_TRUE='#' - HAVE_WINDOWS_FALSE= -fi - - if test x$have_x86 = xtrue; then - ARCH_x86_TRUE= - ARCH_x86_FALSE='#' -else - ARCH_x86_TRUE='#' - ARCH_x86_FALSE= -fi - - if test x$have_x86_64 = xtrue; then - ARCH_x86_64_TRUE= - ARCH_x86_64_FALSE='#' -else - ARCH_x86_64_TRUE='#' - ARCH_x86_64_FALSE= -fi - - -if test x$request_jansson = xtrue -then - JANSSON_LIBS="compat/jansson/libjansson.a" -else - JANSSON_LIBS=-ljansson -fi - - - - - - - - - - - - - - - - - - - - - - - - - - -# Check whether --with-libcurl was given. -if test "${with_libcurl+set}" = set; then : - withval=$with_libcurl; _libcurl_with=$withval -else - _libcurl_with=yes -fi - - - if test "$_libcurl_with" != "no" ; then - - for ac_prog in gawk mawk nawk awk -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_AWK+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$AWK"; then - ac_cv_prog_AWK="$AWK" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_AWK="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -AWK=$ac_cv_prog_AWK -if test -n "$AWK"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 -$as_echo "$AWK" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$AWK" && break -done - - - _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[1]+256*A[2]+A[3]; print X;}'" - - _libcurl_try_link=yes - - if test -d "$_libcurl_with" ; then - LIBCURL_CPPFLAGS="-I$withval/include" - _libcurl_ldflags="-L$withval/lib" - # Extract the first word of "curl-config", so it can be a program name with args. -set dummy curl-config; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path__libcurl_config+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $_libcurl_config in - [\\/]* | ?:[\\/]*) - ac_cv_path__libcurl_config="$_libcurl_config" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in "$withval/bin" -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_path__libcurl_config="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -_libcurl_config=$ac_cv_path__libcurl_config -if test -n "$_libcurl_config"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_libcurl_config" >&5 -$as_echo "$_libcurl_config" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - else - # Extract the first word of "curl-config", so it can be a program name with args. -set dummy curl-config; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path__libcurl_config+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $_libcurl_config in - [\\/]* | ?:[\\/]*) - ac_cv_path__libcurl_config="$_libcurl_config" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_path__libcurl_config="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -_libcurl_config=$ac_cv_path__libcurl_config -if test -n "$_libcurl_config"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_libcurl_config" >&5 -$as_echo "$_libcurl_config" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - fi - - if test x$_libcurl_config != "x" ; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the version of libcurl" >&5 -$as_echo_n "checking for the version of libcurl... " >&6; } -if ${libcurl_cv_lib_curl_version+:} false; then : - $as_echo_n "(cached) " >&6 -else - libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $2}'` -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libcurl_cv_lib_curl_version" >&5 -$as_echo "$libcurl_cv_lib_curl_version" >&6; } - - _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse` - _libcurl_wanted=`echo 7.15.2 | $_libcurl_version_parse` - - if test $_libcurl_wanted -gt 0 ; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libcurl >= version 7.15.2" >&5 -$as_echo_n "checking for libcurl >= version 7.15.2... " >&6; } -if ${libcurl_cv_lib_version_ok+:} false; then : - $as_echo_n "(cached) " >&6 -else - - if test $_libcurl_version -ge $_libcurl_wanted ; then - libcurl_cv_lib_version_ok=yes - else - libcurl_cv_lib_version_ok=no - fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libcurl_cv_lib_version_ok" >&5 -$as_echo "$libcurl_cv_lib_version_ok" >&6; } - fi - - if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then - if test x"$LIBCURL_CPPFLAGS" = "x" ; then - LIBCURL_CPPFLAGS=`$_libcurl_config --cflags` - fi - if test x"$LIBCURL" = "x" ; then - LIBCURL=`$_libcurl_config --libs` - - # This is so silly, but Apple actually has a bug in their - # curl-config script. Fixed in Tiger, but there are still - # lots of Panther installs around. - case "${host}" in - powerpc-apple-darwin7*) - LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'` - ;; - esac - fi - - # All curl-config scripts support --feature - _libcurl_features=`$_libcurl_config --feature` - - # Is it modern enough to have --protocols? (7.12.4) - if test $_libcurl_version -ge 461828 ; then - _libcurl_protocols=`$_libcurl_config --protocols` - fi - else - _libcurl_try_link=no - fi - - unset _libcurl_wanted - fi - - if test $_libcurl_try_link = yes ; then - - # we didn't find curl-config, so let's see if the user-supplied - # link line (or failing that, "-lcurl") is enough. - LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"} - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether libcurl is usable" >&5 -$as_echo_n "checking whether libcurl is usable... " >&6; } -if ${libcurl_cv_lib_curl_usable+:} false; then : - $as_echo_n "(cached) " >&6 -else - - _libcurl_save_cppflags=$CPPFLAGS - CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS" - _libcurl_save_libs=$LIBS - LIBS="$LIBCURL $LIBS" - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ - -/* Try and use a few common options to force a failure if we are - missing symbols or can't link. */ -int x; -curl_easy_setopt(NULL,CURLOPT_URL,NULL); -x=CURL_ERROR_SIZE; -x=CURLOPT_WRITEFUNCTION; -x=CURLOPT_FILE; -x=CURLOPT_ERRORBUFFER; -x=CURLOPT_STDERR; -x=CURLOPT_VERBOSE; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - libcurl_cv_lib_curl_usable=yes -else - libcurl_cv_lib_curl_usable=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext - - CPPFLAGS=$_libcurl_save_cppflags - LIBS=$_libcurl_save_libs - unset _libcurl_save_cppflags - unset _libcurl_save_libs - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libcurl_cv_lib_curl_usable" >&5 -$as_echo "$libcurl_cv_lib_curl_usable" >&6; } - - if test $libcurl_cv_lib_curl_usable = yes ; then - - # Does curl_free() exist in this version of libcurl? - # If not, fake it with free() - - _libcurl_save_cppflags=$CPPFLAGS - CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS" - _libcurl_save_libs=$LIBS - LIBS="$LIBS $LIBCURL" - - ac_fn_c_check_func "$LINENO" "curl_free" "ac_cv_func_curl_free" -if test "x$ac_cv_func_curl_free" = xyes; then : - -else - -$as_echo "#define curl_free free" >>confdefs.h - -fi - - - CPPFLAGS=$_libcurl_save_cppflags - LIBS=$_libcurl_save_libs - unset _libcurl_save_cppflags - unset _libcurl_save_libs - - -$as_echo "#define HAVE_LIBCURL 1" >>confdefs.h - - - - - for _libcurl_feature in $_libcurl_features ; do - cat >>confdefs.h <<_ACEOF -#define `$as_echo "libcurl_feature_$_libcurl_feature" | $as_tr_cpp` 1 -_ACEOF - - eval `$as_echo "libcurl_feature_$_libcurl_feature" | $as_tr_sh`=yes - done - - if test "x$_libcurl_protocols" = "x" ; then - - # We don't have --protocols, so just assume that all - # protocols are available - _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP" - - if test x$libcurl_feature_SSL = xyes ; then - _libcurl_protocols="$_libcurl_protocols HTTPS" - - # FTPS wasn't standards-compliant until version - # 7.11.0 (0x070b00 == 461568) - if test $_libcurl_version -ge 461568; then - _libcurl_protocols="$_libcurl_protocols FTPS" - fi - fi - - # RTSP, IMAP, POP3 and SMTP were added in - # 7.20.0 (0x071400 == 463872) - if test $_libcurl_version -ge 463872; then - _libcurl_protocols="$_libcurl_protocols RTSP IMAP POP3 SMTP" - fi - fi - - for _libcurl_protocol in $_libcurl_protocols ; do - cat >>confdefs.h <<_ACEOF -#define `$as_echo "libcurl_protocol_$_libcurl_protocol" | $as_tr_cpp` 1 -_ACEOF - - eval `$as_echo "libcurl_protocol_$_libcurl_protocol" | $as_tr_sh`=yes - done - else - unset LIBCURL - unset LIBCURL_CPPFLAGS - fi - fi - - unset _libcurl_try_link - unset _libcurl_version_parse - unset _libcurl_config - unset _libcurl_feature - unset _libcurl_features - unset _libcurl_protocol - unset _libcurl_protocols - unset _libcurl_version - unset _libcurl_ldflags - fi - - if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then - # This is the IF-NO path - as_fn_error $? "Missing required libcurl >= 7.15.2" "$LINENO" 5 - else - # This is the IF-YES path - : - fi - - unset _libcurl_with - - - - - - - -ac_config_files="$ac_config_files Makefile compat/Makefile compat/jansson/Makefile" - - -ARCH=`uname -m` -if [ $ARCH == "x86_64" ]; -then - SUFFIX="64" -else - SUFFIX="" -fi - - -# Check whether --with-cuda was given. -if test "${with_cuda+set}" = set; then : - withval=$with_cuda; -fi - - -if test -n "$with_cuda" -then - CUDA_CFLAGS="-I$with_cuda/include" - CUDA_LIBS="-lcudart" - CUDA_LDFLAGS="-L$with_cuda/lib$SUFFIX" - NVCC="$with_cuda/bin/nvcc" -else - CUDA_CFLAGS="-I/usr/local/cuda/include" - CUDA_LIBS="-lcudart -static-libstdc++" - CUDA_LDFLAGS="-L/usr/local/cuda/lib$SUFFIX" - NVCC="nvcc" -fi - - - - - - - -cat >confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overridden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, we kill variables containing newlines. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -( - for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do - eval ac_val=\$$ac_var - case $ac_val in #( - *${as_nl}*) - case $ac_var in #( - *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 -$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; - esac - case $ac_var in #( - _ | IFS | as_nl) ;; #( - BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( - *) { eval $ac_var=; unset $ac_var;} ;; - esac ;; - esac - done - - (set) 2>&1 | - case $as_nl`(ac_space=' '; set) 2>&1` in #( - *${as_nl}ac_space=\ *) - # `set' does not quote correctly, so add quotes: double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \. - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; #( - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" - ;; - esac | - sort -) | - sed ' - /^ac_cv_env_/b end - t clear - :clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - :end' >>confcache -if diff "$cache_file" confcache >/dev/null 2>&1; then :; else - if test -w "$cache_file"; then - if test "x$cache_file" != "x/dev/null"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 -$as_echo "$as_me: updating cache $cache_file" >&6;} - if test ! -f "$cache_file" || test -h "$cache_file"; then - cat confcache >"$cache_file" - else - case $cache_file in #( - */* | ?:*) - mv -f confcache "$cache_file"$$ && - mv -f "$cache_file"$$ "$cache_file" ;; #( - *) - mv -f confcache "$cache_file" ;; - esac - fi - fi - else - { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 -$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -DEFS=-DHAVE_CONFIG_H - -ac_libobjs= -ac_ltlibobjs= -U= -for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue - # 1. Remove the extension, and $U if already installed. - ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' - ac_i=`$as_echo "$ac_i" | sed "$ac_script"` - # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR - # will be set to the directory where LIBOBJS objects are built. - as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" - as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' -done -LIBOBJS=$ac_libobjs - -LTLIBOBJS=$ac_ltlibobjs - - - if test -n "$EXEEXT"; then - am__EXEEXT_TRUE= - am__EXEEXT_FALSE='#' -else - am__EXEEXT_TRUE='#' - am__EXEEXT_FALSE= -fi - -if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then - as_fn_error $? "conditional \"AMDEP\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCC\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${WANT_JANSSON_TRUE}" && test -z "${WANT_JANSSON_FALSE}"; then - as_fn_error $? "conditional \"WANT_JANSSON\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${HAVE_WINDOWS_TRUE}" && test -z "${HAVE_WINDOWS_FALSE}"; then - as_fn_error $? "conditional \"HAVE_WINDOWS\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${ARCH_x86_TRUE}" && test -z "${ARCH_x86_FALSE}"; then - as_fn_error $? "conditional \"ARCH_x86\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${ARCH_x86_64_TRUE}" && test -z "${ARCH_x86_64_FALSE}"; then - as_fn_error $? "conditional \"ARCH_x86_64\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi - -: "${CONFIG_STATUS=./config.status}" -ac_write_fail=0 -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 -$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} -as_write_fail=0 -cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 -#! $SHELL -# Generated by $as_me. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -ac_cs_recheck=false -ac_cs_silent=false - -SHELL=\${CONFIG_SHELL-$SHELL} -export SHELL -_ASEOF -cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 -## -------------------- ## -## M4sh Initialization. ## -## -------------------- ## - -# Be more Bourne compatible -DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in #( - *posix*) : - set -o posix ;; #( - *) : - ;; -esac -fi - - -as_nl=' -' -export as_nl -# Printing a long string crashes Solaris 7 /usr/bin/printf. -as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -# Prefer a ksh shell builtin over an external printf program on Solaris, -# but without wasting forks for bash or zsh. -if test -z "$BASH_VERSION$ZSH_VERSION" \ - && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='print -r --' - as_echo_n='print -rn --' -elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='printf %s\n' - as_echo_n='printf %s' -else - if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then - as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' - as_echo_n='/usr/ucb/echo -n' - else - as_echo_body='eval expr "X$1" : "X\\(.*\\)"' - as_echo_n_body='eval - arg=$1; - case $arg in #( - *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; - esac; - expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" - ' - export as_echo_n_body - as_echo_n='sh -c $as_echo_n_body as_echo' - fi - export as_echo_body - as_echo='sh -c $as_echo_body as_echo' -fi - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - PATH_SEPARATOR=: - (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { - (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || - PATH_SEPARATOR=';' - } -fi - - -# IFS -# We need space, tab and new line, in precisely that order. Quoting is -# there to prevent editors from complaining about space-tab. -# (If _AS_PATH_WALK were called with IFS unset, it would disable word -# splitting by setting IFS to empty value.) -IFS=" "" $as_nl" - -# Find who we are. Look in the path if we contain no directory separator. -as_myself= -case $0 in #(( - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break - done -IFS=$as_save_IFS - - ;; -esac -# We did not find ourselves, most probably we were run as `sh COMMAND' -# in which case we are not to be found in the path. -if test "x$as_myself" = x; then - as_myself=$0 -fi -if test ! -f "$as_myself"; then - $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 - exit 1 -fi - -# Unset variables that we do not need and which cause bugs (e.g. in -# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" -# suppresses any "Segmentation fault" message there. '((' could -# trigger a bug in pdksh 5.2.14. -for as_var in BASH_ENV ENV MAIL MAILPATH -do eval test x\${$as_var+set} = xset \ - && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : -done -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# CDPATH. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - - -# as_fn_error STATUS ERROR [LINENO LOG_FD] -# ---------------------------------------- -# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are -# provided, also output the error to LOG_FD, referencing LINENO. Then exit the -# script with STATUS, using 1 if that was 0. -as_fn_error () -{ - as_status=$1; test $as_status -eq 0 && as_status=1 - if test "$4"; then - as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 - fi - $as_echo "$as_me: error: $2" >&2 - as_fn_exit $as_status -} # as_fn_error - - -# as_fn_set_status STATUS -# ----------------------- -# Set $? to STATUS, without forking. -as_fn_set_status () -{ - return $1 -} # as_fn_set_status - -# as_fn_exit STATUS -# ----------------- -# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. -as_fn_exit () -{ - set +e - as_fn_set_status $1 - exit $1 -} # as_fn_exit - -# as_fn_unset VAR -# --------------- -# Portably unset VAR. -as_fn_unset () -{ - { eval $1=; unset $1;} -} -as_unset=as_fn_unset -# as_fn_append VAR VALUE -# ---------------------- -# Append the text in VALUE to the end of the definition contained in VAR. Take -# advantage of any shell optimizations that allow amortized linear growth over -# repeated appends, instead of the typical quadratic growth present in naive -# implementations. -if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : - eval 'as_fn_append () - { - eval $1+=\$2 - }' -else - as_fn_append () - { - eval $1=\$$1\$2 - } -fi # as_fn_append - -# as_fn_arith ARG... -# ------------------ -# Perform arithmetic evaluation on the ARGs, and store the result in the -# global $as_val. Take advantage of shells that can avoid forks. The arguments -# must be portable across $(()) and expr. -if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : - eval 'as_fn_arith () - { - as_val=$(( $* )) - }' -else - as_fn_arith () - { - as_val=`expr "$@" || test $? -eq 1` - } -fi # as_fn_arith - - -if expr a : '\(a\)' >/dev/null 2>&1 && - test "X`expr 00001 : '.*\(...\)'`" = X001; then - as_expr=expr -else - as_expr=false -fi - -if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - -if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then - as_dirname=dirname -else - as_dirname=false -fi - -as_me=`$as_basename -- "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ - s//\1/ - q - } - /^X\/\(\/\/\)$/{ - s//\1/ - q - } - /^X\/\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -ECHO_C= ECHO_N= ECHO_T= -case `echo -n x` in #((((( --n*) - case `echo 'xy\c'` in - *c*) ECHO_T=' ';; # ECHO_T is single tab character. - xy) ECHO_C='\c';; - *) echo `echo ksh88 bug on AIX 6.1` > /dev/null - ECHO_T=' ';; - esac;; -*) - ECHO_N='-n';; -esac - -rm -f conf$$ conf$$.exe conf$$.file -if test -d conf$$.dir; then - rm -f conf$$.dir/conf$$.file -else - rm -f conf$$.dir - mkdir conf$$.dir 2>/dev/null -fi -if (echo >conf$$.file) 2>/dev/null; then - if ln -s conf$$.file conf$$ 2>/dev/null; then - as_ln_s='ln -s' - # ... but there are two gotchas: - # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. - # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. - ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' - elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln - else - as_ln_s='cp -p' - fi -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file -rmdir conf$$.dir 2>/dev/null - - -# as_fn_mkdir_p -# ------------- -# Create "$as_dir" as a directory, including parents if necessary. -as_fn_mkdir_p () -{ - - case $as_dir in #( - -*) as_dir=./$as_dir;; - esac - test -d "$as_dir" || eval $as_mkdir_p || { - as_dirs= - while :; do - case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( - *) as_qdir=$as_dir;; - esac - as_dirs="'$as_qdir' $as_dirs" - as_dir=`$as_dirname -- "$as_dir" || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - test -d "$as_dir" && break - done - test -z "$as_dirs" || eval "mkdir $as_dirs" - } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" - - -} # as_fn_mkdir_p -if mkdir -p . 2>/dev/null; then - as_mkdir_p='mkdir -p "$as_dir"' -else - test -d ./-p && rmdir ./-p - as_mkdir_p=false -fi - -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" - - -exec 6>&1 -## ----------------------------------- ## -## Main body of $CONFIG_STATUS script. ## -## ----------------------------------- ## -_ASEOF -test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -# Save the log message, to keep $0 and so on meaningful, and to -# report actual input values of CONFIG_FILES etc. instead of their -# values after options handling. -ac_log=" -This file was extended by ccminer $as_me 2014.05.03, which was -generated by GNU Autoconf 2.68. Invocation command line was - - CONFIG_FILES = $CONFIG_FILES - CONFIG_HEADERS = $CONFIG_HEADERS - CONFIG_LINKS = $CONFIG_LINKS - CONFIG_COMMANDS = $CONFIG_COMMANDS - $ $0 $@ - -on `(hostname || uname -n) 2>/dev/null | sed 1q` -" - -_ACEOF - -case $ac_config_files in *" -"*) set x $ac_config_files; shift; ac_config_files=$*;; -esac - -case $ac_config_headers in *" -"*) set x $ac_config_headers; shift; ac_config_headers=$*;; -esac - - -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -# Files that config.status was made for. -config_files="$ac_config_files" -config_headers="$ac_config_headers" -config_commands="$ac_config_commands" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -ac_cs_usage="\ -\`$as_me' instantiates files and other configuration actions -from templates according to the current configuration. Unless the files -and actions are specified as TAGs, all are instantiated by default. - -Usage: $0 [OPTION]... [TAG]... - - -h, --help print this help, then exit - -V, --version print version number and configuration settings, then exit - --config print configuration, then exit - -q, --quiet, --silent - do not print progress messages - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to the package provider." - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" -ac_cs_version="\\ -ccminer config.status 2014.05.03 -configured by $0, generated by GNU Autoconf 2.68, - with options \\"\$ac_cs_config\\" - -Copyright (C) 2010 Free Software Foundation, Inc. -This config.status script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it." - -ac_pwd='$ac_pwd' -srcdir='$srcdir' -INSTALL='$INSTALL' -MKDIR_P='$MKDIR_P' -AWK='$AWK' -test -n "\$AWK" || AWK=awk -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -# The default lists apply if the user does not specify any file. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=?*) - ac_option=`expr "X$1" : 'X\([^=]*\)='` - ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` - ac_shift=: - ;; - --*=) - ac_option=`expr "X$1" : 'X\([^=]*\)='` - ac_optarg= - ac_shift=: - ;; - *) - ac_option=$1 - ac_optarg=$2 - ac_shift=shift - ;; - esac - - case $ac_option in - # Handling of the options. - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - ac_cs_recheck=: ;; - --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) - $as_echo "$ac_cs_version"; exit ;; - --config | --confi | --conf | --con | --co | --c ) - $as_echo "$ac_cs_config"; exit ;; - --debug | --debu | --deb | --de | --d | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - $ac_shift - case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; - '') as_fn_error $? "missing file argument" ;; - esac - as_fn_append CONFIG_FILES " '$ac_optarg'" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - $ac_shift - case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - as_fn_append CONFIG_HEADERS " '$ac_optarg'" - ac_need_defaults=false;; - --he | --h) - # Conflict between --help and --header - as_fn_error $? "ambiguous option: \`$1' -Try \`$0 --help' for more information.";; - --help | --hel | -h ) - $as_echo "$ac_cs_usage"; exit ;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil | --si | --s) - ac_cs_silent=: ;; - - # This is an error. - -*) as_fn_error $? "unrecognized option: \`$1' -Try \`$0 --help' for more information." ;; - - *) as_fn_append ac_config_targets " $1" - ac_need_defaults=false ;; - - esac - shift -done - -ac_configure_extra_args= - -if $ac_cs_silent; then - exec 6>/dev/null - ac_configure_extra_args="$ac_configure_extra_args --silent" -fi - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -if \$ac_cs_recheck; then - set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion - shift - \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 - CONFIG_SHELL='$SHELL' - export CONFIG_SHELL - exec "\$@" -fi - -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -exec 5>>config.log -{ - echo - sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX -## Running $as_me. ## -_ASBOX - $as_echo "$ac_log" -} >&5 - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -# -# INIT-COMMANDS -# -AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 - -# Handling of arguments. -for ac_config_target in $ac_config_targets -do - case $ac_config_target in - "cpuminer-config.h") CONFIG_HEADERS="$CONFIG_HEADERS cpuminer-config.h" ;; - "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; - "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; - "compat/Makefile") CONFIG_FILES="$CONFIG_FILES compat/Makefile" ;; - "compat/jansson/Makefile") CONFIG_FILES="$CONFIG_FILES compat/jansson/Makefile" ;; - - *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; - esac -done - - -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Have a temporary directory for convenience. Make it in the build tree -# simply because there is no reason against having it here, and in addition, -# creating and moving files from /tmp can sometimes cause problems. -# Hook for its removal unless debugging. -# Note that there is a small window in which the directory will not be cleaned: -# after its creation but before its name has been assigned to `$tmp'. -$debug || -{ - tmp= ac_tmp= - trap 'exit_status=$? - : "${ac_tmp:=$tmp}" - { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status -' 0 - trap 'as_fn_exit 1' 1 2 13 15 -} -# Create a (secure) tmp directory for tmp files. - -{ - tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && - test -d "$tmp" -} || -{ - tmp=./conf$$-$RANDOM - (umask 077 && mkdir "$tmp") -} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 -ac_tmp=$tmp - -# Set up the scripts for CONFIG_FILES section. -# No need to generate them if there are no CONFIG_FILES. -# This happens for instance with `./config.status config.h'. -if test -n "$CONFIG_FILES"; then - - -ac_cr=`echo X | tr X '\015'` -# On cygwin, bash can eat \r inside `` if the user requested igncr. -# But we know of no other shell where ac_cr would be empty at this -# point, so we can use a bashism as a fallback. -if test "x$ac_cr" = x; then - eval ac_cr=\$\'\\r\' -fi -ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` -if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then - ac_cs_awk_cr='\\r' -else - ac_cs_awk_cr=$ac_cr -fi - -echo 'BEGIN {' >"$ac_tmp/subs1.awk" && -_ACEOF - - -{ - echo "cat >conf$$subs.awk <<_ACEOF" && - echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && - echo "_ACEOF" -} >conf$$subs.sh || - as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 -ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` -ac_delim='%!_!# ' -for ac_last_try in false false false false false :; do - . ./conf$$subs.sh || - as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 - - ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` - if test $ac_delim_n = $ac_delim_num; then - break - elif $ac_last_try; then - as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 - else - ac_delim="$ac_delim!$ac_delim _$ac_delim!! " - fi -done -rm -f conf$$subs.sh - -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && -_ACEOF -sed -n ' -h -s/^/S["/; s/!.*/"]=/ -p -g -s/^[^!]*!// -:repl -t repl -s/'"$ac_delim"'$// -t delim -:nl -h -s/\(.\{148\}\)..*/\1/ -t more1 -s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ -p -n -b repl -:more1 -s/["\\]/\\&/g; s/^/"/; s/$/"\\/ -p -g -s/.\{148\}// -t nl -:delim -h -s/\(.\{148\}\)..*/\1/ -t more2 -s/["\\]/\\&/g; s/^/"/; s/$/"/ -p -b -:more2 -s/["\\]/\\&/g; s/^/"/; s/$/"\\/ -p -g -s/.\{148\}// -t delim -' >$CONFIG_STATUS || ac_write_fail=1 -rm -f conf$$subs.awk -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -_ACAWK -cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && - for (key in S) S_is_set[key] = 1 - FS = "" - -} -{ - line = $ 0 - nfields = split(line, field, "@") - substed = 0 - len = length(field[1]) - for (i = 2; i < nfields; i++) { - key = field[i] - keylen = length(key) - if (S_is_set[key]) { - value = S[key] - line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) - len += length(value) + length(field[++i]) - substed = 1 - } else - len += 1 + keylen - } - - print line -} - -_ACAWK -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then - sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" -else - cat -fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ - || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 -_ACEOF - -# VPATH may cause trouble with some makes, so we remove sole $(srcdir), -# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ -h -s/// -s/^/:/ -s/[ ]*$/:/ -s/:\$(srcdir):/:/g -s/:\${srcdir}:/:/g -s/:@srcdir@:/:/g -s/^:*// -s/:*$// -x -s/\(=[ ]*\).*/\1/ -G -s/\n// -s/^[^=]*=[ ]*$// -}' -fi - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -fi # test -n "$CONFIG_FILES" - -# Set up the scripts for CONFIG_HEADERS section. -# No need to generate them if there are no CONFIG_HEADERS. -# This happens for instance with `./config.status Makefile'. -if test -n "$CONFIG_HEADERS"; then -cat >"$ac_tmp/defines.awk" <<\_ACAWK || -BEGIN { -_ACEOF - -# Transform confdefs.h into an awk script `defines.awk', embedded as -# here-document in config.status, that substitutes the proper values into -# config.h.in to produce config.h. - -# Create a delimiter string that does not exist in confdefs.h, to ease -# handling of long lines. -ac_delim='%!_!# ' -for ac_last_try in false false :; do - ac_tt=`sed -n "/$ac_delim/p" confdefs.h` - if test -z "$ac_tt"; then - break - elif $ac_last_try; then - as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 - else - ac_delim="$ac_delim!$ac_delim _$ac_delim!! " - fi -done - -# For the awk script, D is an array of macro values keyed by name, -# likewise P contains macro parameters if any. Preserve backslash -# newline sequences. - -ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* -sed -n ' -s/.\{148\}/&'"$ac_delim"'/g -t rset -:rset -s/^[ ]*#[ ]*define[ ][ ]*/ / -t def -d -:def -s/\\$// -t bsnl -s/["\\]/\\&/g -s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ -D["\1"]=" \3"/p -s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p -d -:bsnl -s/["\\]/\\&/g -s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ -D["\1"]=" \3\\\\\\n"\\/p -t cont -s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p -t cont -d -:cont -n -s/.\{148\}/&'"$ac_delim"'/g -t clear -:clear -s/\\$// -t bsnlc -s/["\\]/\\&/g; s/^/"/; s/$/"/p -d -:bsnlc -s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p -b cont -' >$CONFIG_STATUS || ac_write_fail=1 - -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 - for (key in D) D_is_set[key] = 1 - FS = "" -} -/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { - line = \$ 0 - split(line, arg, " ") - if (arg[1] == "#") { - defundef = arg[2] - mac1 = arg[3] - } else { - defundef = substr(arg[1], 2) - mac1 = arg[2] - } - split(mac1, mac2, "(") #) - macro = mac2[1] - prefix = substr(line, 1, index(line, defundef) - 1) - if (D_is_set[macro]) { - # Preserve the white space surrounding the "#". - print prefix "define", macro P[macro] D[macro] - next - } else { - # Replace #undef with comments. This is necessary, for example, - # in the case of _POSIX_SOURCE, which is predefined and required - # on some systems where configure will not decide to define it. - if (defundef == "undef") { - print "/*", prefix defundef, macro, "*/" - next - } - } -} -{ print } -_ACAWK -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 - as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 -fi # test -n "$CONFIG_HEADERS" - - -eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" -shift -for ac_tag -do - case $ac_tag in - :[FHLC]) ac_mode=$ac_tag; continue;; - esac - case $ac_mode$ac_tag in - :[FHL]*:*);; - :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; - :[FH]-) ac_tag=-:-;; - :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; - esac - ac_save_IFS=$IFS - IFS=: - set x $ac_tag - IFS=$ac_save_IFS - shift - ac_file=$1 - shift - - case $ac_mode in - :L) ac_source=$1;; - :[FH]) - ac_file_inputs= - for ac_f - do - case $ac_f in - -) ac_f="$ac_tmp/stdin";; - *) # Look for the file first in the build tree, then in the source tree - # (if the path is not absolute). The absolute path cannot be DOS-style, - # because $ac_f cannot contain `:'. - test -f "$ac_f" || - case $ac_f in - [\\/$]*) false;; - *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; - esac || - as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; - esac - case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac - as_fn_append ac_file_inputs " '$ac_f'" - done - - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated by config.status. */ - configure_input='Generated from '` - $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' - `' by configure.' - if test x"$ac_file" != x-; then - configure_input="$ac_file. $configure_input" - { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 -$as_echo "$as_me: creating $ac_file" >&6;} - fi - # Neutralize special characters interpreted by sed in replacement strings. - case $configure_input in #( - *\&* | *\|* | *\\* ) - ac_sed_conf_input=`$as_echo "$configure_input" | - sed 's/[\\\\&|]/\\\\&/g'`;; #( - *) ac_sed_conf_input=$configure_input;; - esac - - case $ac_tag in - *:-:* | *:-) cat >"$ac_tmp/stdin" \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; - esac - ;; - esac - - ac_dir=`$as_dirname -- "$ac_file" || -$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - as_dir="$ac_dir"; as_fn_mkdir_p - ac_builddir=. - -case "$ac_dir" in -.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; -*) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` - # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` - case $ac_top_builddir_sub in - "") ac_top_builddir_sub=. ac_top_build_prefix= ;; - *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; - esac ;; -esac -ac_abs_top_builddir=$ac_pwd -ac_abs_builddir=$ac_pwd$ac_dir_suffix -# for backward compatibility: -ac_top_builddir=$ac_top_build_prefix - -case $srcdir in - .) # We are building in place. - ac_srcdir=. - ac_top_srcdir=$ac_top_builddir_sub - ac_abs_top_srcdir=$ac_pwd ;; - [\\/]* | ?:[\\/]* ) # Absolute name. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir - ac_abs_top_srcdir=$srcdir ;; - *) # Relative name. - ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_build_prefix$srcdir - ac_abs_top_srcdir=$ac_pwd/$srcdir ;; -esac -ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix - - - case $ac_mode in - :F) - # - # CONFIG_FILE - # - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; - esac - ac_MKDIR_P=$MKDIR_P - case $MKDIR_P in - [\\/$]* | ?:[\\/]* ) ;; - */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; - esac -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -# If the template does not know about datarootdir, expand it. -# FIXME: This hack should be removed a few years after 2.60. -ac_datarootdir_hack=; ac_datarootdir_seen= -ac_sed_dataroot=' -/datarootdir/ { - p - q -} -/@datadir@/p -/@docdir@/p -/@infodir@/p -/@localedir@/p -/@mandir@/p' -case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in -*datarootdir*) ac_datarootdir_seen=yes;; -*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 -$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 - ac_datarootdir_hack=' - s&@datadir@&$datadir&g - s&@docdir@&$docdir&g - s&@infodir@&$infodir&g - s&@localedir@&$localedir&g - s&@mandir@&$mandir&g - s&\\\${datarootdir}&$datarootdir&g' ;; -esac -_ACEOF - -# Neutralize VPATH when `$srcdir' = `.'. -# Shell code in configure.ac might set extrasub. -# FIXME: do we really want to maintain this feature? -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_sed_extra="$ac_vpsub -$extrasub -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s|@configure_input@|$ac_sed_conf_input|;t t -s&@top_builddir@&$ac_top_builddir_sub&;t t -s&@top_build_prefix@&$ac_top_build_prefix&;t t -s&@srcdir@&$ac_srcdir&;t t -s&@abs_srcdir@&$ac_abs_srcdir&;t t -s&@top_srcdir@&$ac_top_srcdir&;t t -s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t -s&@builddir@&$ac_builddir&;t t -s&@abs_builddir@&$ac_abs_builddir&;t t -s&@abs_top_builddir@&$ac_abs_top_builddir&;t t -s&@INSTALL@&$ac_INSTALL&;t t -s&@MKDIR_P@&$ac_MKDIR_P&;t t -$ac_datarootdir_hack -" -eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ - >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 - -test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && - { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && - { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ - "$ac_tmp/out"`; test -z "$ac_out"; } && - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' -which seems to be undefined. Please make sure it is defined" >&5 -$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' -which seems to be undefined. Please make sure it is defined" >&2;} - - rm -f "$ac_tmp/stdin" - case $ac_file in - -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; - *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; - esac \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 - ;; - :H) - # - # CONFIG_HEADER - # - if test x"$ac_file" != x-; then - { - $as_echo "/* $configure_input */" \ - && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" - } >"$ac_tmp/config.h" \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 - if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then - { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 -$as_echo "$as_me: $ac_file is unchanged" >&6;} - else - rm -f "$ac_file" - mv "$ac_tmp/config.h" "$ac_file" \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 - fi - else - $as_echo "/* $configure_input */" \ - && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ - || as_fn_error $? "could not create -" "$LINENO" 5 - fi -# Compute "$ac_file"'s index in $config_headers. -_am_arg="$ac_file" -_am_stamp_count=1 -for _am_header in $config_headers :; do - case $_am_header in - $_am_arg | $_am_arg:* ) - break ;; - * ) - _am_stamp_count=`expr $_am_stamp_count + 1` ;; - esac -done -echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || -$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$_am_arg" : 'X\(//\)[^/]' \| \ - X"$_am_arg" : 'X\(//\)$' \| \ - X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$_am_arg" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'`/stamp-h$_am_stamp_count - ;; - - :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 -$as_echo "$as_me: executing $ac_file commands" >&6;} - ;; - esac - - - case $ac_file$ac_mode in - "depfiles":C) test x"$AMDEP_TRUE" != x"" || { - # Autoconf 2.62 quotes --file arguments for eval, but not when files - # are listed without --file. Let's play safe and only enable the eval - # if we detect the quoting. - case $CONFIG_FILES in - *\'*) eval set x "$CONFIG_FILES" ;; - *) set x $CONFIG_FILES ;; - esac - shift - for mf - do - # Strip MF so we end up with the name of the file. - mf=`echo "$mf" | sed -e 's/:.*$//'` - # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named `Makefile.in', but - # some people rename them; so instead we look at the file content. - # Grep'ing the first line is not enough: some people post-process - # each Makefile.in and add a new line on top of each file to say so. - # Grep'ing the whole file is not good either: AIX grep has a line - # limit of 2048, but all sed's we know have understand at least 4000. - if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then - dirpart=`$as_dirname -- "$mf" || -$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$mf" : 'X\(//\)[^/]' \| \ - X"$mf" : 'X\(//\)$' \| \ - X"$mf" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$mf" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - else - continue - fi - # Extract the definition of DEPDIR, am__include, and am__quote - # from the Makefile without running `make'. - DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` - test -z "$DEPDIR" && continue - am__include=`sed -n 's/^am__include = //p' < "$mf"` - test -z "am__include" && continue - am__quote=`sed -n 's/^am__quote = //p' < "$mf"` - # When using ansi2knr, U may be empty or an underscore; expand it - U=`sed -n 's/^U = //p' < "$mf"` - # Find all dependency output files, they are included files with - # $(DEPDIR) in their names. We invoke sed twice because it is the - # simplest approach to changing $(DEPDIR) to its actual value in the - # expansion. - for file in `sed -n " - s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do - # Make sure the directory exists. - test -f "$dirpart/$file" && continue - fdir=`$as_dirname -- "$file" || -$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$file" : 'X\(//\)[^/]' \| \ - X"$file" : 'X\(//\)$' \| \ - X"$file" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - as_dir=$dirpart/$fdir; as_fn_mkdir_p - # echo "creating $dirpart/$file" - echo '# dummy' > "$dirpart/$file" - done - done -} - ;; - - esac -done # for ac_tag - - -as_fn_exit 0 -_ACEOF -ac_clean_files=$ac_clean_files_save - -test $ac_write_fail = 0 || - as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 - - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - ac_config_status_args= - test "$silent" = yes && - ac_config_status_args="$ac_config_status_args --quiet" - exec 5>/dev/null - $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || as_fn_exit 1 -fi -if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 -$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} -fi - diff --git a/configure.ac b/configure.ac index 80438fd..25239cd 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ -AC_INIT([ccminer], [2014.06.14]) +AC_INIT([ccminer-cryptonight], [3.06]) AC_PREREQ([2.59c]) AC_CANONICAL_SYSTEM -AC_CONFIG_SRCDIR([cpu-miner.c]) +AC_CONFIG_SRCDIR([cpu-miner.cpp]) AM_INIT_AUTOMAKE([gnu]) AC_CONFIG_HEADERS([cpuminer-config.h]) diff --git a/configure.sh b/configure.sh old mode 100644 new mode 100755 index 134abd1..010b5a3 --- a/configure.sh +++ b/configure.sh @@ -1 +1 @@ -./configure "CFLAGS=-O3" "CXXFLAGS=-O3" --with-cuda=/usr/local/cuda +./configure "CFLAGS=-O3" "CXXFLAGS=-O3" --with-cuda=/usr/local/cuda diff --git a/cpu-miner.c b/cpu-miner.c deleted file mode 100755 index 0241d17..0000000 --- a/cpu-miner.c +++ /dev/null @@ -1,2090 +0,0 @@ -/* - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. See COPYING for more details. - */ - -#include "cpuminer-config.h" -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef WIN32 -#include -#else -#include -#include -#include -#if HAVE_SYS_SYSCTL_H -#include -#if HAVE_SYS_PARAM_H -#include -#endif -#include -#endif -#endif -#include -#include -#include -#include "compat.h" -#include "miner.h" - -#ifdef WIN32 -#include -#pragma comment(lib, "winmm.lib") -#endif - -#define PROGRAM_NAME "minerd" -#define LP_SCANTIME 60 -#define HEAVYCOIN_BLKHDR_SZ 84 -#define MNR_BLKHDR_SZ 80 -#define JSON_BUF_LEN 345 - -// from heavy.cu -#ifdef __cplusplus -extern "C" -{ -#endif -int cuda_num_devices(); -void cuda_deviceinfo(); -int cuda_finddevice(char *name); -#ifdef __cplusplus -} -#endif - -extern void cryptonight_hash(void* output, const void* input, size_t len); -void parse_device_config( char *config, int *blocks, int *threads ); - -#ifdef __linux /* Linux specific policy and affinity management */ -#include -static inline void drop_policy(void) -{ - struct sched_param param; - param.sched_priority = 0; - -#ifdef SCHED_IDLE - if (unlikely(sched_setscheduler(0, SCHED_IDLE, ¶m) == -1)) -#endif -#ifdef SCHED_BATCH - sched_setscheduler(0, SCHED_BATCH, ¶m); -#endif -} - -static inline void affine_to_cpu(int id, int cpu) -{ - cpu_set_t set; - - CPU_ZERO(&set); - CPU_SET(cpu, &set); - sched_setaffinity(0, sizeof(&set), &set); -} -#elif defined(__FreeBSD__) /* FreeBSD specific policy and affinity management */ -#include -static inline void drop_policy(void) -{ -} - -static inline void affine_to_cpu(int id, int cpu) -{ - cpuset_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &set); -} -#else -static inline void drop_policy(void) -{ -} - -static inline void affine_to_cpu(int id, int cpu) -{ -} -#endif - -enum workio_commands { - WC_GET_WORK, - WC_SUBMIT_WORK, -}; - -struct workio_cmd { - enum workio_commands cmd; - struct thr_info *thr; - union { - struct work *work; - } u; -}; - -typedef enum { - ALGO_HEAVY, /* Heavycoin hash */ - ALGO_MJOLLNIR, /* Mjollnir hash */ - ALGO_FUGUE256, /* Fugue256 */ - ALGO_GROESTL, - ALGO_MYR_GR, - ALGO_JACKPOT, - ALGO_QUARK, - ALGO_ANIME, - ALGO_NIST5, - ALGO_X11, - ALGO_X13, - ALGO_CRYPTONIGHT -} sha256_algos; - -static const char *algo_names[] = { - "heavy", - "mjollnir", - "fugue256", - "groestl", - "myr-gr", - "jackpot", - "quark", - "anime", - "nist5", - "x11", - "x13", - "cryptonight" -}; - -bool opt_debug = false; -bool opt_protocol = false; -bool opt_benchmark = false; -bool want_longpoll = true; -bool have_longpoll = false; -bool want_stratum = true; -bool have_stratum = false; -static bool submit_old = false; -bool use_syslog = false; -static bool opt_background = false; -static bool opt_quiet = false; -static int opt_retries = -1; -static int opt_fail_pause = 30; -int opt_timeout = 270; -static int opt_scantime = 5; -static json_t *opt_config; -static const bool opt_time = true; -static sha256_algos opt_algo = ALGO_CRYPTONIGHT; -static int opt_n_threads = 0; -static double opt_difficulty = 1; // CH -bool opt_trust_pool = false; -uint16_t opt_vote = 9999; -static int num_processors; -int device_map[8] = {0,1,2,3,4,5,6,7}; // CB -char *device_name[8]; // CB -int device_arch[8][2]; -int device_mpcount[8]; -int device_bfactor[8]; -int device_bsleep[8]; -int device_config[8][2]; -#ifdef WIN32 -static int default_bfactor = 6; -static int default_bsleep = 100; -#else -static int default_bfactor = 0; -static int default_bsleep = 0; -#endif -static char *rpc_url; -static char *rpc_userpass; -static char *rpc_user, *rpc_pass; -char *opt_cert; -char *opt_proxy; -long opt_proxy_type; -struct thr_info *thr_info; -static int work_thr_id; -int longpoll_thr_id = -1; -int stratum_thr_id = -1; -struct work_restart *work_restart = NULL; -static struct stratum_ctx stratum; -int opt_cn_threads = 8; -int opt_cn_blocks = 40; - -bool jsonrpc_2 = false; -static char rpc2_id[64] = ""; -static char *rpc2_blob = NULL; -static int rpc2_bloblen = 0; -static uint32_t rpc2_target = 0; -static char *rpc2_job_id = NULL; -static pthread_mutex_t rpc2_job_lock; -static pthread_mutex_t rpc2_login_lock; - -pthread_mutex_t applog_lock; -static pthread_mutex_t stats_lock; - -static unsigned long accepted_count = 0L; -static unsigned long rejected_count = 0L; -static double *thr_hashrates; - -#ifdef HAVE_GETOPT_LONG -#include -#else -struct option { - const char *name; - int has_arg; - int *flag; - int val; -}; -#endif - -static char const usage[] = "\ -Usage: " PROGRAM_NAME " [OPTIONS]\n\ -Options:\n\ - -d, --devices takes a comma separated list of CUDA devices to use.\n\ - Device IDs start counting from 0! Alternatively takes\n\ - string names of your cards like gtx780ti or gt640#2\n\ - (matching 2nd gt640 in the PC)\n\ - -f, --diff Divide difficulty by this factor (std is 1) \n\ - -l, --launch=CONFIG launch config for the Cryptonight kernel.\n\ - a comma separated list of values in form of\n\ - AxB where A is the number of threads to run in\n\ - each thread block and B is the number of thread\n\ - blocks to launch. If less values than devices in use\n\ - are provided, the last value will be used for\n\ - the remaining devices. If you don't need to vary the\n\ - value between devices, you can just enter a single value\n\ - and it will be used for all devices. (default: 8x40)\n\ - --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ - The kernel will be run in 2^X parts according to bfactor,\n\ - with a small pause between parts, specified by --bsleep.\n\ - This is a per-device setting like the launch config.\n\ - (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ - --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ - Use in combination with --bfactor to mitigate the lag\n\ - when running on your primary GPU.\n\ - This is a per-device setting like the launch config.\n\ - -m, --trust-pool trust the max block reward vote (maxvote) sent by the pool\n\ - -o, --url=URL URL of mining server\n\ - -O, --userpass=U:P username:password pair for mining server\n\ - -u, --user=USERNAME username for mining server\n\ - -p, --pass=PASSWORD password for mining server\n\ - --cert=FILE certificate for mining server using SSL\n\ - -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy\n\ - -t, --threads=N number of miner threads (default: number of nVidia GPUs)\n\ - -r, --retries=N number of times to retry if a network call fails\n\ - (default: retry indefinitely)\n\ - -R, --retry-pause=N time to pause between retries, in seconds (default: 30)\n\ - -T, --timeout=N network timeout, in seconds (default: 270)\n\ - -s, --scantime=N upper bound on time spent scanning current work when\n\ - long polling is unavailable, in seconds (default: 5)\n\ - --no-longpoll disable X-Long-Polling support\n\ - --no-stratum disable X-Stratum support\n\ - -q, --quiet disable per-thread hashmeter output\n\ - -D, --debug enable debug output\n\ - -P, --protocol-dump verbose dump of protocol-level activities\n" -#ifdef HAVE_SYSLOG_H -"\ - -S, --syslog use system log for output messages\n" -#endif -#ifndef WIN32 -"\ - -B, --background run the miner in the background\n" -#endif -"\ - --benchmark run in offline benchmark mode\n\ - -c, --config=FILE load a JSON-format configuration file\n\ - -V, --version display version information and exit\n\ - -h, --help display this help text and exit\n\ -"; - -static char const short_options[] = -#ifndef WIN32 - "B" -#endif -#ifdef HAVE_SYSLOG_H - "S" -#endif - "a:c:Dhp:Px:qr:R:s:t:T:o:u:O:Vd:f:ml:"; - -static struct option const options[] = { - { "algo", 1, NULL, 'a' }, -#ifndef WIN32 - { "background", 0, NULL, 'B' }, -#endif - { "benchmark", 0, NULL, 1005 }, - { "cert", 1, NULL, 1001 }, - { "config", 1, NULL, 'c' }, - { "debug", 0, NULL, 'D' }, - { "help", 0, NULL, 'h' }, - { "no-longpoll", 0, NULL, 1003 }, - { "no-stratum", 0, NULL, 1007 }, - { "pass", 1, NULL, 'p' }, - { "protocol-dump", 0, NULL, 'P' }, - { "proxy", 1, NULL, 'x' }, - { "quiet", 0, NULL, 'q' }, - { "retries", 1, NULL, 'r' }, - { "retry-pause", 1, NULL, 'R' }, - { "scantime", 1, NULL, 's' }, -#ifdef HAVE_SYSLOG_H - { "syslog", 0, NULL, 'S' }, -#endif - { "threads", 1, NULL, 't' }, - { "trust-pool", 0, NULL, 'm' }, - { "timeout", 1, NULL, 'T' }, - { "url", 1, NULL, 'o' }, - { "user", 1, NULL, 'u' }, - { "userpass", 1, NULL, 'O' }, - { "version", 0, NULL, 'V' }, - { "devices", 1, NULL, 'd' }, - { "diff", 1, NULL, 'f' }, - { "launch", 1, NULL, 'l' }, - { "launch-config", 1, NULL, 'l' }, - { "bfactor", 1, NULL, 1008 }, - { "bsleep", 1, NULL, 1009 }, - { 0, 0, 0, 0 } -}; - -static struct work g_work; -static time_t g_work_time; -static pthread_mutex_t g_work_lock; - -static bool rpc2_login(CURL *curl); - -json_t *json_rpc2_call_recur(CURL *curl, const char *url, - const char *userpass, json_t *rpc_req, - int *curl_err, int flags, int recur) { - if(recur >= 5) { - if(opt_debug) - applog(LOG_DEBUG, "Failed to call rpc command after %i tries", recur); - return NULL; - } - if(!strcmp(rpc2_id, "")) { - if(opt_debug) - applog(LOG_DEBUG, "Tried to call rpc2 command before authentication"); - return NULL; - } - json_t *params = json_object_get(rpc_req, "params"); - if (params) { - json_t *auth_id = json_object_get(params, "id"); - if (auth_id) { - json_string_set(auth_id, rpc2_id); - } - } - json_t *res = json_rpc_call(curl, url, userpass, json_dumps(rpc_req, 0), false, false, - curl_err); - if(!res) goto end; - json_t *error = json_object_get(res, "error"); - if(!error) goto end; - json_t *message; - if(json_is_string(error)) - message = error; - else - message = json_object_get(error, "message"); - if(!message || !json_is_string(message)) goto end; - const char *mes = json_string_value(message); - if(!strcmp(mes, "Unauthenticated")) { - pthread_mutex_lock(&rpc2_login_lock); - rpc2_login(curl); - sleep(1); - pthread_mutex_unlock(&rpc2_login_lock); - return json_rpc2_call_recur(curl, url, userpass, rpc_req, - curl_err, flags, recur + 1); - } else if(!strcmp(mes, "Low difficulty share") || !strcmp(mes, "Block expired") || !strcmp(mes, "Invalid job id") || !strcmp(mes, "Duplicate share")) { - json_t *result = json_object_get(res, "result"); - if(!result) { - goto end; - } - json_object_set(result, "reject-reason", json_string(mes)); - } else { - applog(LOG_ERR, "json_rpc2.0 error: %s", mes); - return NULL; - } - end: - return res; -} - -json_t *json_rpc2_call(CURL *curl, const char *url, - const char *userpass, const char *rpc_req, - int *curl_err, int flags) { - return json_rpc2_call_recur(curl, url, userpass, JSON_LOADS(rpc_req, NULL), - curl_err, flags, 0); -} - -static bool jobj_binary(const json_t *obj, const char *key, - void *buf, size_t buflen) -{ - const char *hexstr; - json_t *tmp; - - tmp = json_object_get(obj, key); - if (unlikely(!tmp)) { - applog(LOG_ERR, "JSON key '%s' not found", key); - return false; - } - hexstr = json_string_value(tmp); - if (unlikely(!hexstr)) { - applog(LOG_ERR, "JSON key '%s' is not a string", key); - return false; - } - if (!hex2bin((unsigned char*)buf, hexstr, buflen)) - return false; - - return true; -} - -bool rpc2_job_decode(const json_t *job, struct work *work) { - if (!jsonrpc_2) { - applog(LOG_ERR, "Tried to decode job without JSON-RPC 2.0"); - return false; - } - json_t *tmp; - tmp = json_object_get(job, "job_id"); - if (!tmp) { - applog(LOG_ERR, "JSON inval job id"); - goto err_out; - } - const char *job_id = json_string_value(tmp); - tmp = json_object_get(job, "blob"); - if (!tmp) { - applog(LOG_ERR, "JSON inval blob"); - goto err_out; - } - const char *hexblob = json_string_value(tmp); - int blobLen = strlen(hexblob); - if (blobLen % 2 != 0 || ((blobLen / 2) < 40 && blobLen != 0) || (blobLen / 2) > 128) { - applog(LOG_ERR, "JSON invalid blob length"); - goto err_out; - } - if (blobLen != 0) { - pthread_mutex_lock(&rpc2_job_lock); - char *blob = (char *)malloc(blobLen / 2); - if (!hex2bin((unsigned char *)blob, hexblob, blobLen / 2)) { - applog(LOG_ERR, "JSON inval blob"); - pthread_mutex_unlock(&rpc2_job_lock); - goto err_out; - } - if (rpc2_blob) { - free(rpc2_blob); - } - rpc2_bloblen = blobLen / 2; - rpc2_blob = (char *)malloc(rpc2_bloblen); - memcpy(rpc2_blob, blob, blobLen / 2); - - free(blob); - - uint32_t target; - jobj_binary(job, "target", &target, 4); - if(rpc2_target != target) { - double hashrate = 0.; - pthread_mutex_lock(&stats_lock); - for (int i = 0; i < opt_n_threads; i++) - hashrate += thr_hashrates[i]; - pthread_mutex_unlock(&stats_lock); - double difficulty = (((double) 0xffffffff) / target); - applog(LOG_INFO, "Pool set diff to %g", difficulty); - rpc2_target = target; - } - - if (rpc2_job_id) { - free(rpc2_job_id); - } - rpc2_job_id = strdup(job_id); - pthread_mutex_unlock(&rpc2_job_lock); - } - if(work) { - if (!rpc2_blob) { - applog(LOG_ERR, "Requested work before work was received"); - goto err_out; - } - memcpy(work->data, rpc2_blob, rpc2_bloblen); - memset(work->target, 0xff, sizeof(work->target)); - work->target[7] = rpc2_target; - strncpy(work->job_id, rpc2_job_id, 128); - } - return true; - - err_out: - return false; -} - -static bool work_decode(const json_t *val, struct work *work) -{ - int i; - - if(jsonrpc_2) { - return rpc2_job_decode(val, work); - } - - if (unlikely(!jobj_binary(val, "data", work->data, sizeof(work->data)))) { - applog(LOG_ERR, "JSON inval data"); - goto err_out; - } - if (unlikely(!jobj_binary(val, "target", work->target, sizeof(work->target)))) { - applog(LOG_ERR, "JSON inval target"); - goto err_out; - } - if (opt_algo == ALGO_HEAVY) { - if (unlikely(!jobj_binary(val, "maxvote", &work->maxvote, sizeof(work->maxvote)))) { - work->maxvote = 1024; - } - } else work->maxvote = 0; - - for (i = 0; i < ARRAY_SIZE(work->data); i++) - work->data[i] = le32dec(work->data + i); - for (i = 0; i < ARRAY_SIZE(work->target); i++) - work->target[i] = le32dec(work->target + i); - - return true; - -err_out: - return false; -} - -bool rpc2_login_decode(const json_t *val) { - const char *id; - const char *s; - - json_t *res = json_object_get(val, "result"); - if(!res) { - applog(LOG_ERR, "JSON invalid result"); - goto err_out; - } - - json_t *tmp; - tmp = json_object_get(res, "id"); - if(!tmp) { - applog(LOG_ERR, "JSON inval id"); - goto err_out; - } - id = json_string_value(tmp); - if(!id) { - applog(LOG_ERR, "JSON id is not a string"); - goto err_out; - } - - memcpy(&rpc2_id, id, 64); - - if(opt_debug) - applog(LOG_DEBUG, "Auth id: %s", id); - - tmp = json_object_get(res, "status"); - if(!tmp) { - applog(LOG_ERR, "JSON inval status"); - goto err_out; - } - s = json_string_value(tmp); - if(!s) { - applog(LOG_ERR, "JSON status is not a string"); - goto err_out; - } - if(strcmp(s, "OK")) { - applog(LOG_ERR, "JSON returned status \"%s\"", s); - return false; - } - - return true; - - err_out: return false; -} - -static void share_result(int result, const char *reason) -{ - char s[345]; - double hashrate; - int i; - - hashrate = 0.; - pthread_mutex_lock(&stats_lock); - for (i = 0; i < opt_n_threads; i++) - hashrate += thr_hashrates[i]; - result ? accepted_count++ : rejected_count++; - pthread_mutex_unlock(&stats_lock); - - if (opt_algo == ALGO_CRYPTONIGHT) { - applog(LOG_INFO, "accepted: %lu/%lu (%.2f%%), %.2f H/s %s", - accepted_count, accepted_count + rejected_count, - 100. * accepted_count / (accepted_count + rejected_count), hashrate, - result ? "(yay!!!)" : "(booooo)"); - } else { - sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate); - applog(LOG_INFO, "accepted: %lu/%lu (%.2f%%), %s khash/s %s", - accepted_count, - accepted_count + rejected_count, - 100. * accepted_count / (accepted_count + rejected_count), - s, - result ? "(yay!!!)" : "(booooo)"); - } - if (opt_debug && reason) - applog(LOG_DEBUG, "DEBUG: reject reason: %s", reason); -} - -static bool submit_upstream_work(CURL *curl, struct work *work) -{ - char *str = NULL; - json_t *val, *res, *reason; - char s[345]; - int i; - bool rc = false; - - /* pass if the previous hash is not the current previous hash */ - if (memcmp(work->data + 1, g_work.data + 1, 32)) { - if (opt_debug) - applog(LOG_DEBUG, "DEBUG: stale work detected, discarding"); - return true; - } - - if (have_stratum) { - uint32_t ntime, nonce; - uint16_t nvote; - char *ntimestr, *noncestr, *xnonce2str, *nvotestr; - - if (jsonrpc_2) { - noncestr = bin2hex(((const unsigned char*)work->data) + 39, 4); - char hash[32]; - cryptonight_hash((void *)hash, (const void *)work->data, 76); - char *hashhex = bin2hex((const unsigned char *)hash, 32); - snprintf(s, JSON_BUF_LEN, - "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":1}\r\n", - rpc2_id, work->job_id, noncestr, hashhex); - free(hashhex); - } else { - le32enc(&ntime, work->data[17]); - le32enc(&nonce, work->data[19]); - be16enc(&nvote, *((uint16_t*)&work->data[20])); - - ntimestr = bin2hex((const unsigned char *)(&ntime), 4); - noncestr = bin2hex((const unsigned char *)(&nonce), 4); - xnonce2str = bin2hex(work->xnonce2, work->xnonce2_len); - nvotestr = bin2hex((const unsigned char *)(&nvote), 2); - if (opt_algo == ALGO_HEAVY) { - sprintf(s, - "{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}", - rpc_user, work->job_id, xnonce2str, ntimestr, noncestr, nvotestr); - } else { - sprintf(s, - "{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}", - rpc_user, work->job_id, xnonce2str, ntimestr, noncestr); - } - free(ntimestr); - free(xnonce2str); - free(nvotestr); - } - free(noncestr); - - if (unlikely(!stratum_send_line(&stratum, s))) { - applog(LOG_ERR, "submit_upstream_work stratum_send_line failed"); - goto out; - } - } else { - /* build JSON-RPC request */ - if(jsonrpc_2) { - char *noncestr = bin2hex(((const unsigned char*)work->data) + 39, 4); - char hash[32]; - cryptonight_hash((void *)hash, (const void *)work->data, 76); - char *hashhex = bin2hex((const unsigned char *)hash, 32); - snprintf(s, JSON_BUF_LEN, - "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":1}\r\n", - rpc2_id, work->job_id, noncestr, hashhex); - free(noncestr); - free(hashhex); - - /* issue JSON-RPC request */ - val = json_rpc2_call(curl, rpc_url, rpc_userpass, s, NULL, 0); - if (unlikely(!val)) { - applog(LOG_ERR, "submit_upstream_work json_rpc_call failed"); - goto out; - } - res = json_object_get(val, "result"); - json_t *status = json_object_get(res, "status"); - reason = json_object_get(res, "reject-reason"); - share_result(!strcmp(status ? json_string_value(status) : "", "OK"), - reason ? json_string_value(reason) : NULL ); - } else { - - /* build hex string */ - - if (opt_algo != ALGO_HEAVY && opt_algo != ALGO_MJOLLNIR) { - for (i = 0; i < ARRAY_SIZE(work->data); i++) - le32enc(work->data + i, work->data[i]); - } - str = bin2hex((unsigned char *)work->data, sizeof(work->data)); - if (unlikely(!str)) { - applog(LOG_ERR, "submit_upstream_work OOM"); - goto out; - } - - /* build JSON-RPC request */ - sprintf(s, - "{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}\r\n", - str); - - /* issue JSON-RPC request */ - val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL); - if (unlikely(!val)) { - applog(LOG_ERR, "submit_upstream_work json_rpc_call failed"); - goto out; - } - - res = json_object_get(val, "result"); - reason = json_object_get(val, "reject-reason"); - share_result(json_is_true(res), reason ? json_string_value(reason) : NULL); - } - - json_decref(val); - } - - rc = true; - -out: - free(str); - return rc; -} - -static const char *rpc_req = - "{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n"; - -static bool get_upstream_work(CURL *curl, struct work *work) -{ - json_t *val; - bool rc; - struct timeval tv_start, tv_end, diff; - - gettimeofday(&tv_start, NULL); - - if(jsonrpc_2) { - char s[128]; - snprintf(s, 128, "{\"method\": \"getjob\", \"params\": {\"id\": \"%s\"}, \"id\":1}\r\n", rpc2_id); - val = json_rpc2_call(curl, rpc_url, rpc_userpass, s, NULL, 0); - } else { - val = json_rpc_call(curl, rpc_url, rpc_userpass, rpc_req, - want_longpoll, false, NULL); - } - gettimeofday(&tv_end, NULL); - - if (have_stratum) { - if (val) - json_decref(val); - return true; - } - - if (!val) - return false; - - rc = work_decode(json_object_get(val, "result"), work); - - if (opt_debug && rc) { - timeval_subtract(&diff, &tv_end, &tv_start); - applog(LOG_DEBUG, "DEBUG: got new work in %d ms", - diff.tv_sec * 1000 + diff.tv_usec / 1000); - } - - json_decref(val); - - return rc; -} - -static bool rpc2_login(CURL *curl) { - if(!jsonrpc_2) { - return false; - } - json_t *val; - bool rc; - struct timeval tv_start, tv_end, diff; - char s[345]; - - snprintf(s, JSON_BUF_LEN, "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"" USER_AGENT "\"}, \"id\": 1}", rpc_user, rpc_pass); - - gettimeofday(&tv_start, NULL ); - val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL); - gettimeofday(&tv_end, NULL ); - - if (!val) - goto end; - -// applog(LOG_DEBUG, "JSON value: %s", json_dumps(val, 0)); - - rc = rpc2_login_decode(val); - - json_t *result = json_object_get(val, "result"); - - if(!result) goto end; - - json_t *job = json_object_get(result, "job"); - - if(!rpc2_job_decode(job, &g_work)) { - goto end; - } - - if (opt_debug && rc) { - timeval_subtract(&diff, &tv_end, &tv_start); - applog(LOG_DEBUG, "DEBUG: authenticated in %d ms", - diff.tv_sec * 1000 + diff.tv_usec / 1000); - } - - json_decref(val); - - end: - return rc; -} - -static void workio_cmd_free(struct workio_cmd *wc) -{ - if (!wc) - return; - - switch (wc->cmd) { - case WC_SUBMIT_WORK: - free(wc->u.work); - break; - default: /* do nothing */ - break; - } - - memset(wc, 0, sizeof(*wc)); /* poison */ - free(wc); -} - -static bool workio_get_work(struct workio_cmd *wc, CURL *curl) -{ - struct work *ret_work; - int failures = 0; - - ret_work = (struct work*)calloc(1, sizeof(*ret_work)); - if (!ret_work) - return false; - - /* obtain new work from bitcoin via JSON-RPC */ - while (!get_upstream_work(curl, ret_work)) { - if (unlikely((opt_retries >= 0) && (++failures > opt_retries))) { - applog(LOG_ERR, "json_rpc_call failed, terminating workio thread"); - free(ret_work); - return false; - } - - /* pause, then restart work-request loop */ - applog(LOG_ERR, "json_rpc_call failed, retry after %d seconds", - opt_fail_pause); - sleep(opt_fail_pause); - } - - /* send work to requesting thread */ - if (!tq_push(wc->thr->q, ret_work)) - free(ret_work); - - return true; -} - -static bool workio_submit_work(struct workio_cmd *wc, CURL *curl) -{ - int failures = 0; - - /* submit solution to bitcoin via JSON-RPC */ - while (!submit_upstream_work(curl, wc->u.work)) { - if (unlikely((opt_retries >= 0) && (++failures > opt_retries))) { - applog(LOG_ERR, "...terminating workio thread"); - return false; - } - - /* pause, then restart work-request loop */ - applog(LOG_ERR, "...retry after %d seconds", - opt_fail_pause); - sleep(opt_fail_pause); - } - - return true; -} - -static bool workio_login(CURL *curl) { - int failures = 0; - - /* submit solution to bitcoin via JSON-RPC */ - pthread_mutex_lock(&rpc2_login_lock); - while (!rpc2_login(curl)) { - if (unlikely((opt_retries >= 0) && (++failures > opt_retries))) { - applog(LOG_ERR, "...terminating workio thread"); - pthread_mutex_unlock(&rpc2_login_lock); - return false; - } - - /* pause, then restart work-request loop */ - applog(LOG_ERR, "...retry after %d seconds", opt_fail_pause); - sleep(opt_fail_pause); - pthread_mutex_unlock(&rpc2_login_lock); - pthread_mutex_lock(&rpc2_login_lock); - } - pthread_mutex_unlock(&rpc2_login_lock); - - return true; -} - -static void *workio_thread(void *userdata) -{ - struct thr_info *mythr = (struct thr_info*)userdata; - CURL *curl; - bool ok = true; - - curl = curl_easy_init(); - if (unlikely(!curl)) { - applog(LOG_ERR, "CURL initialization failed"); - return NULL; - } - - if(!have_stratum) { - ok = workio_login(curl); - } - - while (ok) { - struct workio_cmd *wc; - - /* wait for workio_cmd sent to us, on our queue */ - wc = (struct workio_cmd *)tq_pop(mythr->q, NULL); - if (!wc) { - ok = false; - break; - } - - /* process workio_cmd */ - switch (wc->cmd) { - case WC_GET_WORK: - ok = workio_get_work(wc, curl); - break; - case WC_SUBMIT_WORK: - ok = workio_submit_work(wc, curl); - break; - - default: /* should never happen */ - ok = false; - break; - } - - workio_cmd_free(wc); - } - - tq_freeze(mythr->q); - curl_easy_cleanup(curl); - - return NULL; -} - -static bool get_work(struct thr_info *thr, struct work *work) -{ - struct workio_cmd *wc; - struct work *work_heap; - - if (opt_benchmark) { - memset(work->data, 0x55, 76); - work->data[17] = swab32((uint32_t)time(NULL)); - memset(work->data + 19, 0x00, 52); - work->data[20] = 0x80000000; - work->data[31] = 0x00000280; - memset(work->target, 0x00, sizeof(work->target)); - return true; - } - - /* fill out work request message */ - wc = (struct workio_cmd *)calloc(1, sizeof(*wc)); - if (!wc) - return false; - - wc->cmd = WC_GET_WORK; - wc->thr = thr; - - /* send work request to workio thread */ - if (!tq_push(thr_info[work_thr_id].q, wc)) { - workio_cmd_free(wc); - return false; - } - - /* wait for response, a unit of work */ - work_heap = (struct work *)tq_pop(thr->q, NULL); - if (!work_heap) - return false; - - /* copy returned work into storage provided by caller */ - memcpy(work, work_heap, sizeof(*work)); - free(work_heap); - - return true; -} - -static bool submit_work(struct thr_info *thr, const struct work *work_in) -{ - struct workio_cmd *wc; - /* fill out work request message */ - wc = (struct workio_cmd *)calloc(1, sizeof(*wc)); - if (!wc) - return false; - - wc->u.work = (struct work *)malloc(sizeof(*work_in)); - if (!wc->u.work) - goto err_out; - - wc->cmd = WC_SUBMIT_WORK; - wc->thr = thr; - memcpy(wc->u.work, work_in, sizeof(*work_in)); - - /* send solution to workio thread */ - if (!tq_push(thr_info[work_thr_id].q, wc)) - goto err_out; - - return true; - -err_out: - workio_cmd_free(wc); - return false; -} - -static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work) -{ - unsigned char merkle_root[64]; - int i; - - pthread_mutex_lock(&sctx->work_lock); - - if (jsonrpc_2) { - memcpy(work, &sctx->work, sizeof(struct work)); - if( sctx->job.job_id ) strncpy(work->job_id, sctx->job.job_id, 128); - pthread_mutex_unlock(&sctx->work_lock); - } else { - if( sctx->job.job_id ) strncpy(work->job_id, sctx->job.job_id, 128); - work->xnonce2_len = sctx->xnonce2_size; - memcpy(work->xnonce2, sctx->job.xnonce2, sctx->xnonce2_size); - - /* Generate merkle root */ - sha256d(merkle_root, sctx->job.coinbase, (int)sctx->job.coinbase_size); - - for (i = 0; i < sctx->job.merkle_count; i++) { - memcpy(merkle_root + 32, sctx->job.merkle[i], 32); - sha256d(merkle_root, merkle_root, 64); - } - - /* Increment extranonce2 */ - for (i = 0; i < (int)sctx->xnonce2_size && !++sctx->job.xnonce2[i]; i++); - - /* Assemble block header */ - memset(work->data, 0, 128); - work->data[0] = le32dec(sctx->job.version); - for (i = 0; i < 8; i++) - work->data[1 + i] = le32dec((uint32_t *)sctx->job.prevhash + i); - for (i = 0; i < 8; i++) - work->data[9 + i] = be32dec((uint32_t *)merkle_root + i); - work->data[17] = le32dec(sctx->job.ntime); - work->data[18] = le32dec(sctx->job.nbits); - work->data[20] = 0x80000000; - work->data[31] = 0x00000280; - - pthread_mutex_unlock(&sctx->work_lock); - - if (opt_debug) { - char *xnonce2str = bin2hex(work->xnonce2, sctx->xnonce2_size); - applog(LOG_DEBUG, "DEBUG: job_id='%s' extranonce2=%s ntime=%08x", - work->job_id, xnonce2str, swab32(work->data[17])); - free(xnonce2str); - } - - diff_to_target(work->target, sctx->job.diff / opt_difficulty); - } -} - -static void *miner_thread(void *userdata) -{ - struct thr_info *mythr = (struct thr_info *)userdata; - int thr_id = mythr->id; - struct work work; - uint32_t max_nonce; - uint32_t end_nonce = 0xffffffffU / opt_n_threads * (thr_id + 1) - 0x20; - unsigned char *scratchbuf = NULL; - char s[16]; - int i; - static int rounds = 0; - - memset(&work, 0, sizeof(work)); // prevent work from being used uninitialized - - /* Set worker threads to nice 19 and then preferentially to SCHED_IDLE - * and if that fails, then SCHED_BATCH. No need for this to be an - * error if it fails */ - if (!opt_benchmark) { - setpriority(PRIO_PROCESS, 0, 19); - drop_policy(); - } - - /* Cpu affinity only makes sense if the number of threads is a multiple - * of the number of CPUs */ - if (num_processors > 1 && opt_n_threads % num_processors == 0) { - if (!opt_quiet) - applog(LOG_INFO, "Binding thread %d to cpu %d", - thr_id, thr_id % num_processors); - affine_to_cpu(thr_id, thr_id % num_processors); - } - - applog(LOG_INFO, "GPU #%d: %s (%d SMX), using %d blocks of %d threads", - device_map[thr_id], device_name[thr_id], device_mpcount[thr_id], device_config[thr_id][0], device_config[thr_id][1]); - - if( device_config[thr_id][0] % device_mpcount[thr_id] ) - applog(LOG_INFO, "GPU #%d: Warning: block count %d is not a multiple of SMX count %d.", - device_map[thr_id], device_config[thr_id][0], device_mpcount[thr_id]); - - uint32_t *nonceptr = (uint32_t*) (((char*)work.data) + (jsonrpc_2 ? 39 : 76)); - - while (1) { - unsigned long hashes_done; - struct timeval tv_start, tv_end, diff; - int64_t max64; - int rc; - - if (have_stratum) { - while (!jsonrpc_2 && time(NULL) >= g_work_time + 120) - sleep(1); - pthread_mutex_lock(&g_work_lock); - if ((*nonceptr) >= end_nonce - && !(jsonrpc_2 ? memcmp(work.data, g_work.data, 39) || - memcmp(((uint8_t*) work.data) + 43, ((uint8_t*) g_work.data) + 43, 33) - : memcmp(work.data, g_work.data, 76))) - { - stratum_gen_work(&stratum, &g_work); - } - } else { - /* obtain new work from internal workio thread */ - pthread_mutex_lock(&g_work_lock); - if (!have_stratum && (!have_longpoll || - time(NULL) >= g_work_time + LP_SCANTIME*3/4 || - *nonceptr >= end_nonce)) { - if (unlikely(!get_work(mythr, &g_work))) { - applog(LOG_ERR, "work retrieval failed, exiting " - "mining thread %d", mythr->id); - pthread_mutex_unlock(&g_work_lock); - goto out; - } - g_work_time = have_stratum ? 0 : time(NULL); - } - if (have_stratum) { - pthread_mutex_unlock(&g_work_lock); - continue; - } - } - if (jsonrpc_2 ? memcmp(work.data, g_work.data, 39) || memcmp(((uint8_t*) work.data) + 43, ((uint8_t*) g_work.data) + 43, 33) : memcmp(work.data, g_work.data, 76)) { - memcpy(&work, &g_work, sizeof(struct work)); - nonceptr = (uint32_t*) (((char*)work.data) + (jsonrpc_2 ? 39 : 76)); - *nonceptr = 0xffffffffU / opt_n_threads * thr_id; - } else - ++(*nonceptr); - pthread_mutex_unlock(&g_work_lock); - work_restart[thr_id].restart = 0; - - /* adjust max_nonce to meet target scan time */ - if (have_stratum) - max64 = LP_SCANTIME; - else - max64 = g_work_time + (have_longpoll ? LP_SCANTIME : opt_scantime) - - time(NULL); - max64 *= (int64_t)thr_hashrates[thr_id]; - if (max64 <= 0) { - switch (opt_algo) { - - case ALGO_JACKPOT: - max64 = 0x1fffLL; break; - case ALGO_CRYPTONIGHT: - max64 = 0x200LL; break; - default: - max64 = 0xfffffLL; break; - } - } - if ((int64_t)work.data[19] + max64 > end_nonce) - max_nonce = end_nonce; - else - max_nonce = (uint32_t)(*nonceptr + max64); - - hashes_done = 0; - gettimeofday(&tv_start, NULL); - - /* scan nonces for a proof-of-work hash */ - rc = scanhash_cryptonight(thr_id, work.data, work.target, - max_nonce, &hashes_done); - -// if (opt_benchmark) -// if (++rounds == 1) exit(0); - - /* record scanhash elapsed time */ - gettimeofday(&tv_end, NULL); - timeval_subtract(&diff, &tv_end, &tv_start); - if (diff.tv_usec || diff.tv_sec) { - pthread_mutex_lock(&stats_lock); - thr_hashrates[thr_id] = - hashes_done / (diff.tv_sec + 1e-6 * diff.tv_usec); - pthread_mutex_unlock(&stats_lock); - } - if (!opt_quiet) { - - if(opt_algo == ALGO_CRYPTONIGHT) { - applog(LOG_INFO, "GPU #%d: %s, %.2f H/s", - device_map[thr_id], device_name[thr_id], thr_hashrates[thr_id]); - } - else { - sprintf(s, thr_hashrates[thr_id] >= 1e6 ? "%.0f" : "%.2f", - 1e-3 * thr_hashrates[thr_id]); - applog(LOG_INFO, "GPU #%d: %s, %s khash/s", - device_map[thr_id], device_name[thr_id], s); - } - } - if (opt_benchmark && thr_id == opt_n_threads - 1) { - double hashrate = 0.; - for (i = 0; i < opt_n_threads && thr_hashrates[i]; i++) - hashrate += thr_hashrates[i]; - if (i == opt_n_threads) { - - if(opt_algo == ALGO_CRYPTONIGHT) - applog(LOG_INFO, "Total: %.2f H/s", hashrate); - else { - sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate); - applog(LOG_INFO, "Total: %s khash/s", s); - } - } - } - - /* if nonce found, submit work */ - if (rc && !opt_benchmark && !submit_work(mythr, &work)) - break; - } - -out: - tq_freeze(mythr->q); - - return NULL; -} - -static void restart_threads(void) -{ - int i; - - for (i = 0; i < opt_n_threads; i++) - work_restart[i].restart = 1; -} - -static void *longpoll_thread(void *userdata) -{ - struct thr_info *mythr = (struct thr_info *)userdata; - CURL *curl = NULL; - char *copy_start, *hdr_path = NULL, *lp_url = NULL; - bool need_slash = false; - - curl = curl_easy_init(); - if (unlikely(!curl)) { - applog(LOG_ERR, "CURL initialization failed"); - goto out; - } - -start: - hdr_path = (char*)tq_pop(mythr->q, NULL); - if (!hdr_path) - goto out; - - /* full URL */ - if (strstr(hdr_path, "://")) { - lp_url = hdr_path; - hdr_path = NULL; - } - - /* absolute path, on current server */ - else { - copy_start = (*hdr_path == '/') ? (hdr_path + 1) : hdr_path; - if (rpc_url[strlen(rpc_url) - 1] != '/') - need_slash = true; - - lp_url = (char*)malloc(strlen(rpc_url) + strlen(copy_start) + 2); - if (!lp_url) - goto out; - - sprintf(lp_url, "%s%s%s", rpc_url, need_slash ? "/" : "", copy_start); - } - - applog(LOG_INFO, "Long-polling activated for %s", lp_url); - - while (1) { - json_t *val, *soval; - int err; - - if(jsonrpc_2) { - pthread_mutex_lock(&rpc2_login_lock); - if(!strcmp(rpc2_id, "")) { - sleep(1); - continue; - } - char s[128]; - snprintf(s, 128, "{\"method\": \"getjob\", \"params\": {\"id\": \"%s\"}, \"id\":1}\r\n", rpc2_id); - pthread_mutex_unlock(&rpc2_login_lock); - val = json_rpc2_call(curl, rpc_url, rpc_userpass, s, &err, JSON_RPC_LONGPOLL); - } else { - val = json_rpc_call(curl, lp_url, rpc_userpass, rpc_req, - false, true, &err); - } - if (have_stratum) { - if (val) - json_decref(val); - goto out; - } - if (likely(val)) { - - if (!jsonrpc_2) { - soval = json_object_get(json_object_get(val, "result"), "submitold"); - submit_old = soval ? json_is_true(soval) : false; - } - pthread_mutex_lock(&g_work_lock); - char *start_job_id = strdup(g_work.job_id); - if (work_decode(json_object_get(val, "result"), &g_work)) { - if (strcmp(start_job_id, g_work.job_id)) { - if (!opt_quiet) applog(LOG_INFO, "LONGPOLL detected new block"); - if (opt_debug) - applog(LOG_DEBUG, "DEBUG: got new work"); - time(&g_work_time); - restart_threads(); - } - } - pthread_mutex_unlock(&g_work_lock); - json_decref(val); - } else { - pthread_mutex_lock(&g_work_lock); - g_work_time -= LP_SCANTIME; - pthread_mutex_unlock(&g_work_lock); - if (err == CURLE_OPERATION_TIMEDOUT) { - restart_threads(); - } else { - have_longpoll = false; - restart_threads(); - free(hdr_path); - free(lp_url); - lp_url = NULL; - sleep(opt_fail_pause); - goto start; - } - } - } - -out: - free(hdr_path); - free(lp_url); - tq_freeze(mythr->q); - if (curl) - curl_easy_cleanup(curl); - - return NULL; -} - -static bool stratum_handle_response(char *buf) -{ - json_t *val, *err_val, *res_val, *id_val; - json_error_t err; - bool ret = false; - bool valid = false; - - val = JSON_LOADS(buf, &err); - if (!val) { - applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text); - goto out; - } - - res_val = json_object_get(val, "result"); - err_val = json_object_get(val, "error"); - id_val = json_object_get(val, "id"); - - if (!id_val || json_is_null(id_val) || !res_val) - goto out; - - if(jsonrpc_2) { - json_t *status = json_object_get(res_val, "status"); - if(status) { - const char *s = json_string_value(status); - valid = !strcmp(s, "OK") && json_is_null(err_val); - } else { - valid = json_is_null(err_val); - } - } else { - valid = json_is_true(res_val); - } - - share_result(valid, - err_val ? (jsonrpc_2 ? json_string_value(err_val) : json_string_value(json_array_get(err_val, 1))) : NULL); - - ret = true; -out: - if (val) - json_decref(val); - - return ret; -} - -static void *stratum_thread(void *userdata) -{ - struct thr_info *mythr = (struct thr_info *)userdata; - char *s; - - stratum.url = (char*)tq_pop(mythr->q, NULL); - if (!stratum.url) - goto out; - applog(LOG_INFO, "Starting Stratum on %s", stratum.url); - - while (1) { - int failures = 0; - - while (!stratum.curl) { - pthread_mutex_lock(&g_work_lock); - g_work_time = 0; - pthread_mutex_unlock(&g_work_lock); - restart_threads(); - - if (!stratum_connect(&stratum, stratum.url) || - !stratum_subscribe(&stratum) || - !stratum_authorize(&stratum, rpc_user, rpc_pass)) { - stratum_disconnect(&stratum); - if (opt_retries >= 0 && ++failures > opt_retries) { - applog(LOG_ERR, "...terminating workio thread"); - tq_push(thr_info[work_thr_id].q, NULL); - goto out; - } - applog(LOG_ERR, "...retry after %d seconds", opt_fail_pause); - sleep(opt_fail_pause); - } - } - - if (jsonrpc_2) { - if (stratum.work.job_id - && (!g_work_time - || strcmp(stratum.work.job_id, g_work.job_id))) { - pthread_mutex_lock(&g_work_lock); - stratum_gen_work(&stratum, &g_work); - time(&g_work_time); - pthread_mutex_unlock(&g_work_lock); - applog(LOG_INFO, "Stratum detected new block"); - restart_threads(); - } - } else { - if (stratum.job.job_id && - (strcmp(stratum.job.job_id, g_work.job_id) || !g_work_time)) { - pthread_mutex_lock(&g_work_lock); - stratum_gen_work(&stratum, &g_work); - time(&g_work_time); - pthread_mutex_unlock(&g_work_lock); - if (stratum.job.clean) { - if (!opt_quiet) applog(LOG_INFO, "Stratum detected new block"); - restart_threads(); - } - } - } - - if (!stratum_socket_full(&stratum, 120)) { - applog(LOG_ERR, "Stratum connection timed out"); - s = NULL; - } else - s = stratum_recv_line(&stratum); - if (!s) { - stratum_disconnect(&stratum); - applog(LOG_ERR, "Stratum connection interrupted"); - continue; - } - if (!stratum_handle_method(&stratum, s)) - stratum_handle_response(s); - free(s); - } - -out: - return NULL; -} - -static void show_version_and_exit(void) -{ - printf("%s\n%s\n", PACKAGE_STRING, curl_version()); - exit(0); -} - -static void show_usage_and_exit(int status) -{ - if (status) - fprintf(stderr, "Try `" PROGRAM_NAME " --help' for more information.\n"); - else - printf(usage); - exit(status); -} - -void parse_device_config( char *config, int *blocks, int *threads ) -{ - char *p; - int tmp_blocks, tmp_threads; - - if( config == NULL ) goto usedefault; - - - p = strtok(config, "x"); - if(!p) - goto usedefault; - - tmp_threads = atoi(p); - if( tmp_threads < 4 || tmp_threads > 1024 ) - goto usedefault; - - p = strtok(NULL, "x"); - if(!p) - goto usedefault; - - tmp_blocks = atoi(p); - if( tmp_blocks < 1 ) - goto usedefault; - - *blocks = tmp_blocks; - *threads = tmp_threads; - return; - -usedefault: - *blocks = opt_cn_blocks; - *threads = opt_cn_threads; - return; - -} - -static void parse_arg (int key, char *arg) -{ - char *p; - int v, i; - double d; - - switch(key) { - case 'a': - applog(LOG_INFO, "Ignoring algo switch, this program does only cryptonight now."); - break; - case 'B': - opt_background = true; - break; - case 'c': { - json_error_t err; - if (opt_config) - json_decref(opt_config); -#if JANSSON_VERSION_HEX >= 0x020000 - opt_config = json_load_file(arg, 0, &err); -#else - opt_config = json_load_file(arg, &err); -#endif - if (!json_is_object(opt_config)) { - applog(LOG_ERR, "JSON decode of %s failed", arg); - exit(1); - } - break; - } - case 'q': - opt_quiet = true; - break; - case 'D': - opt_debug = true; - break; - case 'p': - free(rpc_pass); - rpc_pass = strdup(arg); - break; - case 'P': - opt_protocol = true; - break; - case 'r': - v = atoi(arg); - if (v < -1 || v > 9999) /* sanity check */ - show_usage_and_exit(1); - opt_retries = v; - break; - case 'R': - v = atoi(arg); - if (v < 1 || v > 9999) /* sanity check */ - show_usage_and_exit(1); - opt_fail_pause = v; - break; - case 's': - v = atoi(arg); - if (v < 1 || v > 9999) /* sanity check */ - show_usage_and_exit(1); - opt_scantime = v; - break; - case 'T': - v = atoi(arg); - if (v < 1 || v > 99999) /* sanity check */ - show_usage_and_exit(1); - opt_timeout = v; - break; - case 't': - v = atoi(arg); - if (v < 1 || v > 9999) /* sanity check */ - show_usage_and_exit(1); - opt_n_threads = v; - break; - case 'v': - break; - case 'm': - opt_trust_pool = true; - break; - case 'u': - free(rpc_user); - rpc_user = strdup(arg); - break; - case 'o': /* --url */ - p = strstr(arg, "://"); - if (p) { - if (strncasecmp(arg, "http://", 7) - && strncasecmp(arg, "https://", 8) - && strncasecmp(arg, "stratum+tcp://", 14)) - show_usage_and_exit(1); - free(rpc_url); - rpc_url = strdup(arg); - } else { - if (!strlen(arg) || *arg == '/') - show_usage_and_exit(1); - free(rpc_url); - rpc_url = (char*)malloc(strlen(arg) + 8); - sprintf(rpc_url, "http://%s", arg); - } - p = strrchr(rpc_url, '@'); - if (p) { - char *sp, *ap; - *p = '\0'; - ap = strstr(rpc_url, "://") + 3; - sp = strchr(ap, ':'); - if (sp) { - free(rpc_userpass); - rpc_userpass = strdup(ap); - free(rpc_user); - rpc_user = (char*)calloc(sp - ap + 1, 1); - strncpy(rpc_user, ap, sp - ap); - free(rpc_pass); - rpc_pass = strdup(sp + 1); - } else { - free(rpc_user); - rpc_user = strdup(ap); - } - memmove(ap, p + 1, strlen(p + 1) + 1); - } - have_stratum = !opt_benchmark && !strncasecmp(rpc_url, "stratum", 7); - break; - case 'O': /* --userpass */ - p = strchr(arg, ':'); - if (!p) - show_usage_and_exit(1); - free(rpc_userpass); - rpc_userpass = strdup(arg); - free(rpc_user); - rpc_user = (char*)calloc(p - arg + 1, 1); - strncpy(rpc_user, arg, p - arg); - free(rpc_pass); - rpc_pass = strdup(p + 1); - break; - case 'x': /* --proxy */ - if (!strncasecmp(arg, "socks4://", 9)) - opt_proxy_type = CURLPROXY_SOCKS4; - else if (!strncasecmp(arg, "socks5://", 9)) - opt_proxy_type = CURLPROXY_SOCKS5; -#if LIBCURL_VERSION_NUM >= 0x071200 - else if (!strncasecmp(arg, "socks4a://", 10)) - opt_proxy_type = CURLPROXY_SOCKS4A; - else if (!strncasecmp(arg, "socks5h://", 10)) - opt_proxy_type = CURLPROXY_SOCKS5_HOSTNAME; -#endif - else - opt_proxy_type = CURLPROXY_HTTP; - free(opt_proxy); - opt_proxy = strdup(arg); - break; - case 1001: - free(opt_cert); - opt_cert = strdup(arg); - break; - case 1005: - opt_benchmark = true; - want_longpoll = false; - want_stratum = false; - have_stratum = false; - break; - case 1003: - want_longpoll = false; - break; - case 1007: - want_stratum = false; - break; - case 'S': - use_syslog = true; - break; - case 'd': // CB - { - char * pch = strtok (arg,","); - opt_n_threads = 0; - while (pch != NULL) { - if (pch[0] >= '0' && pch[0] <= '9' && pch[1] == '\0') - { - if (atoi(pch) < num_processors) - device_map[opt_n_threads++] = atoi(pch); - else { - applog(LOG_ERR, "Non-existant CUDA device #%d specified in -d option", atoi(pch)); - exit(1); - } - } else { - int device = cuda_finddevice(pch); - if (device >= 0 && device < num_processors) - device_map[opt_n_threads++] = device; - else { - applog(LOG_ERR, "Non-existant CUDA device '%s' specified in -d option", pch); - exit(1); - } - } - pch = strtok (NULL, ","); - } - } - break; - case 'f': // CH - Divisor for Difficulty - d = atof(arg); - if (d == 0) /* sanity check */ - show_usage_and_exit(1); - opt_difficulty = d; - break; - case 'l': /* cryptonight launch config */ - { - char *tmp_config[8]; - int tmp_blocks = opt_cn_blocks, tmp_threads = opt_cn_threads; - for( i = 0; i < 8; i++ ) tmp_config[i] = NULL; - p = strtok(arg, ","); - if( p == NULL ) show_usage_and_exit(1); - i = 0; - while( p != NULL && i < 8 ) { - tmp_config[i++] = strdup(p); - p = strtok(NULL, ","); - } - while (i < 8) { - tmp_config[i] = strdup(tmp_config[i-1]); - i++; - } - - for( i = 0; i < 8; i++ ) { - parse_device_config(tmp_config[i], &tmp_blocks, &tmp_threads); - device_config[i][0] = tmp_blocks; - device_config[i][1] = tmp_threads; - } - } - break; - case 1008: - { - p = strtok(arg, ","); - if( p == NULL ) show_usage_and_exit(1); - int last; - i = 0; - while( p != NULL && i < 8 ) { - device_bfactor[i++] = last = atoi(p); - if( last < 0 || last > 10 ) { - applog(LOG_ERR, "Valid range for --bfactor is 0-10"); - exit(1); - } - p = strtok(NULL, ","); - } - while (i < 8) { - device_bfactor[i++] = last; - } - } - break; - case 1009: - p = strtok(arg, ","); - if( p == NULL ) show_usage_and_exit(1); - int last; - i = 0; - while( p != NULL && i < 8 ) { - device_bsleep[i++] = last = atoi(p); - if( last < 0 || last > 1000000 ) { - applog(LOG_ERR, "Valid range for --bsleep is 0-1000000"); - exit(1); - } - p = strtok(NULL, ","); - } - while (i < 8) { - device_bsleep[i++] = last; - } - break; - - case 'V': - show_version_and_exit(); - case 'h': - show_usage_and_exit(0); - default: - show_usage_and_exit(1); - } -} - -static void parse_config(void) -{ - int i; - json_t *val; - - if (!json_is_object(opt_config)) - return; - - for (i = 0; i < ARRAY_SIZE(options); i++) { - if (!options[i].name) - break; - if (!strcmp(options[i].name, "config")) - continue; - - val = json_object_get(opt_config, options[i].name); - if (!val) - continue; - - if (options[i].has_arg && json_is_string(val)) { - char *s = strdup(json_string_value(val)); - if (!s) - break; - parse_arg(options[i].val, s); - free(s); - } else if (!options[i].has_arg && json_is_true(val)) - parse_arg(options[i].val, ""); - else - applog(LOG_ERR, "JSON option %s invalid", - options[i].name); - } - - if (opt_algo == ALGO_HEAVY && opt_vote == 9999) { - fprintf(stderr, "Heavycoin hash requires block reward vote parameter (see --vote)\n"); - show_usage_and_exit(1); - } -} - -static void parse_cmdline(int argc, char *argv[]) -{ - int key; - - while (1) { -#if HAVE_GETOPT_LONG - key = getopt_long(argc, argv, short_options, options, NULL); -#else - key = getopt(argc, argv, short_options); -#endif - if (key < 0) - break; - - parse_arg(key, optarg); - } - if (optind < argc) { - fprintf(stderr, "%s: unsupported non-option argument '%s'\n", - argv[0], argv[optind]); - show_usage_and_exit(1); - } - - if (opt_algo == ALGO_HEAVY && opt_vote == 9999) { - fprintf(stderr, "%s: Heavycoin hash requires block reward vote parameter (see --vote)\n", - argv[0]); - show_usage_and_exit(1); - } - - parse_config(); -} - -#ifndef WIN32 -static void signal_handler(int sig) -{ - switch (sig) { - case SIGHUP: - applog(LOG_INFO, "SIGHUP received"); - break; - case SIGINT: - applog(LOG_INFO, "SIGINT received, exiting"); - exit(0); - break; - case SIGTERM: - applog(LOG_INFO, "SIGTERM received, exiting"); - exit(0); - break; - } -} -#endif - -#define PROGRAM_VERSION "0.13" -int main(int argc, char *argv[]) -{ - struct thr_info *thr; - long flags; - int i; - -#ifdef WIN32 - SYSTEM_INFO sysinfo; -#endif - - printf(" *** ccminer-cryptonight for nVidia GPUs by tsiv ***\n"); - printf(" based on ccMiner by Christian Buchner and Christian H.\n"); - printf(" based on cpuminer-multi by LucasJones\n"); - printf(" based on pooler-cpuminer 2.3.2 (c) 2010 Jeff Garzik, 2012 pooler\n"); - printf(" BTC donation address: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs\n"); - printf(" DRK donation address: XrHp267JNTVdw5P3dsBpqYfgTpWnzoESPQ\n"); - printf(" JPC donation address: Jb9hFeBgakCXvM5u27rTZoYR9j13JGmuc2\n"); - printf(" VTC donation address: VwYsZFPb6KMeWuP4voiS9H1kqxcU9kGbsw\n"); - printf(" XMR donation address: \n"); - printf(" (man these are long... single address, split on two lines)\n"); - printf(" 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohD\n"); - printf(" QLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX\n"); - printf("-----------------------------------------------------------------\n"); - - rpc_user = strdup(""); - rpc_pass = strdup(""); - - pthread_mutex_init(&applog_lock, NULL); - num_processors = cuda_num_devices(); - - for(i = 0; i < 8; i++) { - device_config[i][0] = opt_cn_blocks; - device_config[i][1] = opt_cn_threads; - device_bfactor[i] = default_bfactor; - device_bsleep[i] = default_bsleep; - } - - /* parse command line */ - parse_cmdline(argc, argv); - - cuda_deviceinfo(); - - if(opt_algo == ALGO_CRYPTONIGHT) { - jsonrpc_2 = true; - applog(LOG_INFO, "Using JSON-RPC 2.0"); - } - - if (!opt_benchmark && !rpc_url) { - fprintf(stderr, "%s: no URL supplied\n", argv[0]); - show_usage_and_exit(1); - } - - if (!rpc_userpass) { - rpc_userpass = (char*)malloc(strlen(rpc_user) + strlen(rpc_pass) + 2); - if (!rpc_userpass) - return 1; - sprintf(rpc_userpass, "%s:%s", rpc_user, rpc_pass); - } - - pthread_mutex_init(&stats_lock, NULL); - pthread_mutex_init(&g_work_lock, NULL); - pthread_mutex_init(&rpc2_job_lock, NULL); - pthread_mutex_init(&stratum.sock_lock, NULL); - pthread_mutex_init(&stratum.work_lock, NULL); - - flags = !opt_benchmark && strncmp(rpc_url, "https:", 6) - ? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL) - : CURL_GLOBAL_ALL; - if (curl_global_init(flags)) { - applog(LOG_ERR, "CURL initialization failed"); - return 1; - } - -#ifndef WIN32 - if (opt_background) { - i = fork(); - if (i < 0) exit(1); - if (i > 0) exit(0); - i = setsid(); - if (i < 0) - applog(LOG_ERR, "setsid() failed (errno = %d)", errno); - i = chdir("/"); - if (i < 0) - applog(LOG_ERR, "chdir() failed (errno = %d)", errno); - signal(SIGHUP, signal_handler); - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); - } -#endif - - if (num_processors == 0) - { - applog(LOG_ERR, "No CUDA devices found! terminating."); - exit(1); - } - if (!opt_n_threads) - opt_n_threads = num_processors; - -#ifdef HAVE_SYSLOG_H - if (use_syslog) - openlog("cpuminer", LOG_PID, LOG_USER); -#endif - - work_restart = (struct work_restart *)calloc(opt_n_threads, sizeof(*work_restart)); - if (!work_restart) - return 1; - - thr_info = (struct thr_info *)calloc(opt_n_threads + 3, sizeof(*thr)); - if (!thr_info) - return 1; - - thr_hashrates = (double *) calloc(opt_n_threads, sizeof(double)); - if (!thr_hashrates) - return 1; - - /* init workio thread info */ - work_thr_id = opt_n_threads; - thr = &thr_info[work_thr_id]; - thr->id = work_thr_id; - thr->q = tq_new(); - if (!thr->q) - return 1; - - /* start work I/O thread */ - if (pthread_create(&thr->pth, NULL, workio_thread, thr)) { - applog(LOG_ERR, "workio thread create failed"); - return 1; - } - - if (want_longpoll && !have_stratum) { - /* init longpoll thread info */ - longpoll_thr_id = opt_n_threads + 1; - thr = &thr_info[longpoll_thr_id]; - thr->id = longpoll_thr_id; - thr->q = tq_new(); - if (!thr->q) - return 1; - - /* start longpoll thread */ - if (unlikely(pthread_create(&thr->pth, NULL, longpoll_thread, thr))) { - applog(LOG_ERR, "longpoll thread create failed"); - return 1; - } - } - if (want_stratum) { - /* init stratum thread info */ - stratum_thr_id = opt_n_threads + 2; - thr = &thr_info[stratum_thr_id]; - thr->id = stratum_thr_id; - thr->q = tq_new(); - if (!thr->q) - return 1; - - /* start stratum thread */ - if (unlikely(pthread_create(&thr->pth, NULL, stratum_thread, thr))) { - applog(LOG_ERR, "stratum thread create failed"); - return 1; - } - - if (have_stratum) - tq_push(thr_info[stratum_thr_id].q, strdup(rpc_url)); - } - - /* start mining threads */ - for (i = 0; i < opt_n_threads; i++) { - thr = &thr_info[i]; - - thr->id = i; - thr->q = tq_new(); - if (!thr->q) - return 1; - - if (unlikely(pthread_create(&thr->pth, NULL, miner_thread, thr))) { - applog(LOG_ERR, "thread %d create failed", i); - return 1; - } - } - - applog(LOG_INFO, "%d miner threads started, " - "using '%s' algorithm.", - opt_n_threads, - algo_names[opt_algo]); - -#ifdef WIN32 - timeBeginPeriod(1); // enable high timer precision (similar to Google Chrome Trick) -#endif - - /* main loop - simply wait for workio thread to exit */ - pthread_join(thr_info[work_thr_id].pth, NULL); - -#ifdef WIN32 - timeEndPeriod(1); // be nice and forego high timer precision -#endif - - applog(LOG_INFO, "workio thread dead, exiting."); - - return 0; -} - diff --git a/cpu-miner.cpp b/cpu-miner.cpp new file mode 100644 index 0000000..4c23de1 --- /dev/null +++ b/cpu-miner.cpp @@ -0,0 +1,2205 @@ +/* +* Copyright 2010 Jeff Garzik +* Copyright 2012-2014 pooler +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. See COPYING for more details. +*/ +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else +#include "cpuminer-config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#ifdef WIN32 +#include +#else +#include +#include +#include +#if HAVE_SYS_SYSCTL_H +#include +#if HAVE_SYS_PARAM_H +#include +#endif +#include +#endif +#endif +#include +#include +#include +#include +#include "compat.h" +#include "cryptonight.h" + +#define PROGRAM_NAME "ccminer-cryptonight" +#define LP_SCANTIME 60 + +int cuda_num_devices(); +void cuda_deviceinfo(int); +void cuda_set_device_config(int); +int cuda_finddevice(char *name); + +extern int cryptonight_hash(void* output, const void* input, size_t len, int variant, algo_t opt_algo); +void parse_device_config(int device, char *config, int *blocks, int *threads); + +#ifdef __linux /* Linux specific policy and affinity management */ +#include +static inline void drop_policy(void) +{ + struct sched_param param; + param.sched_priority = 0; + +#ifdef SCHED_IDLE + if(unlikely(sched_setscheduler(0, SCHED_IDLE, ¶m) == -1)) +#endif +#ifdef SCHED_BATCH + sched_setscheduler(0, SCHED_BATCH, ¶m); +#endif +} + +static inline void affine_to_cpu(int id, int cpu) +{ + cpu_set_t set; + + CPU_ZERO(&set); + CPU_SET(cpu, &set); + sched_setaffinity(0, sizeof(&set), &set); +} +#elif defined(__FreeBSD__) /* FreeBSD specific policy and affinity management */ +#include +static inline void drop_policy(void) +{} + +static inline void affine_to_cpu(int id, int cpu) +{ + cpuset_t set; + CPU_ZERO(&set); + CPU_SET(cpu, &set); + cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &set); +} +#else +static inline void drop_policy(void) +{} + +static inline void affine_to_cpu(int id, int cpu) +{} +#endif + +enum workio_commands +{ + WC_GET_WORK, + WC_SUBMIT_WORK, +}; + +struct workio_cmd +{ + enum workio_commands cmd; + struct thr_info *thr; + union + { + struct work *work; + } u; +}; + +bool stop_mining = false; +volatile bool mining_has_stopped[8] = {false}; +bool opt_colors = false; +#ifdef WIN32 +HANDLE handl; +#endif + +extern uint64_t MEMORY; +extern uint32_t ITER; + +algo_t opt_algo = algo_monero; +int forkversion = 7; +bool opt_debug = false; +bool opt_protocol = false; +bool opt_keepalive = false; +bool opt_benchmark = false; +bool want_longpoll = true; +bool have_longpoll = false; +bool want_stratum = true; +bool have_stratum = false; +static bool submit_old = false; +bool use_syslog = false; +static bool opt_background = false; +static bool opt_quiet = false; +static int opt_retries = -1; +static int opt_fail_pause = 30; +int opt_timeout = 270; +static int opt_scantime = 5; +static json_t *opt_config; +static const bool opt_time = true; +static int opt_n_threads = 0; +static double opt_difficulty = 1; // CH +static int num_processors; +int device_map[MAX_GPU]; // CB +char *device_name[MAX_GPU]; // CB +int device_arch[MAX_GPU][2]; +int device_mpcount[MAX_GPU]; +int device_bfactor[MAX_GPU]; +int device_bsleep[MAX_GPU]; +int device_config[MAX_GPU][2]; +#ifdef WIN32 +static int default_bfactor = 6; +static int default_bsleep = 100; +#else +static int default_bfactor = 0; +static int default_bsleep = 0; +#endif +static char *rpc_url; +static char *rpc_userpass; +static char *rpc_user, *rpc_pass; +char *opt_cert; +char *opt_proxy; +long opt_proxy_type; +struct thr_info *thr_info; +static int work_thr_id; +int longpoll_thr_id = -1; +int stratum_thr_id = -1; +struct work_restart *work_restart = NULL; +static struct stratum_ctx stratum; +int opt_cn_threads = 8; +int opt_cn_blocks = 0; + +static char rpc2_id[64] = ""; +static char *rpc2_blob = NULL; +static int rpc2_bloblen = 0; +static uint32_t rpc2_target = 0; +static char *rpc2_job_id = NULL; +static pthread_mutex_t rpc2_job_lock; +static pthread_mutex_t rpc2_login_lock; + +pthread_mutex_t applog_lock; +static pthread_mutex_t stats_lock; + +static unsigned long accepted_count = 0L; +static unsigned long rejected_count = 0L; +static double *thr_hashrates; +static uint64_t *thr_totalhashes; +static struct timeval stats_start; + + +#ifdef HAVE_GETOPT_LONG +#include +#else +struct option +{ + const char *name; + int has_arg; + int *flag; + int val; +}; +#endif + +const char *algo_names[] = +{ + "cryptonight", + "monero", + "graft", + "stellite", + "intense", + "electroneum", + "sumokoin" +}; + +static char const usage[] = "\ +Usage: " PROGRAM_NAME " [OPTIONS]\n\ + Options:\n\ + -a --algo choose between the supported algos:\n\ + cryptonight\n\ + monero\n\ + electroneum\n\ + graft\n\ + stellite\n\ + intense\n\ + sumokoin\n\ + -d, --devices takes a comma separated list of CUDA devices to use.\n\ + Device IDs start counting from 0! Alternatively takes\n\ + string names of your cards like gtx780ti or gt640#2\n\ + (matching 2nd gt640 in the PC)\n\ + -f, --diff Divide difficulty by this factor (std is 1) \n\ + -l, --launch=CONFIG launch config for the Cryptonight kernel.\n\ + a comma separated list of values in form of\n\ + AxB where A is the number of threads to run in\n\ + each thread block and B is the number of thread\n\ + blocks to launch. If less values than devices in use\n\ + are provided, the last value will be used for\n\ + the remaining devices. If you don't need to vary the\n\ + value between devices, you can just enter a single value\n\ + and it will be used for all devices. (default: 8x40)\n\ + --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ + The kernel will be run in 2^X parts according to bfactor,\n\ + with a small pause between parts, specified by --bsleep.\n\ + This is a per-device setting like the launch config.\n\ + (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ + --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ + Use in combination with --bfactor to mitigate the lag\n\ + when running on your primary GPU.\n\ + This is a per-device setting like the launch config.\n\ + -o, --url=URL URL of mining server\n\ + -O, --userpass=U:P username:password pair for mining server\n\ + -u, --user=USERNAME username for mining server\n\ + -p, --pass=PASSWORD password for mining server\n\ + --cert=FILE certificate for mining server using SSL\n\ + -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy\n\ + -k, --keepalive send keepalive requests to avoid a stratum timeout\n\ + -t, --threads=N number of miner threads (default: number of nVidia GPUs)\n\ + -r, --retries=N number of times to retry if a network call fails\n\ + (default: retry indefinitely)\n\ + -R, --retry-pause=N time to pause between retries, in seconds (default: 30)\n\ + --timeout=N network timeout, in seconds (default: 270)\n\ + -s, --scantime=N upper bound on time spent scanning current work when\n\ + long polling is unavailable, in seconds (default: 5)\n\ + --no-longpoll disable X-Long-Polling support\n\ + --no-stratum disable X-Stratum support\n\ + -q, --quiet disable per-thread hashmeter output\n\ + -D, --debug enable debug output\n\ + --color enable output with colors\n\ + -P, --protocol-dump verbose dump of protocol-level activities\n" +#ifdef HAVE_SYSLOG_H +"\ + -S, --syslog use system log for output messages\n" +#endif +#ifndef WIN32 +"\ + -B, --background run the miner in the background\n" +#endif +"\ + --benchmark run in offline benchmark mode\n\ + -c, --config=FILE load a JSON-format configuration file\n\ + -V, --version display version information and exit\n\ + -h, --help display this help text and exit\n\ +"; + +static char const short_options[] = +#ifdef HAVE_SYSLOG_H +"S" +#endif +"a:Bc:Dhp:Px:kqr:R:s:t:T:o:u:O:Vd:f:l:"; + +static struct option const options[] = { + {"algo", 1, NULL, 'a' }, + {"background", 0, NULL, 'B'}, + {"benchmark", 0, NULL, 1005}, + {"cert", 1, NULL, 1001}, + {"config", 1, NULL, 'c'}, + {"debug", 0, NULL, 'D'}, + {"help", 0, NULL, 'h'}, + {"keepalive", 0, NULL, 'k'}, + {"no-longpoll", 0, NULL, 1003}, + {"no-stratum", 0, NULL, 1007}, + {"pass", 1, NULL, 'p'}, + {"protocol-dump", 0, NULL, 'P'}, + {"proxy", 1, NULL, 'x'}, + {"quiet", 0, NULL, 'q'}, + {"retries", 1, NULL, 'r'}, + {"retry-pause", 1, NULL, 'R'}, + {"scantime", 1, NULL, 's'}, +#ifdef HAVE_SYSLOG_H + {"syslog", 0, NULL, 'S'}, +#endif + {"threads", 1, NULL, 't'}, + {"timeout", 1, NULL, 'T'}, + {"url", 1, NULL, 'o'}, + {"user", 1, NULL, 'u'}, + {"userpass", 1, NULL, 'O'}, + {"version", 0, NULL, 'V'}, + {"devices", 1, NULL, 'd'}, + {"diff", 1, NULL, 'f'}, + {"launch", 1, NULL, 'l'}, + {"launch-config", 1, NULL, 'l'}, + {"bfactor", 1, NULL, 1008}, + {"bsleep", 1, NULL, 1009}, + {"color", 0, NULL, 1010}, + {0, 0, 0, 0} +}; + +static struct work g_work; +static time_t g_work_time; +static pthread_mutex_t g_work_lock; + +static bool rpc2_login(CURL *curl); + +void cuda_devicereset(int threads) +{ + for(int i = 0; i < threads; i++) + { + cudaError_t err; + err = cudaSetDevice(device_map[i]); + if(err == cudaSuccess) + { + cudaDeviceSynchronize(); + cudaDeviceReset(); + } + else + applog(LOG_WARNING, "can't reset GPU #%d", device_map[i]); + } +} + +void proper_exit(int exitcode) +{ + pthread_mutex_lock(&g_work_lock); //freeze stratum + stop_mining = true; + applog(LOG_INFO, "stopping %d threads", opt_n_threads); + bool everything_stopped; + do + { + everything_stopped = true; + for(int i = 0; i < opt_n_threads; i++) + { + if(!mining_has_stopped[i]) + everything_stopped = false; + } + } while(!everything_stopped); + applog(LOG_INFO, "resetting GPUs"); + cuda_devicereset(opt_n_threads); + + curl_global_cleanup(); + +#ifdef WIN32 + timeEndPeriod(1); // else never executed +#endif + exit(exitcode); +} + +json_t *json_rpc2_call_recur(CURL *curl, const char *url, + const char *userpass, json_t *rpc_req, + int *curl_err, int flags, int recur) +{ + if(recur >= 5) + { + if(opt_debug) + applog(LOG_DEBUG, "Failed to call rpc command after %i tries", recur); + return NULL; + } + if(!strcmp(rpc2_id, "")) + { + if(opt_debug) + applog(LOG_DEBUG, "Tried to call rpc2 command before authentication"); + return NULL; + } + json_t *params = json_object_get(rpc_req, "params"); + if(params) + { + json_t *auth_id = json_object_get(params, "id"); + if(auth_id) + { + json_string_set(auth_id, rpc2_id); + } + } + json_t *res = json_rpc_call(curl, url, userpass, json_dumps(rpc_req, 0), false, false, + curl_err); + if(!res) + return res; + json_t *error = json_object_get(res, "error"); + if(!error) + return res; + json_t *message; + if(json_is_string(error)) + message = error; + else + message = json_object_get(error, "message"); + if(!message || !json_is_string(message)) + return res; + const char *mes = json_string_value(message); + if(!strcmp(mes, "Unauthenticated")) + { + pthread_mutex_lock(&rpc2_login_lock); + rpc2_login(curl); + sleep(1); + pthread_mutex_unlock(&rpc2_login_lock); + return json_rpc2_call_recur(curl, url, userpass, rpc_req, + curl_err, flags, recur + 1); + } + else if(!strcmp(mes, "Low difficulty share") || !strcmp(mes, "Block expired") || !strcmp(mes, "Invalid job id") || !strcmp(mes, "Duplicate share")) + { + json_t *result = json_object_get(res, "result"); + if(!result) + { + return res; + } + json_object_set(result, "reject-reason", json_string(mes)); + } + else + { + applog(LOG_ERR, "json_rpc2.0 error: %s", mes); + return NULL; + } + return res; +} + +json_t *json_rpc2_call(CURL *curl, const char *url, + const char *userpass, const char *rpc_req, + int *curl_err, int flags) +{ + return json_rpc2_call_recur(curl, url, userpass, JSON_LOADS(rpc_req, NULL), + curl_err, flags, 0); +} + +static bool jobj_binary(const json_t *obj, const char *key, + void *buf, size_t buflen) +{ + const char *hexstr; + json_t *tmp; + + tmp = json_object_get(obj, key); + if(unlikely(!tmp)) + { + applog(LOG_ERR, "JSON key '%s' not found", key); + return false; + } + hexstr = json_string_value(tmp); + if(unlikely(!hexstr)) + { + applog(LOG_ERR, "JSON key '%s' is not a string", key); + return false; + } + if(!hex2bin((unsigned char*)buf, hexstr, buflen)) + return false; + + return true; +} + +bool rpc2_job_decode(const json_t *job, struct work *work) +{ + json_t *tmp; + tmp = json_object_get(job, "job_id"); + if(!tmp) + { + applog(LOG_ERR, "JSON inval job id"); + return false; + } + const char *job_id = json_string_value(tmp); + tmp = json_object_get(job, "blob"); + if(!tmp) + { + applog(LOG_ERR, "JSON inval blob"); + return false; + } + const char *hexblob = json_string_value(tmp); + int blobLen = (int)strlen(hexblob); + if(blobLen % 2 != 0 || ((blobLen / 2) < 40 && blobLen != 0) || (blobLen / 2) > 128) + { + applog(LOG_ERR, "JSON invalid blob length"); + return false; + } + if(blobLen != 0) + { + pthread_mutex_lock(&rpc2_job_lock); + char *blob = (char *)malloc(blobLen / 2); + if (blob == NULL) + { + applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); + proper_exit(1); + } + if(!hex2bin((unsigned char *)blob, hexblob, blobLen / 2)) + { + applog(LOG_ERR, "JSON inval blob"); + pthread_mutex_unlock(&rpc2_job_lock); + return false; + } + if(rpc2_blob) + { + free(rpc2_blob); + } + rpc2_bloblen = blobLen / 2; + rpc2_blob = (char *)malloc(rpc2_bloblen); + if (rpc2_blob == NULL) + { + applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); + proper_exit(1); + } + memcpy(rpc2_blob, blob, blobLen / 2); + + free(blob); + + uint32_t target; + jobj_binary(job, "target", &target, 4); + if(rpc2_target != target) + { + double hashrate = 0.; + pthread_mutex_lock(&stats_lock); + for(int i = 0; i < opt_n_threads; i++) + hashrate += thr_hashrates[i]; + pthread_mutex_unlock(&stats_lock); + double difficulty = (((double)0xffffffff) / target); + applog(LOG_INFO, "Pool set diff to %g", difficulty); + rpc2_target = target; + } + + if(rpc2_job_id) + { + free(rpc2_job_id); + } + rpc2_job_id = strdup(job_id); + pthread_mutex_unlock(&rpc2_job_lock); + } + if(work) + { + if(!rpc2_blob) + { + applog(LOG_ERR, "Requested work before work was received"); + return false; + } + memcpy(work->data, rpc2_blob, rpc2_bloblen); + memset(work->target, 0xff, sizeof(work->target)); + work->target[7] = rpc2_target; + strncpy(work->job_id, rpc2_job_id, 128); + } + return true; +} + +static bool work_decode(const json_t *val, struct work *work) +{ + return rpc2_job_decode(val, work); +} + +bool rpc2_login_decode(const json_t *val) +{ + const char *id; + const char *s; + + json_t *res = json_object_get(val, "result"); + if(!res) + { + applog(LOG_ERR, "JSON invalid result"); + return false; + } + + json_t *tmp; + tmp = json_object_get(res, "id"); + if(!tmp) + { + applog(LOG_ERR, "JSON inval id"); + return false; + } + id = json_string_value(tmp); + if(!id) + { + applog(LOG_ERR, "JSON id is not a string"); + return false; + } + + memcpy(&rpc2_id, id, 64); + + if(opt_debug) + applog(LOG_DEBUG, "Auth id: %s", id); + + tmp = json_object_get(res, "status"); + if(!tmp) + { + applog(LOG_ERR, "JSON inval status"); + return false; + } + s = json_string_value(tmp); + if(!s) + { + applog(LOG_ERR, "JSON status is not a string"); + return false; + } + if(strcmp(s, "OK")) + { + applog(LOG_ERR, "JSON returned status \"%s\"", s); + return false; + } + + return true; +} + +static void share_result(int result, const char *reason) +{ + extern char *CL_GRN; + extern char *CL_RED; + extern char *CL_N; + double hashrate; + int i; + + hashrate = 0.; + pthread_mutex_lock(&stats_lock); + for(i = 0; i < opt_n_threads; i++) + hashrate += thr_hashrates[i]; + result ? accepted_count++ : rejected_count++; + pthread_mutex_unlock(&stats_lock); + + if(result) + applog(LOG_INFO, "accepted: %lu/%lu (%.2f%%), %.2f H/s %s%s%s", + accepted_count, accepted_count + rejected_count, + 100. * accepted_count / (accepted_count + rejected_count), hashrate, + CL_GRN, "(yay!!!)", CL_N); + else + applog(LOG_INFO, "accepted: %lu/%lu (%.2f%%), %.2f H/s %s%s%s", + accepted_count, accepted_count + rejected_count, + 100. * accepted_count / (accepted_count + rejected_count), hashrate, + CL_RED, "(booooo)", CL_N); + + if(reason) + applog(LOG_WARNING, "reject reason: %s", reason); +} + +static bool submit_upstream_work(CURL *curl, struct work *work) +{ + char *str = NULL; + json_t *val, *res, *reason; + char s[345]; + bool rc = false; + + /* pass if the previous hash is not the current previous hash */ + if(memcmp(work->data + 1, g_work.data + 1, 32)) + { + if(opt_debug) + applog(LOG_DEBUG, "DEBUG: stale work detected, discarding"); + return true; + } + int variant = 0; + if(have_stratum) + { + char *noncestr; + + noncestr = bin2hex(((const unsigned char*)work->data) + 39, 4); + if(opt_algo != algo_old) + variant = ((unsigned char*)work->data)[0] >= forkversion ? ((unsigned char*)work->data)[0] - forkversion + 1 : 0; + char hash[32]; + if (!cryptonight_hash((void *)hash, (const void *)work->data, 76, variant, opt_algo)) { + applog(LOG_ERR, "submit_upstream_work cryptonight_hash failed"); + free(str); + return rc; + } + char *hashhex = bin2hex((const unsigned char *)hash, 32); + snprintf(s, sizeof(s), + "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":1}", + rpc2_id, work->job_id, noncestr, hashhex); + free(hashhex); + free(noncestr); + + if(unlikely(!stratum_send_line(&stratum, s))) + { + applog(LOG_ERR, "submit_upstream_work stratum_send_line failed"); + free(str); + return rc; + } + } + else + { + /* build JSON-RPC request */ + char *noncestr = bin2hex(((const unsigned char*)work->data) + 39, 4); + if (opt_algo != algo_old) + variant = ((unsigned char*)work->data)[0] >= forkversion ? ((unsigned char*)work->data)[0] - forkversion + 1 : 0; + char hash[32]; + if (!cryptonight_hash((void *)hash, (const void *)work->data, 76, variant, opt_algo)) { + applog(LOG_ERR, "submit_upstream_work cryptonight_hash failed"); + free(str); + return rc; + } + char *hashhex = bin2hex((const unsigned char *)hash, 32); + snprintf(s, sizeof(s), + "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":1}", + rpc2_id, work->job_id, noncestr, hashhex); + free(noncestr); + free(hashhex); + + /* issue JSON-RPC request */ + val = json_rpc2_call(curl, rpc_url, rpc_userpass, s, NULL, 0); + if(unlikely(!val)) + { + applog(LOG_ERR, "submit_upstream_work json_rpc_call failed"); + free(str); + return rc; + } + res = json_object_get(val, "result"); + json_t *status = json_object_get(res, "status"); + reason = json_object_get(res, "reject-reason"); + share_result(!strcmp(status ? json_string_value(status) : "", "OK"), + reason ? json_string_value(reason) : NULL); + + json_decref(val); + } + + rc = true; + free(str); + return rc; +} + +static const char *rpc_req = +"{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n"; + +static bool get_upstream_work(CURL *curl, struct work *work) +{ + json_t *val; + bool rc; + struct timeval tv_start, tv_end, diff; + + gettimeofday(&tv_start, NULL); + + char s[128]; + snprintf(s, 128, "{\"method\": \"getjob\", \"params\": {\"id\": \"%s\"}, \"id\":1}\r\n", rpc2_id); + val = json_rpc2_call(curl, rpc_url, rpc_userpass, s, NULL, 0); + + gettimeofday(&tv_end, NULL); + + if(have_stratum) + { + if(val) + json_decref(val); + return true; + } + + if(!val) + return false; + + rc = work_decode(json_object_get(val, "result"), work); + + if(opt_debug && rc) + { + timeval_subtract(&diff, &tv_end, &tv_start); + applog(LOG_DEBUG, "DEBUG: got new work in %d ms", + diff.tv_sec * 1000 + diff.tv_usec / 1000); + } + + json_decref(val); + + return rc; +} + +static bool rpc2_login(CURL *curl) +{ + json_t *val; + bool rc; + struct timeval tv_start, tv_end, diff; + char s[345]; + + snprintf(s, sizeof(s), "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"" USER_AGENT "\"}, \"id\": 1}", rpc_user, rpc_pass); + + gettimeofday(&tv_start, NULL); + val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL); + gettimeofday(&tv_end, NULL); + + if(!val) + return false; + + // applog(LOG_DEBUG, "JSON value: %s", json_dumps(val, 0)); + + rc = rpc2_login_decode(val); + + json_t *result = json_object_get(val, "result"); + + if(!result) return rc; + + json_t *job = json_object_get(result, "job"); + + if(!rpc2_job_decode(job, &g_work)) + { + return rc; + } + + if(opt_debug && rc) + { + timeval_subtract(&diff, &tv_end, &tv_start); + applog(LOG_DEBUG, "DEBUG: authenticated in %d ms", + diff.tv_sec * 1000 + diff.tv_usec / 1000); + } + + json_decref(val); + + return rc; +} + +static void workio_cmd_free(struct workio_cmd *wc) +{ + if(!wc) + return; + + switch(wc->cmd) + { + case WC_SUBMIT_WORK: + free(wc->u.work); + break; + default: /* do nothing */ + break; + } + + memset(wc, 0, sizeof(*wc)); /* poison */ + free(wc); +} + +static bool workio_get_work(struct workio_cmd *wc, CURL *curl) +{ + struct work *ret_work; + int failures = 0; + + ret_work = (struct work*)calloc(1, sizeof(*ret_work)); + if(!ret_work) + return false; + + /* obtain new work from bitcoin via JSON-RPC */ + while(!get_upstream_work(curl, ret_work)) + { + if(unlikely((opt_retries >= 0) && (++failures > opt_retries))) + { + applog(LOG_ERR, "json_rpc_call failed, terminating workio thread"); + free(ret_work); + return false; + } + + /* pause, then restart work-request loop */ + applog(LOG_ERR, "json_rpc_call failed, retry after %d seconds", + opt_fail_pause); + sleep(opt_fail_pause); + } + + /* send work to requesting thread */ + if(!tq_push(wc->thr->q, ret_work)) + free(ret_work); + + return true; +} + +static bool workio_submit_work(struct workio_cmd *wc, CURL *curl) +{ + int failures = 0; + + /* submit solution to bitcoin via JSON-RPC */ + while(!submit_upstream_work(curl, wc->u.work)) + { + if(unlikely((opt_retries >= 0) && (++failures > opt_retries))) + { + applog(LOG_ERR, "...terminating workio thread"); + return false; + } + + /* pause, then restart work-request loop */ + applog(LOG_ERR, "...retry after %d seconds", + opt_fail_pause); + sleep(opt_fail_pause); + } + + return true; +} + +static bool workio_login(CURL *curl) +{ + int failures = 0; + + /* submit solution to bitcoin via JSON-RPC */ + pthread_mutex_lock(&rpc2_login_lock); + while(!rpc2_login(curl)) + { + if(unlikely((opt_retries >= 0) && (++failures > opt_retries))) + { + applog(LOG_ERR, "...terminating workio thread"); + pthread_mutex_unlock(&rpc2_login_lock); + return false; + } + + /* pause, then restart work-request loop */ + applog(LOG_ERR, "...retry after %d seconds", opt_fail_pause); + sleep(opt_fail_pause); + pthread_mutex_unlock(&rpc2_login_lock); + pthread_mutex_lock(&rpc2_login_lock); + } + pthread_mutex_unlock(&rpc2_login_lock); + + return true; +} + +static void *workio_thread(void *userdata) +{ + struct thr_info *mythr = (struct thr_info*)userdata; + CURL *curl; + bool ok = true; + + curl = curl_easy_init(); + if(unlikely(!curl)) + { + applog(LOG_ERR, "CURL initialization failed"); + return NULL; + } + + if(!have_stratum && !opt_benchmark) + { + ok = workio_login(curl); + } + + while(ok) + { + struct workio_cmd *wc; + + /* wait for workio_cmd sent to us, on our queue */ + wc = (struct workio_cmd *)tq_pop(mythr->q, NULL); + if(!wc) + { + ok = false; + break; + } + + /* process workio_cmd */ + switch(wc->cmd) + { + case WC_GET_WORK: + ok = workio_get_work(wc, curl); + break; + case WC_SUBMIT_WORK: + ok = workio_submit_work(wc, curl); + break; + + default: /* should never happen */ + ok = false; + break; + } + + workio_cmd_free(wc); + } + + tq_freeze(mythr->q); + curl_easy_cleanup(curl); + + return NULL; +} + +static bool get_work(struct thr_info *thr, struct work *work) +{ + struct workio_cmd *wc; + struct work *work_heap; + + /* fill out work request message */ + wc = (struct workio_cmd *)calloc(1, sizeof(*wc)); + if(!wc) + return false; + + wc->cmd = WC_GET_WORK; + wc->thr = thr; + + /* send work request to workio thread */ + if(!tq_push(thr_info[work_thr_id].q, wc)) + { + workio_cmd_free(wc); + return false; + } + + /* wait for response, a unit of work */ + work_heap = (struct work *)tq_pop(thr->q, NULL); + if(!work_heap) + return false; + + /* copy returned work into storage provided by caller */ + memcpy(work, work_heap, sizeof(*work)); + free(work_heap); + + return true; +} + +static bool submit_work(struct thr_info *thr, const struct work *work_in) +{ + struct workio_cmd *wc; + /* fill out work request message */ + wc = (struct workio_cmd *)calloc(1, sizeof(*wc)); + if(!wc) + return false; + + wc->u.work = (struct work *)malloc(sizeof(*work_in)); + if(wc->u.work == NULL) + { + applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); + proper_exit(1); + } + if(!wc->u.work) { + workio_cmd_free(wc); + return false; + } + + wc->cmd = WC_SUBMIT_WORK; + wc->thr = thr; + memcpy(wc->u.work, work_in, sizeof(*work_in)); + + /* send solution to workio thread */ + if(!tq_push(thr_info[work_thr_id].q, wc)) { + workio_cmd_free(wc); + return false; + } + + return true; +} + +static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work) +{ + pthread_mutex_lock(&sctx->work_lock); + + memcpy(work, &sctx->work, sizeof(struct work)); + if(sctx->job.job_id) strncpy(work->job_id, sctx->job.job_id, 128); + pthread_mutex_unlock(&sctx->work_lock); +} + +static void *miner_thread(void *userdata) +{ + struct thr_info *mythr = (struct thr_info *)userdata; + int thr_id = mythr->id; + struct work work; + uint32_t max_nonce; + uint32_t end_nonce; + + unsigned char *scratchbuf = NULL; + int i; + static int rounds = 0; + end_nonce = 0x01000000U / opt_n_threads * (thr_id + 1) - 1; + memset(&work, 0, sizeof(work)); // prevent work from being used uninitialized + + /* Set worker threads to nice 19 and then preferentially to SCHED_IDLE + * and if that fails, then SCHED_BATCH. No need for this to be an + * error if it fails */ + if(!opt_benchmark) + { + setpriority(PRIO_PROCESS, 0, 19); + drop_policy(); + } + + /* Cpu affinity only makes sense if the number of threads is a multiple + * of the number of CPUs */ + if(num_processors > 1 && opt_n_threads % num_processors == 0) + { + if(opt_debug) + applog(LOG_INFO, "Binding thread %d to cpu %d", + thr_id, thr_id % num_processors); + affine_to_cpu(thr_id, thr_id % num_processors); + } + + applog(LOG_INFO, "GPU #%d: %s (%d SMX), using launch config %dx%d", + device_map[thr_id], device_name[thr_id], device_mpcount[thr_id], device_config[thr_id][1], device_config[thr_id][0]); + + if(device_config[thr_id][0] % device_mpcount[thr_id]) + applog(LOG_WARNING, "GPU #%d: Warning: block count %d is not a multiple of SMX count %d.", + device_map[thr_id], device_config[thr_id][0], device_mpcount[thr_id]); + + uint32_t *const nonceptr = (uint32_t*)(((char*)work.data) + 39); + + thr_totalhashes[thr_id] = 0; + + while(1) + { + unsigned long hashes_done; + struct timeval tv_start, tv_end, diff; + double difftime; + int64_t max64; + int rc; + + if(have_stratum) + { + pthread_mutex_lock(&g_work_lock); + if((*nonceptr) >= end_nonce && + !(memcmp(work.data, g_work.data, 39) || memcmp(((uint8_t*)work.data) + 43, ((uint8_t*)g_work.data) + 43, 33))) + { + stratum_gen_work(&stratum, &g_work); + } + } + else + { + /* obtain new work from internal workio thread */ + pthread_mutex_lock(&g_work_lock); + if(!have_longpoll || time(NULL) >= g_work_time + LP_SCANTIME * 3 / 4 || *nonceptr >= end_nonce) + { + if(opt_benchmark) + { + g_work.data[0] = 8; + memset(g_work.data + 1, 0x00, 76); + g_work.data[20] = 0x80000000; + memset(g_work.data + 21, 0x00, 22); + g_work.data[31] = 0x00000280; + memset(g_work.target, 0x00, sizeof(g_work.target)); + } + else + if(unlikely(!get_work(mythr, &g_work))) + { + applog(LOG_ERR, "work retrieval failed, exiting " + "mining thread %d", mythr->id); + pthread_mutex_unlock(&g_work_lock); + goto out; + } + g_work_time = time(NULL); + } + } + if(memcmp(work.data, g_work.data, 39) || memcmp(((uint8_t*)work.data) + 43, ((uint8_t*)g_work.data) + 43, 33)) + { + if(opt_debug) + applog(LOG_DEBUG, "GPU #%d: %s, got new work", device_map[thr_id], device_name[thr_id]); + memcpy(&work, &g_work, sizeof(struct work)); + end_nonce = 0x01000000U / opt_n_threads * (thr_id + 1) - 1 + *nonceptr; + *nonceptr += 0x01000000U / opt_n_threads * thr_id; + } + else + { + if(opt_debug) + applog(LOG_DEBUG, "GPU #%d: %s, continue with old work", device_map[thr_id], device_name[thr_id], *nonceptr, max_nonce); + *nonceptr += hashes_done; + } + + pthread_mutex_unlock(&g_work_lock); + work_restart[thr_id].restart = 0; + + /* adjust max_nonce to meet target scan time */ + if(opt_benchmark) + opt_scantime = 30; + if(have_stratum) + max64 = LP_SCANTIME; + else + max64 = g_work_time + (have_longpoll ? LP_SCANTIME : opt_scantime) - time(NULL); + max64 *= (int64_t)thr_hashrates[thr_id]; + if(max64 <= 0) + max64 = 0x200LL; + if((int64_t)(*nonceptr) + max64 > end_nonce) + max_nonce = end_nonce; + else + max_nonce = (uint32_t)(*nonceptr + max64); + + if(opt_debug) + applog(LOG_DEBUG, "GPU #%d: %s, startnonce $%08X, endnonce $%08X", device_map[thr_id], device_name[thr_id], *nonceptr, max_nonce); + + hashes_done = 0; + gettimeofday(&tv_start, NULL); + + uint32_t results[2]; + /* scan nonces for a proof-of-work hash */ + rc = scanhash_cryptonight(thr_id, work.data, work.target, max_nonce, &hashes_done, results); + + thr_totalhashes[thr_id] += hashes_done; + + /* record scanhash elapsed time */ + gettimeofday(&tv_end, NULL); + timeval_subtract(&diff, &tv_end, &tv_start); + difftime = diff.tv_sec + 1e-6 * diff.tv_usec; + if(difftime > 0) + { + pthread_mutex_lock(&stats_lock); + thr_hashrates[thr_id] = hashes_done / difftime; + pthread_mutex_unlock(&stats_lock); + } + + timeval_subtract(&diff, &tv_end, &stats_start); + difftime = diff.tv_sec + 1e-6 * diff.tv_usec; + + if(!opt_quiet) + applog(LOG_INFO, "GPU #%d: %s, %.2f H/s (%.2f H/s avg)", device_map[thr_id], device_name[thr_id], thr_hashrates[thr_id], thr_totalhashes[thr_id] / difftime); + + if(opt_benchmark && thr_id == opt_n_threads - 1) + { + double hashrate = 0.; + for(i = 0; i < opt_n_threads && thr_hashrates[i]; i++) + hashrate += thr_hashrates[i]; + if(i == opt_n_threads) + { + applog(LOG_INFO, "Total: %.2f H/s", hashrate); + } + } + + /* if nonce found, submit work */ + if(rc && !opt_benchmark) + { + uint32_t backup = *nonceptr; + *nonceptr = results[0]; + submit_work(mythr, &work); + if(rc > 1) + { + *nonceptr = results[1]; + submit_work(mythr, &work); + } + *nonceptr = backup; + } + } + +out: + tq_freeze(mythr->q); + + return NULL; +} + +static void restart_threads(void) +{ + int i; + + for(i = 0; i < opt_n_threads; i++) + work_restart[i].restart = 1; +} + +static void *longpoll_thread(void *userdata) +{ + struct thr_info *mythr = (struct thr_info *)userdata; + CURL *curl = NULL; + char *copy_start = NULL, *hdr_path = NULL, *lp_url = NULL; + bool need_slash = false; + + curl = curl_easy_init(); + if(unlikely(!curl)) + { + applog(LOG_ERR, "CURL initialization failed"); + goto out; + } + +start: + hdr_path = (char*)tq_pop(mythr->q, NULL); + if(!hdr_path) + goto out; + + /* full URL */ + if(strstr(hdr_path, "://")) + { + lp_url = hdr_path; + hdr_path = NULL; + } + + /* absolute path, on current server */ + else + { + copy_start = (*hdr_path == '/') ? (hdr_path + 1) : hdr_path; + if(rpc_url[strlen(rpc_url) - 1] != '/') + need_slash = true; + + lp_url = (char*)malloc(strlen(rpc_url) + strlen(copy_start) + 2); + if(!lp_url) + goto out; + + sprintf(lp_url, "%s%s%s", rpc_url, need_slash ? "/" : "", copy_start); + } + + applog(LOG_INFO, "Long-polling activated for %s", lp_url); + + while(1) + { + json_t *val, *soval; + int err; + + pthread_mutex_lock(&rpc2_login_lock); + if(!strcmp(rpc2_id, "")) + { + sleep(1); + continue; + } + char s[128]; + snprintf(s, 128, "{\"method\": \"getjob\", \"params\": {\"id\": \"%s\"}, \"id\":1}\r\n", rpc2_id); + pthread_mutex_unlock(&rpc2_login_lock); + val = json_rpc2_call(curl, rpc_url, rpc_userpass, s, &err, JSON_RPC_LONGPOLL); + + if(have_stratum) + { + if(val) + json_decref(val); + goto out; + } + if(likely(val)) + { + + soval = json_object_get(json_object_get(val, "result"), "submitold"); + submit_old = soval ? json_is_true(soval) : false; + pthread_mutex_lock(&g_work_lock); + char *start_job_id = strdup(g_work.job_id); + if(work_decode(json_object_get(val, "result"), &g_work)) + { + if(strcmp(start_job_id, g_work.job_id)) + { + if(!opt_quiet) applog(LOG_INFO, "LONGPOLL detected new block"); + if(opt_debug) + applog(LOG_DEBUG, "DEBUG: got new work"); + time(&g_work_time); + restart_threads(); + } + } + pthread_mutex_unlock(&g_work_lock); + json_decref(val); + } + else + { + pthread_mutex_lock(&g_work_lock); + g_work_time -= LP_SCANTIME; + pthread_mutex_unlock(&g_work_lock); + if(err == CURLE_OPERATION_TIMEDOUT) + { + restart_threads(); + } + else + { + have_longpoll = false; + restart_threads(); + free(hdr_path); + free(lp_url); + lp_url = NULL; + sleep(opt_fail_pause); + goto start; + } + } + } + +out: + free(hdr_path); + free(lp_url); + tq_freeze(mythr->q); + if(curl) + curl_easy_cleanup(curl); + + return NULL; +} + +static bool stratum_handle_response(char *buf) +{ + json_t *val = NULL, *err_val = NULL, *res_val = NULL, *id_val = NULL; + json_t *status = NULL; + json_error_t err; + char *s = NULL; + bool ret = false; + bool valid = false; + + val = JSON_LOADS(buf, &err); + if(!val) + { + applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text); + goto out; + } + + res_val = json_object_get(val, "result"); + err_val = json_object_get(val, "error"); + id_val = json_object_get(val, "id"); + + if(!id_val || json_is_null(id_val) || (!res_val && !err_val) ) + goto out; + + status = json_object_get(res_val, "status"); + if(status != NULL) + { + s = (char*)json_string_value(status); + if(strcmp(s, "KEEPALIVED") == 0) + goto out; + valid = !strcmp(s, "OK") && json_is_null(err_val); + } + else + { + valid = json_is_null(err_val); + } + + if(err_val) + { + share_result(valid, json_string_value(json_object_get(err_val, "message"))); + } + else + share_result(valid, NULL); + + ret = true; +out: + if(val) + json_decref(val); + + return ret; +} + +static void *stratum_thread(void *userdata) +{ + struct thr_info *mythr = (struct thr_info *)userdata; + char *s; + + stratum.url = (char*)tq_pop(mythr->q, NULL); + if(!stratum.url) + return NULL; + applog(LOG_INFO, "Starting Stratum on %s", stratum.url); + + while(1) + { + int failures = 0; + + while(!stratum.curl) + { + pthread_mutex_lock(&g_work_lock); + g_work_time = 0; + pthread_mutex_unlock(&g_work_lock); + restart_threads(); + + if(!stratum_connect(&stratum, stratum.url) || + !stratum_authorize(&stratum, rpc_user, rpc_pass)) + { + stratum_disconnect(&stratum); + if(opt_retries >= 0 && ++failures > opt_retries) + { + applog(LOG_ERR, "...terminating workio thread"); + tq_push(thr_info[work_thr_id].q, NULL); + return NULL; + } + applog(LOG_ERR, "...retry after %d seconds", opt_fail_pause); + sleep(opt_fail_pause); + } + } + + if(stratum.work.job_id + && (!g_work_time + || strcmp(stratum.work.job_id, g_work.job_id))) + { + pthread_mutex_lock(&g_work_lock); + stratum_gen_work(&stratum, &g_work); + time(&g_work_time); + pthread_mutex_unlock(&g_work_lock); + applog(LOG_INFO, "Stratum detected new block"); + restart_threads(); + } + + // Should we send a keepalive? + if( opt_keepalive && !stratum_socket_full(&stratum, 90)) + { + applog(LOG_INFO, "Keepalive send..."); + stratum_keepalived(&stratum,rpc2_id); + } + + if(!stratum_socket_full(&stratum, 120)) + { + applog(LOG_ERR, "Stratum connection timed out"); + s = NULL; + } + else + s = stratum_recv_line(&stratum); + if(!s) + { + stratum_disconnect(&stratum); + applog(LOG_ERR, "Stratum connection interrupted"); + continue; + } + if(!stratum_handle_method(&stratum, s)) + stratum_handle_response(s); + free(s); + } + return NULL; +} + +static void show_version_and_exit(void) +{ + printf("%s\n%s\n", PACKAGE_STRING, curl_version()); + exit(0); +} + +static void show_usage_and_exit(int status) +{ + if(status) + printf("Try `" PROGRAM_NAME " --help' for more information.\n"); + else + printf(usage); + exit(status); +} + +void parse_device_config(int device, char *config, int *blocks, int *threads) +{ + char *p; + int tmp_blocks, tmp_threads; + + if(config == NULL) + return; + + p = strtok(config, "x"); + if(!p) + return; + + tmp_threads = atoi(p); + if(tmp_threads < 4 || tmp_threads > 1024) + return; + + p = strtok(NULL, "x"); + if(!p) + return; + + tmp_blocks = atoi(p); + if(tmp_blocks < 1) + return; + + *blocks = tmp_blocks; + *threads = tmp_threads; + return; +} + +static void parse_arg(int key, char *arg) +{ + char *p; + int v, i; + double d; + + switch(key) + { + case 'a': + for (i = 0; i < ARRAY_SIZE(algo_names); i++) + { + if (algo_names[i] && !strcasecmp(arg, algo_names[i])) + { + opt_algo = (algo_t)i; + break; + } + } + if (opt_algo == algo_monero) + forkversion = 7; + if (opt_algo == algo_graft) + forkversion = 8; + if (opt_algo == algo_stellite) + forkversion = 3; + if(opt_algo == algo_intense) + forkversion = 4; + if (opt_algo == algo_electroneum) + forkversion = 6; + if (opt_algo == algo_sumokoin) + { + MEMORY = 1 << 22; + ITER = 1 << 19; + } + break; + case 'B': + opt_background = true; + break; + case 'c': { + json_error_t err; + if(opt_config) + json_decref(opt_config); +#if JANSSON_VERSION_HEX >= 0x020000 + opt_config = json_load_file(arg, 0, &err); +#else + opt_config = json_load_file(arg, &err); +#endif + if(!json_is_object(opt_config)) + { + applog(LOG_ERR, "JSON decode of %s failed", arg); + exit(1); + } + break; + } + case 'k': + opt_keepalive = true ; + applog(LOG_INFO, "Keepalive activated"); + break; + case 'q': + opt_quiet = true; + break; + case 'D': + opt_debug = true; + break; + case 'p': + free(rpc_pass); + rpc_pass = strdup(arg); + break; + case 'P': + opt_protocol = true; + break; + case 'r': + v = atoi(arg); + if(v < -1 || v > 9999) /* sanity check */ + show_usage_and_exit(1); + opt_retries = v; + break; + case 'R': + v = atoi(arg); + if(v < 1 || v > 9999) /* sanity check */ + show_usage_and_exit(1); + opt_fail_pause = v; + break; + case 's': + v = atoi(arg); + if(v < 1 || v > 9999) /* sanity check */ + show_usage_and_exit(1); + opt_scantime = v; + break; + case 'T': + v = atoi(arg); + if(v < 1 || v > 99999) /* sanity check */ + show_usage_and_exit(1); + opt_timeout = v; + break; + case 't': + v = atoi(arg); + if(v < 1 || v > 9999) /* sanity check */ + show_usage_and_exit(1); + opt_n_threads = v; + break; + case 'v': + break; + case 'u': + free(rpc_user); + rpc_user = strdup(arg); + break; + case 'o': /* --url */ + p = strstr(arg, "://"); + if(p) + { + if(strncasecmp(arg, "http://", 7) + && strncasecmp(arg, "https://", 8) + && strncasecmp(arg, "stratum+tcp://", 14)) + show_usage_and_exit(1); + free(rpc_url); + rpc_url = strdup(arg); + } + else + { + if(!strlen(arg) || *arg == '/') + show_usage_and_exit(1); + free(rpc_url); + rpc_url = (char*)malloc(strlen(arg) + 8); + if (rpc_url == NULL) + { + applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); + exit(1); + } + sprintf(rpc_url, "http://%s", arg); + } + p = strrchr(rpc_url, '@'); + if(p) + { + char *sp, *ap; + *p = '\0'; + ap = strstr(rpc_url, "://") + 3; + sp = strchr(ap, ':'); + if(sp) + { + free(rpc_userpass); + rpc_userpass = strdup(ap); + free(rpc_user); + rpc_user = (char*)calloc(sp - ap + 1, 1); + strncpy(rpc_user, ap, sp - ap); + free(rpc_pass); + rpc_pass = strdup(sp + 1); + } + else + { + free(rpc_user); + rpc_user = strdup(ap); + } + memmove(ap, p + 1, strlen(p + 1) + 1); + } + have_stratum = !opt_benchmark && !strncasecmp(rpc_url, "stratum", 7); + break; + case 'O': /* --userpass */ + p = strchr(arg, ':'); + if(!p) + show_usage_and_exit(1); + free(rpc_userpass); + rpc_userpass = strdup(arg); + free(rpc_user); + rpc_user = (char*)calloc(p - arg + 1, 1); + strncpy(rpc_user, arg, p - arg); + free(rpc_pass); + rpc_pass = strdup(p + 1); + break; + case 'x': /* --proxy */ + if(!strncasecmp(arg, "socks4://", 9)) + opt_proxy_type = CURLPROXY_SOCKS4; + else if(!strncasecmp(arg, "socks5://", 9)) + opt_proxy_type = CURLPROXY_SOCKS5; +#if LIBCURL_VERSION_NUM >= 0x071200 + else if(!strncasecmp(arg, "socks4a://", 10)) + opt_proxy_type = CURLPROXY_SOCKS4A; + else if(!strncasecmp(arg, "socks5h://", 10)) + opt_proxy_type = CURLPROXY_SOCKS5_HOSTNAME; +#endif + else + opt_proxy_type = CURLPROXY_HTTP; + free(opt_proxy); + opt_proxy = strdup(arg); + break; + case 1001: + free(opt_cert); + opt_cert = strdup(arg); + break; + case 1005: + opt_benchmark = true; + want_longpoll = false; + want_stratum = false; + have_stratum = false; + break; + case 1003: + want_longpoll = false; + break; + case 1007: + want_stratum = false; + break; + case 'S': + use_syslog = true; + break; + case 'd': // CB + { + int i; + bool gpu[32] = {false}; + char * pch = strtok(arg, ","); + opt_n_threads = 0; + while(pch != NULL) + { + if(pch[0] >= '0' && pch[0] <= '9') + { + i = atoi(pch); + if(i < num_processors && gpu[i] == false && opt_n_threads < MAX_GPU) + { + gpu[i] = true; + device_map[opt_n_threads++] = i; + } + else + { + if(opt_n_threads >= MAX_GPU) + { + applog(LOG_ERR, "Only %d gpus are supported in this ccminer build.", MAX_GPU); + proper_exit(1); + } + if(gpu[i] == true) + { + applog(LOG_ERR, "Selected gpu #%d more than once in -d option. This is not supported.", i); + proper_exit(1); + } + applog(LOG_ERR, "Non-existant CUDA device #%d specified in -d option", i); + proper_exit(1); + } + } + else + { + int device = cuda_finddevice(pch); + if(device >= 0 && device < num_processors) + device_map[opt_n_threads++] = device; + else + { + applog(LOG_ERR, "Non-existant CUDA device '%s' specified in -d option", pch); + exit(1); + } + } + pch = strtok(NULL, ","); + } + } + break; + case 'f': // CH - Divisor for Difficulty + d = atof(arg); + if(d == 0) /* sanity check */ + show_usage_and_exit(1); + opt_difficulty = d; + break; + case 'l': /* cryptonight launch config */ + { + char *tmp_config[MAX_GPU]; + int tmp_blocks = opt_cn_blocks, tmp_threads = opt_cn_threads; + for(i = 0; i < MAX_GPU; i++) + tmp_config[i] = NULL; + p = strtok(arg, ","); + if(p == NULL) show_usage_and_exit(1); + i = 0; + while(p != NULL && i < MAX_GPU) + { + tmp_config[i++] = strdup(p); + p = strtok(NULL, ","); + } + while(i < 8) + { + tmp_config[i] = strdup(tmp_config[i - 1]); + i++; + } + + for(i = 0; i < MAX_GPU; i++) + { + parse_device_config(i, tmp_config[i], &tmp_blocks, &tmp_threads); + device_config[i][0] = tmp_blocks; + device_config[i][1] = tmp_threads; + } + } + break; + case 1008: + { + p = strtok(arg, ","); + if(p == NULL) show_usage_and_exit(1); + int last; + i = 0; + while(p != NULL && i < MAX_GPU) + { + device_bfactor[i++] = last = atoi(p); + if(last < 0 || last > 10) + { + applog(LOG_ERR, "Valid range for --bfactor is 0-10"); + exit(1); + } + p = strtok(NULL, ","); + } + while(i < MAX_GPU) + { + device_bfactor[i++] = last; + } + } + break; + case 1009: + p = strtok(arg, ","); + if(p == NULL) show_usage_and_exit(1); + int last; + i = 0; + while(p != NULL && i < MAX_GPU) + { + device_bsleep[i++] = last = atoi(p); + if(last < 0 || last > 1000000) + { + applog(LOG_ERR, "Valid range for --bsleep is 0-1000000"); + exit(1); + } + p = strtok(NULL, ","); + } + while(i < MAX_GPU) + { + device_bsleep[i++] = last; + } + break; + case 1010: + opt_colors = true; +#if defined WIN32 && defined ENABLE_VIRTUAL_TERMINAL_PROCESSING + handl = GetStdHandle(STD_ERROR_HANDLE); + SetConsoleMode(handl, ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); +#endif + break; + + case 'V': + show_version_and_exit(); + case 'h': + show_usage_and_exit(0); + default: + show_usage_and_exit(1); + } +} + +static void parse_config(void) +{ + int i; + json_t *val; + + if(!json_is_object(opt_config)) + return; + + for(i = 0; i < ARRAY_SIZE(options); i++) + { + if(!options[i].name) + break; + if(!strcmp(options[i].name, "config")) + continue; + + val = json_object_get(opt_config, options[i].name); + if(!val) + continue; + + if(options[i].has_arg && json_is_string(val)) + { + char *s = strdup(json_string_value(val)); + if(!s) + break; + parse_arg(options[i].val, s); + free(s); + } + else if(!options[i].has_arg && json_is_true(val)) + parse_arg(options[i].val, ""); + else + applog(LOG_ERR, "JSON option %s invalid", + options[i].name); + } +} + +static void parse_cmdline(int argc, char *argv[]) +{ + int key; + + while(1) + { +#if HAVE_GETOPT_LONG + key = getopt_long(argc, argv, short_options, options, NULL); +#else + key = getopt(argc, argv, short_options); +#endif + if(key < 0) + break; + + parse_arg(key, optarg); + } + if(optind < argc) + { + printf("%s: unsupported non-option argument '%s'\n", + argv[0], argv[optind]); + show_usage_and_exit(1); + } + parse_config(); +} + +#ifndef WIN32 +static void signal_handler(int sig) +{ + switch(sig) + { + case SIGHUP: + applog(LOG_INFO, "SIGHUP received"); + break; + case SIGINT: + applog(LOG_INFO, "SIGINT received, exiting"); + exit(0); + break; + case SIGTERM: + applog(LOG_INFO, "SIGTERM received, exiting"); + exit(0); + break; + } +} +#else +BOOL WINAPI ConsoleHandler(DWORD dwType) +{ + switch(dwType) + { + case CTRL_C_EVENT: + applog(LOG_INFO, "CTRL_C_EVENT received, exiting"); + proper_exit(EXIT_SUCCESS); + break; + case CTRL_BREAK_EVENT: + applog(LOG_INFO, "CTRL_BREAK_EVENT received, exiting"); + proper_exit(EXIT_SUCCESS); + break; + default: + return false; + } + return true; +} +#endif + +static int msver(void) +{ + int version; +#ifdef _MSC_VER + switch(_MSC_VER/100) + { + case 15: version = 2008; break; + case 16: version = 2010; break; + case 17: version = 2012; break; + case 18: version = 2013; break; + case 19: version = 2015; break; + default: version = _MSC_VER / 100; + } + if(_MSC_VER > 1900) + version = 2017; +#else + version = 0; +#endif + return version; +} + +#define PROGRAM_VERSION "3.06" +int main(int argc, char *argv[]) +{ + struct thr_info *thr; + int i; + /* +#ifdef WIN32 + SYSTEM_INFO sysinfo; +#endif + */ +#if defined _WIN64 || defined _LP64 + int bits = 64; +#else + int bits = 32; +#endif + printf(" *** ccminer-cryptonight %s (%d bit) for nVidia GPUs by tsiv and KlausT \n", PROGRAM_VERSION, bits); +#ifdef _MSC_VER + printf(" *** Built with Visual Studio %d ", msver()); +#else +#ifdef __clang__ + printf(" *** Built with Clang %s ", __clang_version__); +#else +#ifdef __GNUC__ + printf(" *** Built with GCC %d.%d ", __GNUC__, __GNUC_MINOR__); +#else + printf(" *** Built with an unusual compiler "); +#endif +#endif +#endif + printf("using the Nvidia CUDA Toolkit %d.%d\n\n", CUDART_VERSION / 1000, (CUDART_VERSION % 1000) / 10); + printf(" tsiv's BTC donation address: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs\n"); + printf(" KlausT's BTC donation address: 1QHH2dibyYL5iyMDk3UN4PVvFVtrWD8QKp\n"); + printf(" for more donation addresses please read the README.txt\n"); + printf("-----------------------------------------------------------------\n"); + + rpc_user = strdup(""); + rpc_pass = strdup(""); + + pthread_mutex_init(&applog_lock, NULL); + num_processors = cuda_num_devices(); + if(num_processors == 0) + { + applog(LOG_ERR, "No CUDA devices found! terminating."); + exit(EXIT_FAILURE); + } + else + applog(LOG_INFO, "%d CUDA devices detected", num_processors); + + if(!opt_n_threads) + opt_n_threads = num_processors; + + for(i = 0; i < MAX_GPU; i++) + { + device_map[i] = i; + device_bfactor[i] = default_bfactor; + device_bsleep[i] = default_bsleep; + device_config[i][0] = opt_cn_blocks; + } + + /* parse command line */ + parse_cmdline(argc, argv); + color_init(); + + cuda_deviceinfo(opt_n_threads); + cuda_set_device_config(opt_n_threads); + + if(!opt_benchmark && !rpc_url) + { + printf("%s: no URL supplied\n", argv[0]); + show_usage_and_exit(1); + } + + if(!rpc_userpass) + { + rpc_userpass = (char*)malloc(strlen(rpc_user) + strlen(rpc_pass) + 2); + if(!rpc_userpass) + exit(EXIT_FAILURE); + sprintf(rpc_userpass, "%s:%s", rpc_user, rpc_pass); + } + + pthread_mutex_init(&stats_lock, NULL); + pthread_mutex_init(&g_work_lock, NULL); + pthread_mutex_init(&rpc2_job_lock, NULL); + pthread_mutex_init(&stratum.sock_lock, NULL); + pthread_mutex_init(&stratum.work_lock, NULL); + + if(curl_global_init(CURL_GLOBAL_ALL)) + { + applog(LOG_ERR, "CURL initialization failed"); + exit(EXIT_FAILURE); + } + +#ifndef WIN32 + if(opt_background) + { + i = fork(); + if(i < 0) exit(1); + if(i > 0) exit(0); + i = setsid(); + if(i < 0) + applog(LOG_ERR, "setsid() failed (errno = %d)", errno); + i = chdir("/"); + if(i < 0) + applog(LOG_ERR, "chdir() failed (errno = %d)", errno); + signal(SIGHUP, signal_handler); + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + } + signal(SIGINT, signal_handler); +#else + if(opt_background) + applog(LOG_WARNING, "option -B is not supported under Windows"); + SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE); + SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); +#endif + +#ifdef HAVE_SYSLOG_H + if(use_syslog) + openlog("cpuminer", LOG_PID, LOG_USER); +#endif + + work_restart = (struct work_restart *)calloc(opt_n_threads, sizeof(*work_restart)); + if(!work_restart) + proper_exit(EXIT_FAILURE); + + thr_info = (struct thr_info *)calloc(opt_n_threads + 3, sizeof(*thr)); + if(!thr_info) + proper_exit(EXIT_FAILURE); + + thr_hashrates = (double *)calloc(opt_n_threads, sizeof(double)); + if(!thr_hashrates) + proper_exit(EXIT_FAILURE); + + thr_totalhashes = (uint64_t *)calloc(opt_n_threads, sizeof(uint64_t)); + if(!thr_hashrates) + proper_exit(EXIT_FAILURE); + + /* init workio thread info */ + work_thr_id = opt_n_threads; + thr = &thr_info[work_thr_id]; + thr->id = work_thr_id; + thr->q = tq_new(); + if(!thr->q) + proper_exit(EXIT_FAILURE); + + /* start work I/O thread */ + if(pthread_create(&thr->pth, NULL, workio_thread, thr)) + { + applog(LOG_ERR, "workio thread create failed"); + proper_exit(EXIT_FAILURE); + } + + if(want_longpoll && !have_stratum) + { + /* init longpoll thread info */ + longpoll_thr_id = opt_n_threads + 1; + thr = &thr_info[longpoll_thr_id]; + thr->id = longpoll_thr_id; + thr->q = tq_new(); + if(!thr->q) + proper_exit(EXIT_FAILURE); + + /* start longpoll thread */ + if(unlikely(pthread_create(&thr->pth, NULL, longpoll_thread, thr))) + { + applog(LOG_ERR, "longpoll thread create failed"); + proper_exit(EXIT_FAILURE); + } + } + if(want_stratum) + { + /* init stratum thread info */ + stratum_thr_id = opt_n_threads + 2; + thr = &thr_info[stratum_thr_id]; + thr->id = stratum_thr_id; + thr->q = tq_new(); + if(!thr->q) + proper_exit(EXIT_FAILURE); + + /* start stratum thread */ + if(unlikely(pthread_create(&thr->pth, NULL, stratum_thread, thr))) + { + applog(LOG_ERR, "stratum thread create failed"); + proper_exit(EXIT_FAILURE); + } + + if(have_stratum) + tq_push(thr_info[stratum_thr_id].q, strdup(rpc_url)); + } + gettimeofday(&stats_start, NULL); + + /* start mining threads */ + for(i = 0; i < opt_n_threads; i++) + { + thr = &thr_info[i]; + + thr->id = i; + thr->q = tq_new(); + if(!thr->q) + proper_exit(EXIT_FAILURE); + + if(unlikely(pthread_create(&thr->pth, NULL, miner_thread, thr))) + { + applog(LOG_ERR, "thread %d create failed", i); + proper_exit(EXIT_FAILURE); + } + } + + applog(LOG_INFO, "%d miner threads started", opt_n_threads); + +#ifdef WIN32 + timeBeginPeriod(1); // enable high timer precision (similar to Google Chrome Trick) +#endif + + /* main loop - simply wait for workio thread to exit */ + pthread_join(thr_info[work_thr_id].pth, NULL); + +#ifdef WIN32 + timeEndPeriod(1); // be nice and forego high timer precision +#endif + + applog(LOG_INFO, "workio thread dead, exiting."); + + proper_exit(EXIT_SUCCESS); +} + diff --git a/cpuminer-config.h b/cpuminer-config-win.h similarity index 87% rename from cpuminer-config.h rename to cpuminer-config-win.h index 03114b9..0aef6b3 100644 --- a/cpuminer-config.h +++ b/cpuminer-config-win.h @@ -1,8 +1,3 @@ -/* cpuminer-config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP - systems. This function is required for `alloca.c' support on those systems. - */ #undef CRAY_STACKSEG_END /* Define to 1 if using `alloca.c'. */ @@ -38,16 +33,16 @@ #undef HAVE_INTTYPES_H /* Define to 1 if you have a functional curl library. */ -#undef HAVE_LIBCURL +#define HAVE_LIBCURL 1 /* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H +#define HAVE_MEMORY_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H +#define HAVE_STDINT_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H +#define HAVE_STDLIB_H 1 /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H @@ -77,13 +72,13 @@ #undef HAVE_UNISTD_H /* Defined if libcurl supports AsynchDNS */ -#undef LIBCURL_FEATURE_ASYNCHDNS +#define LIBCURL_FEATURE_ASYNCHDNS 1 /* Defined if libcurl supports IDN */ -#undef LIBCURL_FEATURE_IDN +#define LIBCURL_FEATURE_IDN 1 /* Defined if libcurl supports IPv6 */ -#undef LIBCURL_FEATURE_IPV6 +#define LIBCURL_FEATURE_IPV6 1 /* Defined if libcurl supports KRB4 */ #undef LIBCURL_FEATURE_KRB4 @@ -95,7 +90,7 @@ #undef LIBCURL_FEATURE_NTLM /* Defined if libcurl supports SSL */ -#undef LIBCURL_FEATURE_SSL +#define LIBCURL_FEATURE_SSL 1 /* Defined if libcurl supports SSPI */ #undef LIBCURL_FEATURE_SSPI @@ -113,10 +108,10 @@ #undef LIBCURL_PROTOCOL_FTPS /* Defined if libcurl supports HTTP */ -#undef LIBCURL_PROTOCOL_HTTP +#define LIBCURL_PROTOCOL_HTTP 1 /* Defined if libcurl supports HTTPS */ -#undef LIBCURL_PROTOCOL_HTTPS +#define LIBCURL_PROTOCOL_HTTPS 1 /* Defined if libcurl supports IMAP */ #undef LIBCURL_PROTOCOL_IMAP @@ -149,10 +144,10 @@ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ -#define PACKAGE_NAME "ccminer" +#define PACKAGE_NAME "ccminer-cryptonight" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "ccminer 2014.06.14" +#define PACKAGE_STRING "ccminer-cryptonight 3.06" /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME @@ -161,7 +156,10 @@ #undef PACKAGE_URL /* Define to the version of this package. */ -#define PACKAGE_VERSION "2014.06.14" +#define PACKAGE_VERSION "3.06" + +/* Version number of package */ +#undef VERSION /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be @@ -172,7 +170,7 @@ #undef STACK_DIRECTION /* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS +#define STDC_HEADERS 1 /* Define to 1 if AVX assembly is available. */ #undef USE_AVX @@ -180,11 +178,8 @@ /* Define to 1 if XOP assembly is available. */ #undef USE_XOP -/* Version number of package */ -#undef VERSION - /* Define curl_free() as free() if our version of curl lacks curl_free. */ #undef curl_free /* Define to `unsigned int' if does not define. */ -#undef size_t +/*#undef size_t*/ diff --git a/cpuminer-config.h.in b/cpuminer-config.h.in deleted file mode 100644 index b8668be..0000000 --- a/cpuminer-config.h.in +++ /dev/null @@ -1,199 +0,0 @@ -/* cpuminer-config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP - systems. This function is required for `alloca.c' support on those systems. - */ -#undef CRAY_STACKSEG_END - -/* Define to 1 if using `alloca.c'. */ -#undef C_ALLOCA - -/* Define to 1 if you have `alloca', as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define to 1 if you have and it should be used (not on Ultrix). - */ -#undef HAVE_ALLOCA_H - -/* Define to 1 if you have the declaration of `be32dec', and to 0 if you - don't. */ -#undef HAVE_DECL_BE32DEC - -/* Define to 1 if you have the declaration of `be32enc', and to 0 if you - don't. */ -#undef HAVE_DECL_BE32ENC - -/* Define to 1 if you have the declaration of `le32dec', and to 0 if you - don't. */ -#undef HAVE_DECL_LE32DEC - -/* Define to 1 if you have the declaration of `le32enc', and to 0 if you - don't. */ -#undef HAVE_DECL_LE32ENC - -/* Define to 1 if you have the `getopt_long' function. */ -#undef HAVE_GETOPT_LONG - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the `crypto' library (-lcrypto). */ -#undef HAVE_LIBCRYPTO - -/* Define to 1 if you have a functional curl library. */ -#undef HAVE_LIBCURL - -/* Define to 1 if you have the `ssl' library (-lssl). */ -#undef HAVE_LIBSSL - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_ENDIAN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_PARAM_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SYSCTL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Defined if libcurl supports AsynchDNS */ -#undef LIBCURL_FEATURE_ASYNCHDNS - -/* Defined if libcurl supports IDN */ -#undef LIBCURL_FEATURE_IDN - -/* Defined if libcurl supports IPv6 */ -#undef LIBCURL_FEATURE_IPV6 - -/* Defined if libcurl supports KRB4 */ -#undef LIBCURL_FEATURE_KRB4 - -/* Defined if libcurl supports libz */ -#undef LIBCURL_FEATURE_LIBZ - -/* Defined if libcurl supports NTLM */ -#undef LIBCURL_FEATURE_NTLM - -/* Defined if libcurl supports SSL */ -#undef LIBCURL_FEATURE_SSL - -/* Defined if libcurl supports SSPI */ -#undef LIBCURL_FEATURE_SSPI - -/* Defined if libcurl supports DICT */ -#undef LIBCURL_PROTOCOL_DICT - -/* Defined if libcurl supports FILE */ -#undef LIBCURL_PROTOCOL_FILE - -/* Defined if libcurl supports FTP */ -#undef LIBCURL_PROTOCOL_FTP - -/* Defined if libcurl supports FTPS */ -#undef LIBCURL_PROTOCOL_FTPS - -/* Defined if libcurl supports HTTP */ -#undef LIBCURL_PROTOCOL_HTTP - -/* Defined if libcurl supports HTTPS */ -#undef LIBCURL_PROTOCOL_HTTPS - -/* Defined if libcurl supports IMAP */ -#undef LIBCURL_PROTOCOL_IMAP - -/* Defined if libcurl supports LDAP */ -#undef LIBCURL_PROTOCOL_LDAP - -/* Defined if libcurl supports POP3 */ -#undef LIBCURL_PROTOCOL_POP3 - -/* Defined if libcurl supports RTSP */ -#undef LIBCURL_PROTOCOL_RTSP - -/* Defined if libcurl supports SMTP */ -#undef LIBCURL_PROTOCOL_SMTP - -/* Defined if libcurl supports TELNET */ -#undef LIBCURL_PROTOCOL_TELNET - -/* Defined if libcurl supports TFTP */ -#undef LIBCURL_PROTOCOL_TFTP - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -#undef NO_MINUS_C_MINUS_O - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at runtime. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ -#undef STACK_DIRECTION - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define to 1 if AVX assembly is available. */ -#undef USE_AVX - -/* Define to 1 if AVX2 assembly is available. */ -#undef USE_AVX2 - -/* Define to 1 if XOP assembly is available. */ -#undef USE_XOP - -/* Version number of package */ -#undef VERSION - -/* Define curl_free() as free() if our version of curl lacks curl_free. */ -#undef curl_free - -/* Define to `unsigned int' if does not define. */ -#undef size_t diff --git a/crypto/aesb.c b/crypto/aesb.cpp old mode 100755 new mode 100644 similarity index 98% rename from crypto/aesb.c rename to crypto/aesb.cpp index 2e18b2b..97c23ea --- a/crypto/aesb.c +++ b/crypto/aesb.cpp @@ -20,11 +20,6 @@ Issue Date: 20/12/2007 #include -#if defined(__cplusplus) -extern "C" -{ -#endif - #define TABLE_ALIGN 32 #define WPOLY 0x011b #define N_COLS 4 @@ -164,7 +159,3 @@ void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey) round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 9 * N_COLS); } - -#if defined(__cplusplus) -} -#endif diff --git a/crypto/c_blake256.c b/crypto/c_blake256.cpp old mode 100755 new mode 100644 similarity index 100% rename from crypto/c_blake256.c rename to crypto/c_blake256.cpp diff --git a/crypto/c_groestl.c b/crypto/c_groestl.cpp old mode 100755 new mode 100644 similarity index 99% rename from crypto/c_groestl.c rename to crypto/c_groestl.cpp index 0f57ea1..9f10b67 --- a/crypto/c_groestl.c +++ b/crypto/c_groestl.cpp @@ -7,7 +7,7 @@ * * */ - +#include #include "c_groestl.h" #include "groestl_tables.h" @@ -204,10 +204,9 @@ static void OutputTransformation(groestlHashState *ctx) { /* initialise context */ static void Init(groestlHashState* ctx) { - int i = 0; /* allocate memory for state and data buffer */ - for(;i<(SIZE512/sizeof(uint32_t));i++) + for(size_t i = 0;i<(SIZE512/sizeof(uint32_t));i++) { ctx->chaining[i] = 0; } diff --git a/crypto/c_jh.c b/crypto/c_jh.cpp old mode 100755 new mode 100644 similarity index 99% rename from crypto/c_jh.c rename to crypto/c_jh.cpp index 728f3bb..6a38fd3 --- a/crypto/c_jh.c +++ b/crypto/c_jh.cpp @@ -261,16 +261,16 @@ static HashReturn Update(hashState *state, const BitSequence *data, DataLength d /*There is data in the buffer, but the incoming data is insufficient for a full block*/ if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) < 512) ) { if ( (databitlen & 7) == 0 ) { - memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)) ; + memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, (size_t)(64-(state->datasize_in_buffer >> 3))) ; } - else memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)+1) ; + else memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, (size_t)(64-(state->datasize_in_buffer >> 3)+1)) ; state->datasize_in_buffer += databitlen; databitlen = 0; } /*There is data in the buffer, and the incoming data is sufficient for a full block*/ if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) >= 512) ) { - memcpy( state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3) ) ; + memcpy( state->buffer + (state->datasize_in_buffer >> 3), data, (size_t)(64-(state->datasize_in_buffer >> 3)) ) ; index = 64-(state->datasize_in_buffer >> 3); databitlen = databitlen - (512 - state->datasize_in_buffer); F8(state); diff --git a/crypto/c_keccak.c b/crypto/c_keccak.cpp old mode 100755 new mode 100644 similarity index 95% rename from crypto/c_keccak.c rename to crypto/c_keccak.cpp index 28e9c6a..d3c5c32 --- a/crypto/c_keccak.c +++ b/crypto/c_keccak.cpp @@ -83,11 +83,11 @@ void keccakf(uint64_t st[25], int rounds) // compute a keccak hash (md) of given byte length from "in" typedef uint64_t state_t[25]; -int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) +int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen) { state_t st; uint8_t temp[144]; - int i, rsiz, rsizw; + size_t i, rsiz, rsizw; rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; rsizw = rsiz / 8; @@ -116,7 +116,7 @@ int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) return 0; } -void keccak1600(const uint8_t *in, int inlen, uint8_t *md) +void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md) { keccak(in, inlen, md, sizeof(state_t)); } diff --git a/crypto/c_keccak.h b/crypto/c_keccak.h index 566a305..435bd0d 100755 --- a/crypto/c_keccak.h +++ b/crypto/c_keccak.h @@ -24,11 +24,11 @@ #endif // compute a keccak hash (md) of given byte length from "in" -int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); +int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen); // update the state void keccakf(uint64_t st[25], int norounds); -void keccak1600(const uint8_t *in, int inlen, uint8_t *md); +void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md); #endif diff --git a/crypto/c_skein.c b/crypto/c_skein.cpp old mode 100755 new mode 100644 similarity index 99% rename from crypto/c_skein.c rename to crypto/c_skein.cpp index 255d14a..1d51137 --- a/crypto/c_skein.c +++ b/crypto/c_skein.cpp @@ -1952,12 +1952,12 @@ static SkeinHashReturn Init(hashState *state, int hashbitlen) if (hashbitlen <= SKEIN_512_NIST_MAX_HASHBITS) { state->statebits = 64*SKEIN_512_STATE_WORDS; - return Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen); + return (SkeinHashReturn)Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen); } else { state->statebits = 64*SKEIN1024_STATE_WORDS; - return Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen); + return (SkeinHashReturn)Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen); } } @@ -1973,9 +1973,9 @@ static SkeinHashReturn Update(hashState *state, const SkeinBitSequence *data, Sk { switch ((state->statebits >> 8) & 3) { - case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3); - case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3); - case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3); + case 2: return (SkeinHashReturn)Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3); + case 1: return (SkeinHashReturn)Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3); + case 0: return (SkeinHashReturn)Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3); default: return SKEIN_FAIL; } } @@ -2013,9 +2013,9 @@ static SkeinHashReturn Final(hashState *state, SkeinBitSequence *hashval) Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL); switch ((state->statebits >> 8) & 3) { - case 2: return Skein_512_Final(&state->u.ctx_512,hashval); - case 1: return Skein_256_Final(&state->u.ctx_256,hashval); - case 0: return Skein1024_Final(&state->u.ctx1024,hashval); + case 2: return (SkeinHashReturn)Skein_512_Final(&state->u.ctx_512,hashval); + case 1: return (SkeinHashReturn)Skein_256_Final(&state->u.ctx_256,hashval); + case 0: return (SkeinHashReturn)Skein1024_Final(&state->u.ctx1024,hashval); default: return SKEIN_FAIL; } } diff --git a/crypto/oaes_config.h b/crypto/oaes_config.h index d43e113..104eacd 100755 --- a/crypto/oaes_config.h +++ b/crypto/oaes_config.h @@ -31,10 +31,6 @@ #ifndef _OAES_CONFIG_H #define _OAES_CONFIG_H -#ifdef __cplusplus -extern "C" { -#endif - //#ifndef OAES_HAVE_ISAAC //#define OAES_HAVE_ISAAC 1 //#endif // OAES_HAVE_ISAAC @@ -44,8 +40,4 @@ extern "C" { //#endif // OAES_DEBUG //#define OAES_DEBUG 1 -#ifdef __cplusplus -} -#endif - #endif // _OAES_CONFIG_H diff --git a/crypto/oaes_lib.c b/crypto/oaes_lib.cpp old mode 100755 new mode 100644 similarity index 92% rename from crypto/oaes_lib.c rename to crypto/oaes_lib.cpp index 045b94e..4687c63 --- a/crypto/oaes_lib.c +++ b/crypto/oaes_lib.cpp @@ -1,19 +1,19 @@ -/* +/* * --------------------------------------------------------------------------- * OpenAES License * --------------------------------------------------------------------------- * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - 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. - * + * * 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 AND FITNESS FOR A PARTICULAR PURPOSE @@ -34,7 +34,7 @@ static const char _NR[] = { #include "miner.h" #include -#include +#include #include #if !((defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__APPLE__)) #include @@ -43,8 +43,9 @@ static const char _NR[] = { #include #include -#ifdef WIN32 +#ifdef _MSC_VER #include +#define getpid() _getpid() #else #include #include @@ -239,21 +240,21 @@ static uint8_t oaes_gf_mul_e[16][16] = { static OAES_RET oaes_sub_byte( uint8_t * byte ) { size_t _x, _y; - - if( unlikely(NULL == byte) ) + + if(NULL == byte) return OAES_RET_ARG1; _y = ((_x = *byte) >> 4) & 0x0f; _x &= 0x0f; *byte = oaes_sub_byte_value[_y][_x]; - + return OAES_RET_SUCCESS; } static OAES_RET oaes_inv_sub_byte( uint8_t * byte ) { size_t _x, _y; - + if( NULL == byte ) return OAES_RET_ARG1; @@ -262,57 +263,62 @@ static OAES_RET oaes_inv_sub_byte( uint8_t * byte ) _y &= 0xf0; _y >>= 4; *byte = oaes_inv_sub_byte_value[_y][_x]; - + return OAES_RET_SUCCESS; } /* static OAES_RET oaes_word_rot_right( uint8_t word[OAES_COL_LEN] ) { uint8_t _temp[OAES_COL_LEN]; - + if( NULL == word ) return OAES_RET_ARG1; memcpy( _temp + 1, word, OAES_COL_LEN - 1 ); _temp[0] = word[OAES_COL_LEN - 1]; memcpy( word, _temp, OAES_COL_LEN ); - + return OAES_RET_SUCCESS; } */ static OAES_RET oaes_word_rot_left( uint8_t word[OAES_COL_LEN] ) { uint8_t _temp[OAES_COL_LEN]; - + if( NULL == word ) return OAES_RET_ARG1; memcpy( _temp, word + 1, OAES_COL_LEN - 1 ); _temp[OAES_COL_LEN - 1] = word[0]; memcpy( word, _temp, OAES_COL_LEN ); - + return OAES_RET_SUCCESS; } static OAES_RET oaes_shift_rows( uint8_t block[OAES_BLOCK_SIZE] ) { - uint8_t _temp[] = { block[0x03], block[0x02], block[0x01], block[0x06], block[0x0b] }; + uint8_t _temp[OAES_BLOCK_SIZE]; - if( unlikely(NULL == block) ) + if(NULL == block) return OAES_RET_ARG1; - block[0x0b] = block[0x07]; - block[0x01] = block[0x05]; - block[0x02] = block[0x0a]; - block[0x03] = block[0x0f]; - block[0x05] = block[0x09]; - block[0x06] = block[0x0e]; - block[0x07] = _temp[0]; - block[0x09] = block[0x0d]; - block[0x0a] = _temp[1]; - block[0x0d] = _temp[2]; - block[0x0e] = _temp[3]; - block[0x0f] = _temp[4]; + _temp[0x00] = block[0x00]; + _temp[0x01] = block[0x05]; + _temp[0x02] = block[0x0a]; + _temp[0x03] = block[0x0f]; + _temp[0x04] = block[0x04]; + _temp[0x05] = block[0x09]; + _temp[0x06] = block[0x0e]; + _temp[0x07] = block[0x03]; + _temp[0x08] = block[0x08]; + _temp[0x09] = block[0x0d]; + _temp[0x0a] = block[0x02]; + _temp[0x0b] = block[0x07]; + _temp[0x0c] = block[0x0c]; + _temp[0x0d] = block[0x01]; + _temp[0x0e] = block[0x06]; + _temp[0x0f] = block[0x0b]; + memcpy(block, _temp, OAES_BLOCK_SIZE); return OAES_RET_SUCCESS; } @@ -341,7 +347,7 @@ static OAES_RET oaes_inv_shift_rows( uint8_t block[OAES_BLOCK_SIZE] ) _temp[0x0e] = block[0x06]; _temp[0x0f] = block[0x03]; memcpy( block, _temp, OAES_BLOCK_SIZE ); - + return OAES_RET_SUCCESS; } @@ -351,7 +357,7 @@ static uint8_t oaes_gf_mul(uint8_t left, uint8_t right) _y = ((_x = left) >> 4) & 0x0f; _x &= 0x0f; - + switch( right ) { case 0x02: @@ -382,9 +388,9 @@ static OAES_RET oaes_mix_cols( uint8_t word[OAES_COL_LEN] ) { uint8_t _temp[OAES_COL_LEN]; - if( unlikely(NULL == word) ) + if(NULL == word) return OAES_RET_ARG1; - + _temp[0] = oaes_gf_mul(word[0], 0x02) ^ oaes_gf_mul( word[1], 0x03 ) ^ word[2] ^ word[3]; _temp[1] = word[0] ^ oaes_gf_mul( word[1], 0x02 ) ^ @@ -394,7 +400,7 @@ static OAES_RET oaes_mix_cols( uint8_t word[OAES_COL_LEN] ) _temp[3] = oaes_gf_mul( word[0], 0x03 ) ^ word[1] ^ word[2] ^ oaes_gf_mul( word[3], 0x02 ); memcpy( word, _temp, OAES_COL_LEN ); - + return OAES_RET_SUCCESS; } @@ -404,7 +410,7 @@ static OAES_RET oaes_inv_mix_cols( uint8_t word[OAES_COL_LEN] ) if( NULL == word ) return OAES_RET_ARG1; - + _temp[0] = oaes_gf_mul( word[0], 0x0e ) ^ oaes_gf_mul( word[1], 0x0b ) ^ oaes_gf_mul( word[2], 0x0d ) ^ oaes_gf_mul( word[3], 0x09 ); _temp[1] = oaes_gf_mul( word[0], 0x09 ) ^ oaes_gf_mul( word[1], 0x0e ) ^ @@ -414,7 +420,7 @@ static OAES_RET oaes_inv_mix_cols( uint8_t word[OAES_COL_LEN] ) _temp[3] = oaes_gf_mul( word[0], 0x0b ) ^ oaes_gf_mul( word[1], 0x0d ) ^ oaes_gf_mul( word[2], 0x09 ) ^ oaes_gf_mul( word[3], 0x0e ); memcpy( word, _temp, OAES_COL_LEN ); - + return OAES_RET_SUCCESS; } @@ -423,13 +429,13 @@ OAES_RET oaes_sprintf( { size_t _i, _buf_len_in; char _temp[4]; - + if( NULL == buf_len ) return OAES_RET_ARG2; _buf_len_in = *buf_len; *buf_len = data_len * 3 + data_len / OAES_BLOCK_SIZE + 1; - + if( NULL == buf ) return OAES_RET_SUCCESS; @@ -440,7 +446,7 @@ OAES_RET oaes_sprintf( return OAES_RET_ARG3; strcpy( buf, "" ); - + for( _i = 0; _i < data_len; _i++ ) { sprintf( _temp, "%02x ", data[_i] ); @@ -448,7 +454,7 @@ OAES_RET oaes_sprintf( if( _i && 0 == ( _i + 1 ) % OAES_BLOCK_SIZE ) strcat( buf, "\n" ); } - + return OAES_RET_SUCCESS; } @@ -458,7 +464,7 @@ static void oaes_get_seed( char buf[RANDSIZ + 1] ) struct timeb timer; struct tm *gmTimer; char * _test = NULL; - + ftime (&timer); gmTimer = gmtime( &timer.time ); _test = (char *) calloc( sizeof( char ), timer.millitm ); @@ -466,7 +472,7 @@ static void oaes_get_seed( char buf[RANDSIZ + 1] ) gmTimer->tm_year + 1900, gmTimer->tm_mon + 1, gmTimer->tm_mday, gmTimer->tm_hour, gmTimer->tm_min, gmTimer->tm_sec, timer.millitm, _test + timer.millitm, getpid() ); - + if( _test ) free( _test ); } @@ -477,17 +483,17 @@ static uint32_t oaes_get_seed(void) struct tm *gmTimer; char * _test = NULL; uint32_t _ret = 0; - + ftime (&timer); gmTimer = gmtime( &timer.time ); _test = (char *) calloc( sizeof( char ), timer.millitm ); - _ret = gmTimer->tm_year + 1900 + gmTimer->tm_mon + 1 + gmTimer->tm_mday + + _ret = (uint32_t)(gmTimer->tm_year + 1900 + gmTimer->tm_mon + 1 + gmTimer->tm_mday + gmTimer->tm_hour + gmTimer->tm_min + gmTimer->tm_sec + timer.millitm + - (uintptr_t) ( _test + timer.millitm ) + getpid(); + (uintptr_t) ( _test + timer.millitm ) + getpid()); if( _test ) free( _test ); - + return _ret; } #endif // OAES_HAVE_ISAAC @@ -496,26 +502,26 @@ static OAES_RET oaes_key_destroy( oaes_key ** key ) { if( NULL == *key ) return OAES_RET_SUCCESS; - + if( (*key)->data ) { free( (*key)->data ); (*key)->data = NULL; } - + if( (*key)->exp_data ) { free( (*key)->exp_data ); (*key)->exp_data = NULL; } - + (*key)->data_len = 0; (*key)->exp_data_len = 0; (*key)->num_keys = 0; (*key)->key_base = 0; free( *key ); *key = NULL; - + return OAES_RET_SUCCESS; } @@ -523,34 +529,33 @@ static OAES_RET oaes_key_expand( OAES_CTX * ctx ) { size_t _i, _j; oaes_ctx * _ctx = (oaes_ctx *) ctx; - uint8_t _temp[OAES_COL_LEN]; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + _ctx->key->key_base = _ctx->key->data_len / OAES_RKEY_LEN; _ctx->key->num_keys = _ctx->key->key_base + OAES_ROUND_BASE; - + _ctx->key->exp_data_len = _ctx->key->num_keys * OAES_RKEY_LEN * OAES_COL_LEN; _ctx->key->exp_data = (uint8_t *) calloc( _ctx->key->exp_data_len, sizeof( uint8_t )); - + if( NULL == _ctx->key->exp_data ) return OAES_RET_MEM; - + // the first _ctx->key->data_len are a direct copy memcpy( _ctx->key->exp_data, _ctx->key->data, _ctx->key->data_len ); // apply ExpandKey algorithm for remainder for( _i = _ctx->key->key_base; _i < _ctx->key->num_keys * OAES_RKEY_LEN; _i++ ) { - - memcpy( _temp, - _ctx->key->exp_data + ( _i - 1 ) * OAES_RKEY_LEN, OAES_COL_LEN ); - + uint8_t _temp[OAES_COL_LEN]; + + memcpy( _temp,_ctx->key->exp_data + ( _i - 1 ) * OAES_RKEY_LEN, OAES_COL_LEN ); + // transform key column if( 0 == _i % _ctx->key->key_base ) { @@ -566,7 +571,7 @@ static OAES_RET oaes_key_expand( OAES_CTX * ctx ) for( _j = 0; _j < OAES_COL_LEN; _j++ ) oaes_sub_byte( _temp + _j ); } - + for( _j = 0; _j < OAES_COL_LEN; _j++ ) { _ctx->key->exp_data[ _i * OAES_RKEY_LEN + _j ] = @@ -574,7 +579,7 @@ static OAES_RET oaes_key_expand( OAES_CTX * ctx ) OAES_RKEY_LEN + _j ] ^ _temp[_j]; } } - + return OAES_RET_SUCCESS; } @@ -584,40 +589,42 @@ static OAES_RET oaes_key_gen( OAES_CTX * ctx, size_t key_size ) oaes_key * _key = NULL; oaes_ctx * _ctx = (oaes_ctx *) ctx; OAES_RET _rc = OAES_RET_SUCCESS; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + _key = (oaes_key *) calloc( sizeof( oaes_key ), 1 ); - + if( NULL == _key ) return OAES_RET_MEM; - + if( _ctx->key ) oaes_key_destroy( &(_ctx->key) ); - + _key->data_len = key_size; _key->data = (uint8_t *) calloc( key_size, sizeof( uint8_t )); - - if( NULL == _key->data ) + + if (NULL == _key->data) { + free(_key); return OAES_RET_MEM; - + } + for( _i = 0; _i < key_size; _i++ ) #ifdef OAES_HAVE_ISAAC _key->data[_i] = (uint8_t) rand( _ctx->rctx ); #else _key->data[_i] = (uint8_t) rand(); #endif // OAES_HAVE_ISAAC - + _ctx->key = _key; - _rc = _rc || oaes_key_expand( ctx ); - + _rc = (OAES_RET)oaes_key_expand( ctx ); + if( _rc != OAES_RET_SUCCESS ) { oaes_key_destroy( &(_ctx->key) ); return _rc; } - + return OAES_RET_SUCCESS; } @@ -641,13 +648,13 @@ OAES_RET oaes_key_export( OAES_CTX * ctx, { size_t _data_len_in; oaes_ctx * _ctx = (oaes_ctx *) ctx; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + if( NULL == data_len ) return OAES_RET_ARG3; @@ -657,16 +664,16 @@ OAES_RET oaes_key_export( OAES_CTX * ctx, if( NULL == data ) return OAES_RET_SUCCESS; - + if( _data_len_in < *data_len ) return OAES_RET_BUF; - + // header memcpy( data, oaes_header, OAES_BLOCK_SIZE ); data[5] = 0x01; data[7] = _ctx->key->data_len; memcpy( data + OAES_BLOCK_SIZE, _ctx->key->data, _ctx->key->data_len ); - + return OAES_RET_SUCCESS; } @@ -675,13 +682,13 @@ OAES_RET oaes_key_export_data( OAES_CTX * ctx, { size_t _data_len_in; oaes_ctx * _ctx = (oaes_ctx *) ctx; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + if( NULL == data_len ) return OAES_RET_ARG3; @@ -690,12 +697,12 @@ OAES_RET oaes_key_export_data( OAES_CTX * ctx, if( NULL == data ) return OAES_RET_SUCCESS; - + if( _data_len_in < *data_len ) return OAES_RET_BUF; - + memcpy( data, _ctx->key->data, *data_len ); - + return OAES_RET_SUCCESS; } @@ -705,13 +712,13 @@ OAES_RET oaes_key_import( OAES_CTX * ctx, oaes_ctx * _ctx = (oaes_ctx *) ctx; OAES_RET _rc = OAES_RET_SUCCESS; int _key_length; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == data ) return OAES_RET_ARG2; - + switch( data_len ) { case 16 + OAES_BLOCK_SIZE: @@ -721,7 +728,7 @@ OAES_RET oaes_key_import( OAES_CTX * ctx, default: return OAES_RET_ARG3; } - + // header if( 0 != memcmp( data, oaes_header, 4 ) ) return OAES_RET_HEADER; @@ -734,7 +741,7 @@ OAES_RET oaes_key_import( OAES_CTX * ctx, default: return OAES_RET_HEADER; } - + // header type switch( data[5] ) { @@ -743,7 +750,7 @@ OAES_RET oaes_key_import( OAES_CTX * ctx, default: return OAES_RET_HEADER; } - + // options _key_length = data[7]; switch( _key_length ) @@ -755,22 +762,22 @@ OAES_RET oaes_key_import( OAES_CTX * ctx, default: return OAES_RET_HEADER; } - + if( (int)data_len != _key_length + OAES_BLOCK_SIZE ) return OAES_RET_ARG3; - + if( _ctx->key ) oaes_key_destroy( &(_ctx->key) ); - + _ctx->key = (oaes_key *) calloc( sizeof( oaes_key ), 1 ); - + if( NULL == _ctx->key ) return OAES_RET_MEM; - + _ctx->key->data_len = _key_length; _ctx->key->data = (uint8_t *) calloc( _key_length, sizeof( uint8_t )); - + if( NULL == _ctx->key->data ) { oaes_key_destroy( &(_ctx->key) ); @@ -778,14 +785,14 @@ OAES_RET oaes_key_import( OAES_CTX * ctx, } memcpy( _ctx->key->data, data + OAES_BLOCK_SIZE, _key_length ); - _rc = _rc || oaes_key_expand( ctx ); - + _rc = (OAES_RET)oaes_key_expand( ctx ); + if( _rc != OAES_RET_SUCCESS ) { oaes_key_destroy( &(_ctx->key) ); return _rc; } - + return OAES_RET_SUCCESS; } @@ -794,13 +801,13 @@ OAES_RET oaes_key_import_data( OAES_CTX * ctx, { oaes_ctx * _ctx = (oaes_ctx *) ctx; OAES_RET _rc = OAES_RET_SUCCESS; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == data ) return OAES_RET_ARG2; - + switch( data_len ) { case 16: @@ -810,19 +817,19 @@ OAES_RET oaes_key_import_data( OAES_CTX * ctx, default: return OAES_RET_ARG3; } - + if( _ctx->key ) oaes_key_destroy( &(_ctx->key) ); - + _ctx->key = (oaes_key *) calloc( sizeof( oaes_key ), 1 ); - + if( NULL == _ctx->key ) return OAES_RET_MEM; - + _ctx->key->data_len = data_len; _ctx->key->data = (uint8_t *) calloc( data_len, sizeof( uint8_t )); - + if( NULL == _ctx->key->data ) { oaes_key_destroy( &(_ctx->key) ); @@ -830,34 +837,31 @@ OAES_RET oaes_key_import_data( OAES_CTX * ctx, } memcpy( _ctx->key->data, data, data_len ); - _rc = _rc || oaes_key_expand( ctx ); - + _rc = (OAES_RET)oaes_key_expand( ctx ); + if( _rc != OAES_RET_SUCCESS ) { oaes_key_destroy( &(_ctx->key) ); return _rc; } - + return OAES_RET_SUCCESS; } OAES_CTX * oaes_alloc(void) { - oaes_ctx * _ctx = (oaes_ctx *) calloc( sizeof( oaes_ctx ), 1 ); - - if( NULL == _ctx ) + oaes_ctx * _ctx = (oaes_ctx *) calloc(sizeof(oaes_ctx), 1); + if(NULL == _ctx) return NULL; #ifdef OAES_HAVE_ISAAC { ub4 _i = 0; char _seed[RANDSIZ + 1]; - - _ctx->rctx = (randctx *) calloc( sizeof( randctx ), 1 ); - if( NULL == _ctx->rctx ) - { - free( _ctx ); + _ctx->rctx = (randctx *) calloc(sizeof(randctx), 1); + if(!_ctx->rctx) { + free(_ctx); return NULL; } @@ -881,16 +885,16 @@ OAES_CTX * oaes_alloc(void) return (OAES_CTX *) _ctx; } -OAES_RET oaes_free( OAES_CTX ** ctx ) +OAES_RET oaes_free(OAES_CTX ** ctx) { oaes_ctx ** _ctx = (oaes_ctx **) ctx; - if( NULL == _ctx ) + if(!_ctx) return OAES_RET_ARG1; - - if( NULL == *_ctx ) + + if(!*_ctx) return OAES_RET_SUCCESS; - + if( (*_ctx)->key ) oaes_key_destroy( &((*_ctx)->key) ); @@ -901,19 +905,18 @@ OAES_RET oaes_free( OAES_CTX ** ctx ) (*_ctx)->rctx = NULL; } #endif // OAES_HAVE_ISAAC - + free( *_ctx ); *_ctx = NULL; return OAES_RET_SUCCESS; } -OAES_RET oaes_set_option( OAES_CTX * ctx, - OAES_OPTION option, const void * value ) +OAES_RET oaes_set_option(OAES_CTX * ctx, OAES_OPTION option, const void * value) { size_t _i; oaes_ctx * _ctx = (oaes_ctx *) ctx; - + if( NULL == _ctx ) return OAES_RET_ARG1; @@ -972,24 +975,23 @@ OAES_RET oaes_set_option( OAES_CTX * ctx, return OAES_RET_SUCCESS; } -static OAES_RET oaes_encrypt_block( - OAES_CTX * ctx, uint8_t * c, size_t c_len ) +static OAES_RET oaes_encrypt_block(OAES_CTX * ctx, uint8_t * c, size_t c_len) { size_t _i, _j; oaes_ctx * _ctx = (oaes_ctx *) ctx; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == c ) return OAES_RET_ARG2; - + if( c_len != OAES_BLOCK_SIZE ) return OAES_RET_ARG3; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + #ifdef OAES_DEBUG if( _ctx->step_cb ) _ctx->step_cb( c, "input", 1, NULL ); @@ -998,7 +1000,7 @@ static OAES_RET oaes_encrypt_block( // AddRoundKey(State, K0) for( _i = 0; _i < c_len; _i++ ) c[_i] = c[_i] ^ _ctx->key->exp_data[_i]; - + #ifdef OAES_DEBUG if( _ctx->step_cb ) { @@ -1021,7 +1023,7 @@ static OAES_RET oaes_encrypt_block( // ShiftRows(state) oaes_shift_rows( c ); - + #ifdef OAES_DEBUG if( _ctx->step_cb ) _ctx->step_cb( c, "s_row", _i, NULL ); @@ -1032,7 +1034,7 @@ static OAES_RET oaes_encrypt_block( oaes_mix_cols( c + 4 ); oaes_mix_cols( c + 8 ); oaes_mix_cols( c + 12 ); - + #ifdef OAES_DEBUG if( _ctx->step_cb ) _ctx->step_cb( c, "m_col", _i, NULL ); @@ -1053,11 +1055,11 @@ static OAES_RET oaes_encrypt_block( #endif // OAES_DEBUG } - + // SubBytes(state) for( _i = 0; _i < c_len; _i++ ) oaes_sub_byte( c + _i ); - + #ifdef OAES_DEBUG if( _ctx->step_cb ) _ctx->step_cb( c, "s_box", _ctx->key->num_keys - 1, NULL ); @@ -1089,24 +1091,23 @@ static OAES_RET oaes_encrypt_block( return OAES_RET_SUCCESS; } -static OAES_RET oaes_decrypt_block( - OAES_CTX * ctx, uint8_t * c, size_t c_len ) +static OAES_RET oaes_decrypt_block(OAES_CTX * ctx, uint8_t * c, size_t c_len) { size_t _i, _j; oaes_ctx * _ctx = (oaes_ctx *) ctx; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == c ) return OAES_RET_ARG2; - + if( c_len != OAES_BLOCK_SIZE ) return OAES_RET_ARG3; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + #ifdef OAES_DEBUG if( _ctx->step_cb ) _ctx->step_cb( c, "iinput", _ctx->key->num_keys - 1, NULL ); @@ -1140,7 +1141,7 @@ static OAES_RET oaes_decrypt_block( // InvSubBytes(state) for( _j = 0; _j < c_len; _j++ ) oaes_inv_sub_byte( c + _j ); - + #ifdef OAES_DEBUG if( _ctx->step_cb ) _ctx->step_cb( c, "is_box", _i, NULL ); @@ -1150,7 +1151,7 @@ static OAES_RET oaes_decrypt_block( for( _j = 0; _j < c_len; _j++ ) c[_j] = c[_j] ^ _ctx->key->exp_data[_i * OAES_RKEY_LEN * OAES_COL_LEN + _j]; - + #ifdef OAES_DEBUG if( _ctx->step_cb ) { @@ -1193,7 +1194,7 @@ static OAES_RET oaes_decrypt_block( // AddRoundKey(state, w[0, Nb-1]) for( _i = 0; _i < c_len; _i++ ) c[_i] = c[_i] ^ _ctx->key->exp_data[_i]; - + #ifdef OAES_DEBUG if( _ctx->step_cb ) { @@ -1205,8 +1206,7 @@ static OAES_RET oaes_decrypt_block( return OAES_RET_SUCCESS; } -OAES_RET oaes_encrypt( OAES_CTX * ctx, - const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len ) +OAES_RET oaes_encrypt(OAES_CTX * ctx, const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len) { size_t _i, _j, _c_len_in, _c_data_len; size_t _pad_len = m_len % OAES_BLOCK_SIZE == 0 ? @@ -1214,16 +1214,16 @@ OAES_RET oaes_encrypt( OAES_CTX * ctx, oaes_ctx * _ctx = (oaes_ctx *) ctx; OAES_RET _rc = OAES_RET_SUCCESS; uint8_t _flags = _pad_len ? OAES_FLAG_PAD : 0; - + if( NULL == _ctx ) return OAES_RET_ARG1; - + if( NULL == m ) return OAES_RET_ARG2; - + if( NULL == c_len ) return OAES_RET_ARG5; - + _c_len_in = *c_len; // data + pad _c_data_len = m_len + _pad_len; @@ -1232,13 +1232,13 @@ OAES_RET oaes_encrypt( OAES_CTX * ctx, if( NULL == c ) return OAES_RET_SUCCESS; - + if( _c_len_in < *c_len ) return OAES_RET_BUF; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + // header memcpy(c, oaes_header, OAES_BLOCK_SIZE ); memcpy(c + 6, &_ctx->options, sizeof(_ctx->options)); @@ -1247,18 +1247,18 @@ OAES_RET oaes_encrypt( OAES_CTX * ctx, memcpy(c + OAES_BLOCK_SIZE, _ctx->iv, OAES_BLOCK_SIZE ); // data memcpy(c + 2 * OAES_BLOCK_SIZE, m, m_len ); - + for( _i = 0; _i < _c_data_len; _i += OAES_BLOCK_SIZE ) { uint8_t _block[OAES_BLOCK_SIZE]; size_t _block_size = min( m_len - _i, OAES_BLOCK_SIZE ); memcpy( _block, c + 2 * OAES_BLOCK_SIZE + _i, _block_size ); - + // insert pad for( _j = 0; _j < OAES_BLOCK_SIZE - _block_size; _j++ ) - _block[ _block_size + _j ] = _j + 1; - + _block[ _block_size + _j ] = (uint8_t)_j + 1; + // CBC if( _ctx->options & OAES_OPTION_CBC ) { @@ -1266,19 +1266,18 @@ OAES_RET oaes_encrypt( OAES_CTX * ctx, _block[_j] = _block[_j] ^ _ctx->iv[_j]; } - _rc = _rc || + _rc = _rc ? _rc : oaes_encrypt_block( ctx, _block, OAES_BLOCK_SIZE ); memcpy( c + 2 * OAES_BLOCK_SIZE + _i, _block, OAES_BLOCK_SIZE ); - + if( _ctx->options & OAES_OPTION_CBC ) memcpy( _ctx->iv, _block, OAES_BLOCK_SIZE ); } - + return _rc; } -OAES_RET oaes_decrypt( OAES_CTX * ctx, - const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len ) +OAES_RET oaes_decrypt(OAES_CTX * ctx, const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len) { size_t _i, _j, _m_len_in; oaes_ctx * _ctx = (oaes_ctx *) ctx; @@ -1286,31 +1285,31 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, uint8_t _iv[OAES_BLOCK_SIZE]; uint8_t _flags; OAES_OPTION _options; - + if( NULL == ctx ) return OAES_RET_ARG1; - + if( NULL == c ) return OAES_RET_ARG2; - + if( c_len % OAES_BLOCK_SIZE ) return OAES_RET_ARG3; - + if( NULL == m_len ) return OAES_RET_ARG5; - + _m_len_in = *m_len; *m_len = c_len - 2 * OAES_BLOCK_SIZE; - + if( NULL == m ) return OAES_RET_SUCCESS; - + if( _m_len_in < *m_len ) return OAES_RET_BUF; - + if( NULL == _ctx->key ) return OAES_RET_NOKEY; - + // header if( 0 != memcmp( c, oaes_header, 4 ) ) return OAES_RET_HEADER; @@ -1323,7 +1322,7 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, default: return OAES_RET_HEADER; } - + // header type switch( c[5] ) { @@ -1332,7 +1331,7 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, default: return OAES_RET_HEADER; } - + // options memcpy(&_options, c + 6, sizeof(_options)); // validate that all options are valid @@ -1350,7 +1349,7 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, return OAES_RET_HEADER; if( _options == OAES_OPTION_NONE ) return OAES_RET_HEADER; - + // flags memcpy(&_flags, c + 8, sizeof(_flags)); // validate that all flags are valid @@ -1363,15 +1362,15 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, memcpy( _iv, c + OAES_BLOCK_SIZE, OAES_BLOCK_SIZE); // data + pad memcpy( m, c + 2 * OAES_BLOCK_SIZE, *m_len ); - + for( _i = 0; _i < *m_len; _i += OAES_BLOCK_SIZE ) { if( ( _options & OAES_OPTION_CBC ) && _i > 0 ) memcpy( _iv, c + OAES_BLOCK_SIZE + _i, OAES_BLOCK_SIZE ); - - _rc = _rc || + + _rc = _rc ? _rc : oaes_decrypt_block( ctx, m + _i, min( *m_len - _i, OAES_BLOCK_SIZE ) ); - + // CBC if( _options & OAES_OPTION_CBC ) { @@ -1379,7 +1378,7 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, m[ _i + _j ] = m[ _i + _j ] ^ _iv[_j]; } } - + // remove pad if( _flags & OAES_FLAG_PAD ) { @@ -1399,59 +1398,56 @@ OAES_RET oaes_decrypt( OAES_CTX * ctx, else return OAES_RET_HEADER; } - + return OAES_RET_SUCCESS; } - -OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ) +OAES_API OAES_RET oaes_encryption_round(const uint8_t * key, uint8_t * c) { - size_t _i; + size_t _i; - if( unlikely(NULL == key) ) - return OAES_RET_ARG1; + if(!key) + return OAES_RET_ARG1; - if( unlikely(NULL == c) ) - return OAES_RET_ARG2; + if(!c) + return OAES_RET_ARG2; - // SubBytes(state) - for( _i = 0; _i < OAES_BLOCK_SIZE; _i++ ) - oaes_sub_byte( c + _i ); + // SubBytes(state) + for(_i = 0; _i < OAES_BLOCK_SIZE; _i++) + oaes_sub_byte( c + _i ); - // ShiftRows(state) - oaes_shift_rows( c ); + // ShiftRows(state) + oaes_shift_rows( c ); - // MixColumns(state) - oaes_mix_cols( c ); - oaes_mix_cols( c + 4 ); - oaes_mix_cols( c + 8 ); - oaes_mix_cols( c + 12 ); + // MixColumns(state) + oaes_mix_cols( c ); + oaes_mix_cols( c + 4 ); + oaes_mix_cols( c + 8 ); + oaes_mix_cols( c + 12 ); - // AddRoundKey(State, key) - for( _i = 0; _i < OAES_BLOCK_SIZE; _i++ ) - c[_i] ^= key[_i]; + // AddRoundKey(State, key) + for( _i = 0; _i < OAES_BLOCK_SIZE; _i++ ) + c[_i] ^= key[_i]; - return OAES_RET_SUCCESS; + return OAES_RET_SUCCESS; } -OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ) +OAES_API OAES_RET oaes_pseudo_encrypt_ecb(OAES_CTX * ctx, uint8_t * c) { - size_t _i; - oaes_ctx * _ctx = (oaes_ctx *) ctx; + oaes_ctx * _ctx = (oaes_ctx *) ctx; + size_t _i; - if( unlikely(NULL == _ctx) ) - return OAES_RET_ARG1; + if(!_ctx) + return OAES_RET_ARG1; - if( unlikely(NULL == c) ) - return OAES_RET_ARG2; + if(!c) + return OAES_RET_ARG2; - if( unlikely(NULL == _ctx->key) ) - return OAES_RET_NOKEY; + if(!_ctx->key) + return OAES_RET_NOKEY; - for ( _i = 0; _i < 10; ++_i ) - { - oaes_encryption_round( &_ctx->key->exp_data[_i * OAES_RKEY_LEN * OAES_COL_LEN], c ); - } + for (_i = 0; _i < 10; _i++) + oaes_encryption_round(&_ctx->key->exp_data[_i * OAES_RKEY_LEN * OAES_COL_LEN], c); - return OAES_RET_SUCCESS; + return OAES_RET_SUCCESS; } diff --git a/crypto/oaes_lib.h b/crypto/oaes_lib.h index a22bbf4..8ed0735 100755 --- a/crypto/oaes_lib.h +++ b/crypto/oaes_lib.h @@ -32,10 +32,7 @@ #define _OAES_LIB_H #include - -#ifdef __cplusplus -extern "C" { -#endif +#include #ifdef _WIN32 # ifdef OAES_SHARED @@ -207,8 +204,4 @@ OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ); OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ); -#ifdef __cplusplus -} -#endif - #endif // _OAES_LIB_H diff --git a/cryptonight.c b/cryptonight-cpu.cpp old mode 100755 new mode 100644 similarity index 67% rename from cryptonight.c rename to cryptonight-cpu.cpp index c37e6df..279b9dc --- a/cryptonight.c +++ b/cryptonight-cpu.cpp @@ -4,8 +4,11 @@ // Modified for CPUminer by Lucas Jones +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else #include "cpuminer-config.h" -#include "miner.h" +#endif #include "crypto/oaes_lib.h" #include "crypto/c_keccak.h" #include "crypto/c_groestl.h" @@ -14,30 +17,56 @@ #include "crypto/c_skein.h" #include "cryptonight.h" -struct cryptonight_ctx { - uint8_t long_state[MEMORY]; - union cn_slow_hash_state state; - uint8_t text[INIT_SIZE_BYTE]; - uint8_t a[AES_BLOCK_SIZE]; - uint8_t b[AES_BLOCK_SIZE]; - uint8_t c[AES_BLOCK_SIZE]; - oaes_ctx* aes_ctx; +uint64_t MEMORY = 1ULL << 21; // 2 MiB / 2097152 B +uint32_t ITER = 1 << 20; // 1048576 + +struct cryptonight_ctx +{ + uint8_t *long_state; + union cn_slow_hash_state state; + uint8_t text[INIT_SIZE_BYTE]; + uint8_t a[AES_BLOCK_SIZE]; + uint8_t b[AES_BLOCK_SIZE]; + uint8_t c[AES_BLOCK_SIZE]; + oaes_ctx* aes_ctx; }; +#define VARIANT1_1(p) \ + if (variant == 2 && opt_algo == algo_stellite) \ + { \ + const uint8_t tmp = ((const uint8_t*)(p))[11]; \ + static const uint32_t table = 0x75312; \ + const uint8_t index = (((tmp >> 4) & 6) | (tmp & 1)) << 1; \ + ((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \ + } \ + else if(variant > 0){ \ + const uint8_t tmp = ((const uint8_t*)(p))[11]; \ + static const uint32_t table = 0x75310; \ + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ + ((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \ + } + +#define VARIANT1_INIT() \ + if (variant > 0 && len < 43) \ + { \ + return 0; \ + } \ + const uint64_t tweak1_2 = variant > 0 ? *((const uint64_t*) (((const uint8_t*)input) + 35)) ^ ctx->state.hs.w[24] : 0 + static void do_blake_hash(const void* input, size_t len, char* output) { - blake256_hash((uint8_t*)output, input, len); + blake256_hash((uint8_t*)output, (const uint8_t*)input, len); } void do_groestl_hash(const void* input, size_t len, char* output) { - groestl(input, len * 8, (uint8_t*)output); + groestl((const BitSequence*)input, len * 8, (uint8_t*)output); } static void do_jh_hash(const void* input, size_t len, char* output) { - int r = jh_hash(HASH_SIZE * 8, input, 8 * len, (uint8_t*)output); + int r = jh_hash(HASH_SIZE * 8, (const BitSequence*)input, 8 * len, (uint8_t*)output); } static void do_skein_hash(const void* input, size_t len, char* output) { - int r = skein_hash(8 * HASH_SIZE, input, 8 * len, (uint8_t*)output); + int r = skein_hash(8 * HASH_SIZE, (const SkeinBitSequence*)input, 8 * len, (uint8_t*)output); } void hash_permutation(union hash_state *state) { @@ -45,13 +74,11 @@ void hash_permutation(union hash_state *state) { } void hash_process(union hash_state *state, const uint8_t *buf, size_t count) { - keccak1600(buf, count, (uint8_t*)state); + keccak1600(buf, (int)count, (uint8_t*)state); } -extern int fast_aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey); -extern int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey); -extern int aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey); -extern int fast_aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey); +extern void aesb_single_round(const uint8_t *in, uint8_t*out, uint8_t *expandedKey); +extern void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey); static void (* const extra_hashes[4])(const void *, size_t, char *) = { do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash @@ -105,14 +132,14 @@ static void mul_sum_dst(const uint8_t* a, const uint8_t* b, const uint8_t* c, ui ((uint64_t*) dst)[0] += ((uint64_t*) c)[0]; } -static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst) { +static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst, const int variant, const uint64_t tweak1_2) { uint64_t hi, lo = mul128(((uint64_t*) a)[0], ((uint64_t*) dst)[0], &hi) + ((uint64_t*) c)[1]; hi += ((uint64_t*) c)[0]; ((uint64_t*) c)[0] = ((uint64_t*) dst)[0] ^ hi; ((uint64_t*) c)[1] = ((uint64_t*) dst)[1] ^ lo; ((uint64_t*) dst)[0] = hi; - ((uint64_t*) dst)[1] = lo; + ((uint64_t*) dst)[1] = variant > 0 ? lo ^ tweak1_2 : lo; } static void copy_block(uint8_t* dst, const uint8_t* src) { @@ -130,12 +157,14 @@ static void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) { ((uint64_t*) dst)[1] = ((uint64_t*) a)[1] ^ ((uint64_t*) b)[1]; } -void cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cryptonight_ctx* ctx) { +int cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cryptonight_ctx* ctx, int variant, algo_t opt_algo) { size_t i, j; hash_process(&ctx->state.hs, (const uint8_t*) input, len); ctx->aes_ctx = (oaes_ctx*) oaes_alloc(); memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE); + VARIANT1_INIT(); + oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE); for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) { #undef RND @@ -158,14 +187,16 @@ void cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cr j = e2i(ctx->a) * AES_BLOCK_SIZE; aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a); xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]); + VARIANT1_1(&ctx->long_state[j]); - mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c) * AES_BLOCK_SIZE]); + mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c) * AES_BLOCK_SIZE], variant, tweak1_2); j = e2i(ctx->a) * AES_BLOCK_SIZE; aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a); xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); + VARIANT1_1(&ctx->long_state[j]); - mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b) * AES_BLOCK_SIZE]); + mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b) * AES_BLOCK_SIZE], variant, tweak1_2); } memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE); @@ -185,12 +216,29 @@ void cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cr } memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE); hash_permutation(&ctx->state.hs); - extra_hashes[ctx->state.hs.b[0] & 3](&ctx->state, 200, output); + extra_hashes[ctx->state.hs.b[0] & 3](&ctx->state, 200, (char *)output); oaes_free((OAES_CTX **) &ctx->aes_ctx); + return 1; } -void cryptonight_hash(void* output, const void* input, size_t len) { +extern void proper_exit(int); + +int cryptonight_hash(void* output, const void* input, size_t len, int variant, algo_t opt_algo) +{ struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx)); - cryptonight_hash_ctx(output, input, len, ctx); - free(ctx); + if (ctx == NULL) + { + applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); + proper_exit(1); + } + ctx->long_state = (uint8_t*)malloc(MEMORY); + if (ctx->long_state == NULL) + { + applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); + proper_exit(1); + } + int rc = cryptonight_hash_ctx(output, input, len, ctx, variant, opt_algo); + free(ctx->long_state); + free(ctx); + return rc; } diff --git a/cryptonight.h b/cryptonight.h index 3977d74..2cff86a 100755 --- a/cryptonight.h +++ b/cryptonight.h @@ -1,129 +1,156 @@ - -#define MEMORY (1 << 21) // 2 MiB / 2097152 B -#define ITER (1 << 20) // 1048576 -#define AES_BLOCK_SIZE 16 -#define AES_KEY_SIZE 32 -#define INIT_SIZE_BLK 8 -#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B - -#define AES_RKEY_LEN 4 -#define AES_COL_LEN 4 -#define AES_ROUND_BASE 7 - -#ifndef HASH_SIZE -#define HASH_SIZE 32 -#endif - -#ifndef HASH_DATA_AREA -#define HASH_DATA_AREA 136 -#endif - -#define hi_dword(x) (x >> 32) -#define lo_dword(x) (x & 0xFFFFFFFF) - -#define C32(x) ((uint32_t)(x ## U)) -#define T32(x) ((x) & C32(0xFFFFFFFF)) - -#ifndef ROTL64 - #if __CUDA_ARCH__ >= 350 - __forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) { - uint2 result; - if(offset >= 32) { - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); - } else { - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); - } - return __double_as_longlong(__hiloint2double(result.y, result.x)); - } - #define ROTL64(x, n) (cuda_ROTL64(x, n)) - #else - #define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) - #endif -#endif - -#ifndef ROTL32 - #if __CUDA_ARCH__ < 350 - #define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n)))) - #else - #define ROTL32(x, n) __funnelshift_l( (x), (x), (n) ) - #endif -#endif - -#ifndef ROTR32 - #if __CUDA_ARCH__ < 350 - #define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) - #else - #define ROTR32(x, n) __funnelshift_r( (x), (x), (n) ) - #endif -#endif - -#define MEMSET8(dst,what,cnt) { \ - int i_memset8; \ - uint64_t *out_memset8 = (uint64_t *)(dst); \ - for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \ - out_memset8[i_memset8] = (what); } - -#define MEMSET4(dst,what,cnt) { \ - int i_memset4; \ - uint32_t *out_memset4 = (uint32_t *)(dst); \ - for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \ - out_memset4[i_memset4] = (what); } - -#define MEMCPY8(dst,src,cnt) { \ - int i_memcpy8; \ - uint64_t *in_memcpy8 = (uint64_t *)(src); \ - uint64_t *out_memcpy8 = (uint64_t *)(dst); \ - for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \ - out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; } - -#define MEMCPY4(dst,src,cnt) { \ - int i_memcpy4; \ - uint32_t *in_memcpy4 = (uint32_t *)(src); \ - uint32_t *out_memcpy4 = (uint32_t *)(dst); \ - for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \ - out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; } - -#define XOR_BLOCKS(a,b) { \ - ((uint64_t *)a)[0] ^= ((uint64_t *)b)[0]; \ - ((uint64_t *)a)[1] ^= ((uint64_t *)b)[1]; } - -#define XOR_BLOCKS_DST(x,y,z) { \ - ((uint64_t *)z)[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \ - ((uint64_t *)z)[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; } - -#define MUL_SUM_XOR_DST(a,c,dst) { \ - uint64_t hi, lo = cuda_mul128(((uint64_t *)a)[0], ((uint64_t *)dst)[0], &hi) + ((uint64_t *)c)[1]; \ - hi += ((uint64_t *)c)[0]; \ - ((uint64_t *)c)[0] = ((uint64_t *)dst)[0] ^ hi; \ - ((uint64_t *)c)[1] = ((uint64_t *)dst)[1] ^ lo; \ - ((uint64_t *)dst)[0] = hi; \ - ((uint64_t *)dst)[1] = lo; } - -#define E2I(x) ((size_t)(((*((uint64_t*)(x)) >> 4) & 0x1ffff))) - -union hash_state { - uint8_t b[200]; - uint64_t w[25]; -}; - -union cn_slow_hash_state { - union hash_state hs; - struct { - uint8_t k[64]; - uint8_t init[INIT_SIZE_BYTE]; - }; -}; - -struct cryptonight_gpu_ctx { - uint32_t state[50]; - uint32_t a[4]; - uint32_t b[4]; - uint32_t key1[40]; - uint32_t key2[40]; - uint32_t text[32]; -}; - -void hash_permutation(union hash_state *state); -void hash_process(union hash_state *state, const uint8_t *buf, size_t count); +#pragma once +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else +#include "cpuminer-config.h" +#endif + +#include +#include +#include +#include "miner.h" +#include + +#ifdef __INTELLISENSE__ +#define __CUDA_ARCH__ 610 +/* avoid red underlining */ + +struct uint3 +{ + unsigned int x, y, z; +}; + +struct uint3 threadIdx; +struct uint3 blockIdx; +struct uint3 blockDim; +#define __funnelshift_r(a,b,c) 1 +#define __syncthreads() +#define asm(x) +#define SHFL(a,b,c) 1 +#define __umul64hi(x, y) (x*y) +#endif + +#define AES_BLOCK_SIZE 16 +#define AES_KEY_SIZE 32 +#define INIT_SIZE_BLK 8 +#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B + +#define AES_RKEY_LEN 4 +#define AES_COL_LEN 4 +#define AES_ROUND_BASE 7 + +#ifndef HASH_SIZE +#define HASH_SIZE 32 +#endif + +#ifndef HASH_DATA_AREA +#define HASH_DATA_AREA 136 +#endif + +#define hi_dword(x) (x >> 32) +#define lo_dword(x) (x & 0xFFFFFFFF) + +#define C32(x) ((uint32_t)(x ## U)) +#define T32(x) ((x) & C32(0xFFFFFFFF)) + +#ifndef ROTL64 + #if __CUDA_ARCH__ >= 350 + __forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) { + uint2 result; + if(offset >= 32) { + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); + } else { + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); + } + return __double_as_longlong(__hiloint2double(result.y, result.x)); + } + #define ROTL64(x, n) (cuda_ROTL64(x, n)) + #else + #define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) + #endif +#endif + +#ifndef ROTL32 + #if __CUDA_ARCH__ < 350 + #define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n)))) + #else + #define ROTL32(x, n) __funnelshift_l( (x), (x), (n) ) + #endif +#endif + +#ifndef ROTR32 + #if __CUDA_ARCH__ < 350 + #define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) + #else + #define ROTR32(x, n) __funnelshift_r( (x), (x), (n) ) + #endif +#endif + +#define MEMSET8(dst,what,cnt) { \ + int i_memset8; \ + uint64_t *out_memset8 = (uint64_t *)(dst); \ + for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \ + out_memset8[i_memset8] = (what); } + +#define MEMSET4(dst,what,cnt) { \ + int i_memset4; \ + uint32_t *out_memset4 = (uint32_t *)(dst); \ + for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \ + out_memset4[i_memset4] = (what); } + +#define MEMCPY8(dst,src,cnt) { \ + int i_memcpy8; \ + uint64_t *in_memcpy8 = (uint64_t *)(src); \ + uint64_t *out_memcpy8 = (uint64_t *)(dst); \ + for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \ + out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; } + +#define MEMCPY4(dst,src,cnt) { \ + int i_memcpy4; \ + uint32_t *in_memcpy4 = (uint32_t *)(src); \ + uint32_t *out_memcpy4 = (uint32_t *)(dst); \ + for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \ + out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; } + +#define XOR_BLOCKS(a,b) \ + ((uint64_t *)a)[0] ^= ((uint64_t *)b)[0]; \ + ((uint64_t *)a)[1] ^= ((uint64_t *)b)[1]; + +#define XOR_BLOCKS_DST(x,y,z) \ + ((uint64_t *)(z))[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \ + ((uint64_t *)(z))[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; + +#define XOR_BLOCKS_DST2(x,y,z) \ + ((uint64_t *)z)[0] = (x)[0] ^ (y)[0]; \ + ((uint64_t *)z)[1] = (x)[1] ^ (y)[1]; + +#define E2I(x) ((size_t)(((*((uint64_t*)(x)) >> 4) & 0x1ffff))) + +union hash_state { + uint8_t b[200]; + uint64_t w[25]; +}; + +union cn_slow_hash_state { + union hash_state hs; + struct { + uint8_t k[64]; + uint8_t init[INIT_SIZE_BYTE]; + }; +}; + +/* +struct cryptonight_gpu_ctx { + uint32_t state[50]; + uint32_t a[4]; + uint32_t b[4]; + uint32_t key1[40]; + uint32_t key2[40]; + uint32_t text[32]; +}; +*/ + +void hash_permutation(union hash_state *state); +void hash_process(union hash_state *state, const uint8_t *buf, size_t count); diff --git a/cryptonight/cryptonight.cu b/cryptonight/cryptonight.cu index 9959a60..85800d0 100755 --- a/cryptonight/cryptonight.cu +++ b/cryptonight/cryptonight.cu @@ -5,189 +5,345 @@ #include "cuda.h" #include "cuda_runtime.h" -extern "C" -{ +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else #include "cpuminer-config.h" -#include "miner.h" +#endif #include "cryptonight.h" -} -extern char *device_name[8]; -extern int device_arch[8][2]; -extern int device_mpcount[8]; -extern int device_map[8]; -extern int device_config[8][2]; +extern uint64_t MEMORY; +extern uint32_t ITER; +extern void proper_exit(int); + +void cryptonight_core_cpu_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint32_t *d_ctx_tweak1_2, algo_t opt_algo); + +void cryptonight_extra_cpu_setData(int thr_id, const void *data, const void *pTargetIn); +void cryptonight_extra_cpu_init(int thr_id); +void cryptonight_extra_cpu_prepare(int thr_id, int threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint32_t *d_ctx_tweak1_2); +void cryptonight_extra_cpu_final(int thr_id, int threads, uint32_t startNonce, uint32_t *nonce, uint32_t *d_ctx_state); -// Zahl der CUDA Devices im System bestimmen -extern "C" int cuda_num_devices() +extern char *device_name[MAX_GPU]; +extern int device_arch[MAX_GPU][2]; +extern int device_mpcount[MAX_GPU]; +extern int device_map[MAX_GPU]; +extern int device_config[MAX_GPU][2]; +extern algo_t opt_algo; +extern int forkversion; + +void exit_if_cudaerror(int thr_id, const char *file, int line) { - int version; - cudaError_t err = cudaDriverGetVersion(&version); - if (err != cudaSuccess) - { - applog(LOG_ERR, "Unable to query CUDA driver version! Is an nVidia driver installed?"); - exit(1); - } - - int maj = version / 1000, min = version % 100; // same as in deviceQuery sample - if (maj < 5 || (maj == 5 && min < 5)) - { - applog(LOG_ERR, "Driver does not support CUDA %d.%d API! Update your nVidia driver!", 5, 5); - exit(1); - } - - int GPU_N; - err = cudaGetDeviceCount(&GPU_N); - if (err != cudaSuccess) - { - applog(LOG_ERR, "Unable to query number of CUDA devices! Is an nVidia driver installed?"); - exit(1); - } - return GPU_N; + cudaError_t err = cudaGetLastError(); + if (err != cudaSuccess) + { + printf("\nGPU %d: %s\n%s line %d\n", device_map[thr_id], cudaGetErrorString(err), file, line); + proper_exit(1); + } +} + +//Number of CUDA Devices on the system +int cuda_num_devices() +{ + int version; + cudaError_t err = cudaDriverGetVersion(&version); + if(err != cudaSuccess) + { + applog(LOG_ERR, "Unable to query CUDA driver version! Is an nVidia driver installed?"); + exit(1); + } + + if(version < CUDART_VERSION) + { + applog(LOG_ERR, "Driver does not support CUDA %d.%d API! Update your nVidia driver!", CUDART_VERSION / 1000, (CUDART_VERSION % 1000) / 10); + exit(1); + } + + int GPU_N; + err = cudaGetDeviceCount(&GPU_N); + if(err != cudaSuccess) + { + if(err != cudaErrorNoDevice) + applog(LOG_ERR, "No CUDA device found!"); + else + applog(LOG_ERR, "Unable to query number of CUDA devices!"); + exit(1); + } + return GPU_N; } +void cuda_set_device_config(int GPU_N) +{ + for (int i = 0; i < GPU_N; i++) + { + cudaError_t err; -extern "C" void cuda_deviceinfo() + err = cudaSetDevice(device_map[i]); + if (err != cudaSuccess) + { + applog(LOG_ERR, "GPU %d: %s", device_map[i], cudaGetErrorString(err)); + exit(EXIT_FAILURE); + } + err = cudaDeviceReset(); + if (err != cudaSuccess) + { + applog(LOG_ERR, "GPU %d: %s", device_map[i], cudaGetErrorString(err)); + exit(EXIT_FAILURE); + } + if (device_config[i][0] == 0) + { + int len = strlen(device_name[i]); + device_config[i][0] = device_mpcount[i] * 4; + if(len > 0 && device_name[i][len - 1] == 'M') // mobile gpu + device_config[i][1] = 8; + else + device_config[i][1] = 32; + + if (device_arch[i][0] < 6) + { + //Try to stay under 950 threads ( 1900MiB memory per for hashes ) + while (device_config[i][0] * device_config[i][1] >= 950 && device_config[i][0] > device_mpcount[i]) + { + device_config[i][0] -= device_mpcount[i]; + } + } + //Stay within 85% of the available RAM + size_t freeMemory = 0; + size_t totalMemoery = 0; + + err = cudaMemGetInfo(&freeMemory, &totalMemoery); + if (err == cudaSuccess) + { + freeMemory = (freeMemory * size_t(85)) / 100; + while (device_config[i][0] > device_mpcount[i]) + { + + if (freeMemory > size_t(device_config[i][0]) * size_t(device_config[i][1]) * (MEMORY + 688)) + { + break; + } + else + { + device_config[i][0] -= device_mpcount[i]; + } + } + } + else + { + applog(LOG_ERR, "GPU #%d: CUDA error: %s", device_map[i], cudaGetErrorString(err)); + exit(1); + } + } + } +} +void cuda_deviceinfo(int GPU_N) { - cudaError_t err; - int GPU_N; - err = cudaGetDeviceCount(&GPU_N); - if (err != cudaSuccess) - { - applog(LOG_ERR, "Unable to query number of CUDA devices! Is an nVidia driver installed?"); - exit(1); - } - - for (int i=0; i < GPU_N; i++) - { - cudaDeviceProp props; - cudaGetDeviceProperties(&props, device_map[i]); - - device_name[i] = strdup(props.name); - device_mpcount[i] = props.multiProcessorCount; - device_arch[i][0] = props.major; - device_arch[i][1] = props.minor; - } + cudaError_t err; + for(int i = 0; i < GPU_N; i++) + { + cudaDeviceProp props; + err = cudaGetDeviceProperties(&props, device_map[i]); + if(err != cudaSuccess) + { + printf("\nGPU %d: %s\n%s line %d\n", device_map[i], cudaGetErrorString(err), __FILE__, __LINE__); + exit(1); + } + + device_name[i] = strdup(props.name); + device_mpcount[i] = props.multiProcessorCount; + device_arch[i][0] = props.major; + device_arch[i][1] = props.minor; + } } static bool substringsearch(const char *haystack, const char *needle, int &match) { - int hlen = strlen(haystack); - int nlen = strlen(needle); - for (int i=0; i < hlen; ++i) - { - if (haystack[i] == ' ') continue; - int j=0, x = 0; - while(j < nlen) - { - if (haystack[i+x] == ' ') {++x; continue;} - if (needle[j] == ' ') {++j; continue;} - if (needle[j] == '#') return ++match == needle[j+1]-'0'; - if (tolower(haystack[i+x]) != tolower(needle[j])) break; - ++j; ++x; - } - if (j == nlen) return true; - } - return false; + int hlen = (int)strlen(haystack); + int nlen = (int)strlen(needle); + for(int i = 0; i < hlen; ++i) + { + if(haystack[i] == ' ') continue; + int j = 0, x = 0; + while(j < nlen) + { + if(haystack[i + x] == ' ') + { + ++x; continue; + } + if(needle[j] == ' ') + { + ++j; continue; + } + if(needle[j] == '#') return ++match == needle[j + 1] - '0'; + if(tolower(haystack[i + x]) != tolower(needle[j])) break; + ++j; ++x; + } + if(j == nlen) return true; + } + return false; } -// CUDA Gerät nach Namen finden (gibt Geräte-Index zurück oder -1) -extern "C" int cuda_finddevice(char *name) +int cuda_finddevice(char *name) { - int num = cuda_num_devices(); - int match = 0; - for (int i=0; i < num; ++i) - { - cudaDeviceProp props; - if (cudaGetDeviceProperties(&props, i) == cudaSuccess) - if (substringsearch(props.name, name, match)) return i; - } - return -1; + int num = cuda_num_devices(); + int match = 0; + for(int i = 0; i < num; ++i) + { + cudaDeviceProp props; + if(cudaGetDeviceProperties(&props, i) == cudaSuccess) + if(substringsearch(props.name, name, match)) return i; + } + return -1; } -static uint32_t *d_long_state[8]; -static struct cryptonight_gpu_ctx *d_ctx[8]; +static uint32_t *d_long_state[MAX_GPU]; +static uint32_t *d_ctx_state[MAX_GPU]; +static uint32_t *d_ctx_a[MAX_GPU]; +static uint32_t *d_ctx_b[MAX_GPU]; +static uint32_t *d_ctx_key1[MAX_GPU]; +static uint32_t *d_ctx_key2[MAX_GPU]; +static uint32_t *d_ctx_text[MAX_GPU]; +static uint32_t *d_ctx_tweak1_2[MAX_GPU]; extern bool opt_benchmark; +extern bool stop_mining; +extern volatile bool mining_has_stopped[MAX_GPU]; -extern void cryptonight_core_cpu_init(int thr_id, int threads); -extern void cryptonight_core_cpu_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, struct cryptonight_gpu_ctx *d_ctx); -extern void cryptonight_extra_cpu_setData(int thr_id, const void *data, const void *pTargetIn); -extern void cryptonight_extra_cpu_init(int thr_id); -extern void cryptonight_extra_cpu_prepare(int thr_id, int threads, uint32_t startNonce, struct cryptonight_gpu_ctx *d_ctx); -extern void cryptonight_extra_cpu_final(int thr_id, int threads, uint32_t startNonce, uint32_t *nonce, struct cryptonight_gpu_ctx *d_ctx); +int cryptonight_hash(void* output, const void* input, size_t len, int variant, algo_t opt_algo); -extern "C" void cryptonight_hash(void* output, const void* input, size_t len); - -extern "C" int scanhash_cryptonight(int thr_id, uint32_t *pdata, - const uint32_t *ptarget, uint32_t max_nonce, - unsigned long *hashes_done) +int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done, uint32_t *results) { - uint32_t *nonceptr = (uint32_t*)(((char*)pdata) + 39); - const uint32_t first_nonce = *nonceptr; - uint32_t nonce = *nonceptr; - int cn_blocks = device_config[thr_id][0], cn_threads = device_config[thr_id][1]; - - if (opt_benchmark) { - ((uint32_t*)ptarget)[7] = 0x0000ff; - pdata[17] = 0; - } + cudaError_t err; + int res; + uint32_t *nonceptr = (uint32_t*)(((char*)pdata) + 39); + int variant = 0; + const uint32_t first_nonce = *nonceptr; + uint32_t nonce = *nonceptr; + int cn_blocks = device_config[thr_id][0]; + int cn_threads = device_config[thr_id][1]; + + bool heavy; + if (opt_algo == algo_sumokoin) + heavy = true; + else + { + heavy = false; + if (opt_algo != algo_old) + variant = ((uint8_t*)pdata)[0] >= forkversion ? ((uint8_t*)pdata)[0] - forkversion + 1 : 0; + } + + if(opt_benchmark) + { + ((uint32_t*)ptarget)[7] = 0x0002ffff; + pdata[17] = 0; + } const uint32_t Htarg = ptarget[7]; - const int throughput = cn_threads * cn_blocks; - const size_t alloc = MEMORY * throughput; + const uint32_t throughput = cn_threads * cn_blocks; + if(sizeof(size_t) == 4 && throughput > 0xffffffff / MEMORY) + { + applog(LOG_ERR, "GPU %d: THE 32bit VERSION CAN'T ALLOCATE MORE THAN 4GB OF MEMORY!", device_map[thr_id]); + applog(LOG_ERR, "GPU %d: PLEASE REDUCE THE NUMBER OF THREADS OR BLOCKS", device_map[thr_id]); + exit(1); + } + const size_t alloc = MEMORY * throughput; - static bool init[8] = { false, false, false, false, false, false, false, false }; - if (!init[thr_id]) + static bool init[MAX_GPU] = {false, false, false, false, false, false, false, false}; + if(!init[thr_id]) { - cudaSetDevice(device_map[thr_id]); - cudaDeviceReset(); - cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); - if( cudaMalloc(&d_long_state[thr_id], alloc) != cudaSuccess ) { - applog(LOG_ERR, "GPU #%d: FATAL: failed to allocate device memory for long state", thr_id); - exit(1); - } - if( cudaMalloc(&d_ctx[thr_id], sizeof(struct cryptonight_gpu_ctx) * throughput) != cudaSuccess ) { - applog(LOG_ERR, "GPU #%d: FATAL: failed to allocate device memory for hash context", thr_id); - exit(1); - } - cryptonight_core_cpu_init(thr_id, throughput); - cryptonight_extra_cpu_init(thr_id); + err = cudaSetDevice(device_map[thr_id]); + if(err != cudaSuccess) + { + applog(LOG_ERR, "GPU %d: %s", device_map[thr_id], cudaGetErrorString(err)); + } + cudaDeviceReset(); + cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); + cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); + cudaMalloc(&d_long_state[thr_id], alloc); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_state[thr_id], 50 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_key1[thr_id], 40 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_key2[thr_id], 40 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_text[thr_id], 32 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_a[thr_id], 4 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_b[thr_id], 4 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMalloc(&d_ctx_tweak1_2[thr_id], 2 * sizeof(uint32_t) * throughput); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + + cryptonight_extra_cpu_init(thr_id); + init[thr_id] = true; } - cryptonight_extra_cpu_setData(thr_id, (const void *)pdata, (const void *)ptarget); + cryptonight_extra_cpu_setData(thr_id, (const void *)pdata, (const void *)ptarget); - do { - uint32_t foundNonce = 0xFFFFFFFF; + do + { + uint32_t foundNonce[2]; - cryptonight_extra_cpu_prepare(thr_id, throughput, nonce, d_ctx[thr_id]); - cryptonight_core_cpu_hash(thr_id, cn_blocks, cn_threads, d_long_state[thr_id], d_ctx[thr_id]); - cryptonight_extra_cpu_final(thr_id, throughput, nonce, &foundNonce, d_ctx[thr_id]); + if (!heavy) + { + cryptonight_extra_cpu_prepare(thr_id, throughput, nonce, d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak1_2[thr_id]); + cryptonight_core_cpu_hash(thr_id, cn_blocks, cn_threads, d_long_state[thr_id], d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak1_2[thr_id], opt_algo); + cryptonight_extra_cpu_final(thr_id, throughput, nonce, foundNonce, d_ctx_state[thr_id]); + } + else + { } // not implemented yet - if (foundNonce < 0xffffffff) + if(stop_mining) { - uint32_t vhash64[8]; - uint32_t tempdata[19]; - memcpy(tempdata, pdata, 76); - uint32_t *tempnonceptr = (uint32_t*)(((char*)tempdata) + 39); - *tempnonceptr = foundNonce; - cryptonight_hash(vhash64, tempdata, 76); - - if( (vhash64[7] <= Htarg) && fulltest(vhash64, ptarget) ) { - - *nonceptr = foundNonce; - *hashes_done = foundNonce - first_nonce + 1; - return 1; - } else { - applog(LOG_INFO, "GPU #%d: result for nonce $%08X does not validate on CPU!", thr_id, foundNonce); - } - - foundNonce = 0xffffffff; - } + mining_has_stopped[thr_id] = true; + pthread_exit(NULL); + } - nonce += throughput; - } while (nonce < max_nonce && !work_restart[thr_id].restart); + if(foundNonce[0] < 0xffffffff) + { + uint32_t vhash64[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + uint32_t tempdata[19]; + memcpy(tempdata, pdata, 76); + uint32_t *tempnonceptr = (uint32_t*)(((char*)tempdata) + 39); + *tempnonceptr = foundNonce[0]; + const int rc = cryptonight_hash(vhash64, tempdata, 76, variant, opt_algo); + if(rc && (vhash64[7] <= Htarg) && fulltest(vhash64, ptarget)) + { + res = 1; + if(opt_debug || opt_benchmark) + applog(LOG_DEBUG, "GPU #%d: found nonce $%08X", device_map[thr_id], foundNonce[0]); + results[0] = foundNonce[0]; + *hashes_done = nonce - first_nonce + throughput; + if(foundNonce[1] < 0xffffffff) + { + *tempnonceptr = foundNonce[1]; + const int rc = cryptonight_hash(vhash64, tempdata, 76, variant, opt_algo); + if(rc && (vhash64[7] <= Htarg) && fulltest(vhash64, ptarget)) + { + res++; + if(opt_debug || opt_benchmark) + applog(LOG_DEBUG, "GPU #%d: found nonce $%08X", device_map[thr_id], foundNonce[1]); + results[1] = foundNonce[1]; + } + else + { + applog(LOG_WARNING, "GPU #%d: result for nonce $%08X does not validate on CPU!", device_map[thr_id], foundNonce[1]); + } + } + return res; + } + else + { + applog(LOG_WARNING, "GPU #%d: result for nonce $%08X does not validate on CPU!", device_map[thr_id], foundNonce[0]); + } + } + if((nonce & 0x00ffffff) > (0x00ffffff - throughput)) + nonce = max_nonce; + else + nonce += throughput; + } while(nonce < max_nonce && !work_restart[thr_id].restart); - *hashes_done = nonce - first_nonce + 1; + *hashes_done = nonce - first_nonce; return 0; } diff --git a/cryptonight/cuda_cryptonight_aes.cu b/cryptonight/cuda_cryptonight_aes.cu index 04765a4..0637a95 100755 --- a/cryptonight/cuda_cryptonight_aes.cu +++ b/cryptonight/cuda_cryptonight_aes.cu @@ -1,108 +1,322 @@ - -#define N_COLS 4 -#define WPOLY 0x011b - -static __constant__ uint32_t d_t_fn[4][256]; - -#define sb_data(w) {\ - w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ - w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ - w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ - w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ - w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ - w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ - w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ - w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ - w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ - w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ - w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ - w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ - w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ - w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ - w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ - w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ - w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ - w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ - w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ - w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ - w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ - w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ - w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ - w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ - w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ - w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ - w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ - w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ - w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ - w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ - w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ - w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } - -#define bytes2word(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \ - ((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0)) - -#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) -#define f3(x) (f2(x) ^ x) - -#define u0(p) bytes2word(f2(p), p, p, f3(p)) -#define u1(p) bytes2word(f3(p), f2(p), p, p) -#define u2(p) bytes2word(p, f3(p), f2(p), p) -#define u3(p) bytes2word(p, p, f3(p), f2(p)) - -#define t_dec(m,n) t_##m##n - -#define d_4(t,n,b,e,f,g,h) const t n[4][256] = { b(e), b(f), b(g), b(h) } - -d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3); - -#define t_fn0(x) (*((uint32_t*)sharedMemory + ( (x)))) -#define t_fn1(x) (*((uint32_t*)sharedMemory + (256+(x)))) -#define t_fn2(x) (*((uint32_t*)sharedMemory + (512+(x)))) -#define t_fn3(x) (*((uint32_t*)sharedMemory + (768+(x)))) - - -#define round(dummy,y,x,k) \ - y[0] = (k)[0] ^ (t_fn0(x[0] & 0xff) ^ t_fn1((x[1] >> 8) & 0xff) ^ t_fn2((x[2] >> 16) & 0xff) ^ t_fn3((x[3] >> 24) & 0xff)); \ - y[1] = (k)[1] ^ (t_fn0(x[1] & 0xff) ^ t_fn1((x[2] >> 8) & 0xff) ^ t_fn2((x[3] >> 16) & 0xff) ^ t_fn3((x[0] >> 24) & 0xff)); \ - y[2] = (k)[2] ^ (t_fn0(x[2] & 0xff) ^ t_fn1((x[3] >> 8) & 0xff) ^ t_fn2((x[0] >> 16) & 0xff) ^ t_fn3((x[1] >> 24) & 0xff)); \ - y[3] = (k)[3] ^ (t_fn0(x[3] & 0xff) ^ t_fn1((x[0] >> 8) & 0xff) ^ t_fn2((x[1] >> 16) & 0xff) ^ t_fn3((x[2] >> 24) & 0xff)); - -__device__ __forceinline__ void cn_aes_single_round(uint32_t *sharedMemory, const uint8_t *in, uint32_t *out, uint32_t *expandedKey) -{ - round(sharedMemory, ((uint32_t*) out), ((uint32_t*) in), ((uint32_t*) expandedKey)); -} - -__device__ __forceinline__ void cn_aes_pseudo_round_mut(uint32_t *sharedMemory, uint32_t *val, uint32_t *expandedKey) -{ - uint32_t b1[4]; - round(sharedMemory, b1, ((uint32_t*) val), ((const uint32_t *) expandedKey)); - round(sharedMemory, ((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 1 * N_COLS); - round(sharedMemory, b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 2 * N_COLS); - round(sharedMemory, ((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 3 * N_COLS); - round(sharedMemory, b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 4 * N_COLS); - round(sharedMemory, ((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 5 * N_COLS); - round(sharedMemory, b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 6 * N_COLS); - round(sharedMemory, ((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 7 * N_COLS); - round(sharedMemory, b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 8 * N_COLS); - round(sharedMemory, ((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 9 * N_COLS); -} - -static void cn_aes_cpu_init() -{ - cudaMemcpyToSymbol( d_t_fn, t_fn, sizeof(t_fn), 0, cudaMemcpyHostToDevice); -} - -__device__ __forceinline__ void cn_aes_gpu_init(uint32_t *sharedMemory) -{ - int x; - - // TODO: actually spread the shared memory loading between more or less all threads - // instead of just using the first four to do it... - if(threadIdx.x < 4) { - - for( x = 0; x < 256; x++ ) { - - sharedMemory[threadIdx.x*256+x] = d_t_fn[threadIdx.x][x]; - } - } -} + +#define N_COLS 4 +#define WPOLY 0x011b + +static __constant__ uint32_t d_t_fn[1024] = +{ + 0xa56363c6U, 0x847c7cf8U, 0x997777eeU, 0x8d7b7bf6U, + 0x0df2f2ffU, 0xbd6b6bd6U, 0xb16f6fdeU, 0x54c5c591U, + 0x50303060U, 0x03010102U, 0xa96767ceU, 0x7d2b2b56U, + 0x19fefee7U, 0x62d7d7b5U, 0xe6abab4dU, 0x9a7676ecU, + 0x45caca8fU, 0x9d82821fU, 0x40c9c989U, 0x877d7dfaU, + 0x15fafaefU, 0xeb5959b2U, 0xc947478eU, 0x0bf0f0fbU, + 0xecadad41U, 0x67d4d4b3U, 0xfda2a25fU, 0xeaafaf45U, + 0xbf9c9c23U, 0xf7a4a453U, 0x967272e4U, 0x5bc0c09bU, + 0xc2b7b775U, 0x1cfdfde1U, 0xae93933dU, 0x6a26264cU, + 0x5a36366cU, 0x413f3f7eU, 0x02f7f7f5U, 0x4fcccc83U, + 0x5c343468U, 0xf4a5a551U, 0x34e5e5d1U, 0x08f1f1f9U, + 0x937171e2U, 0x73d8d8abU, 0x53313162U, 0x3f15152aU, + 0x0c040408U, 0x52c7c795U, 0x65232346U, 0x5ec3c39dU, + 0x28181830U, 0xa1969637U, 0x0f05050aU, 0xb59a9a2fU, + 0x0907070eU, 0x36121224U, 0x9b80801bU, 0x3de2e2dfU, + 0x26ebebcdU, 0x6927274eU, 0xcdb2b27fU, 0x9f7575eaU, + 0x1b090912U, 0x9e83831dU, 0x742c2c58U, 0x2e1a1a34U, + 0x2d1b1b36U, 0xb26e6edcU, 0xee5a5ab4U, 0xfba0a05bU, + 0xf65252a4U, 0x4d3b3b76U, 0x61d6d6b7U, 0xceb3b37dU, + 0x7b292952U, 0x3ee3e3ddU, 0x712f2f5eU, 0x97848413U, + 0xf55353a6U, 0x68d1d1b9U, 0x00000000U, 0x2cededc1U, + 0x60202040U, 0x1ffcfce3U, 0xc8b1b179U, 0xed5b5bb6U, + 0xbe6a6ad4U, 0x46cbcb8dU, 0xd9bebe67U, 0x4b393972U, + 0xde4a4a94U, 0xd44c4c98U, 0xe85858b0U, 0x4acfcf85U, + 0x6bd0d0bbU, 0x2aefefc5U, 0xe5aaaa4fU, 0x16fbfbedU, + 0xc5434386U, 0xd74d4d9aU, 0x55333366U, 0x94858511U, + 0xcf45458aU, 0x10f9f9e9U, 0x06020204U, 0x817f7ffeU, + 0xf05050a0U, 0x443c3c78U, 0xba9f9f25U, 0xe3a8a84bU, + 0xf35151a2U, 0xfea3a35dU, 0xc0404080U, 0x8a8f8f05U, + 0xad92923fU, 0xbc9d9d21U, 0x48383870U, 0x04f5f5f1U, + 0xdfbcbc63U, 0xc1b6b677U, 0x75dadaafU, 0x63212142U, + 0x30101020U, 0x1affffe5U, 0x0ef3f3fdU, 0x6dd2d2bfU, + 0x4ccdcd81U, 0x140c0c18U, 0x35131326U, 0x2fececc3U, + 0xe15f5fbeU, 0xa2979735U, 0xcc444488U, 0x3917172eU, + 0x57c4c493U, 0xf2a7a755U, 0x827e7efcU, 0x473d3d7aU, + 0xac6464c8U, 0xe75d5dbaU, 0x2b191932U, 0x957373e6U, + 0xa06060c0U, 0x98818119U, 0xd14f4f9eU, 0x7fdcdca3U, + 0x66222244U, 0x7e2a2a54U, 0xab90903bU, 0x8388880bU, + 0xca46468cU, 0x29eeeec7U, 0xd3b8b86bU, 0x3c141428U, + 0x79dedea7U, 0xe25e5ebcU, 0x1d0b0b16U, 0x76dbdbadU, + 0x3be0e0dbU, 0x56323264U, 0x4e3a3a74U, 0x1e0a0a14U, + 0xdb494992U, 0x0a06060cU, 0x6c242448U, 0xe45c5cb8U, + 0x5dc2c29fU, 0x6ed3d3bdU, 0xefacac43U, 0xa66262c4U, + 0xa8919139U, 0xa4959531U, 0x37e4e4d3U, 0x8b7979f2U, + 0x32e7e7d5U, 0x43c8c88bU, 0x5937376eU, 0xb76d6ddaU, + 0x8c8d8d01U, 0x64d5d5b1U, 0xd24e4e9cU, 0xe0a9a949U, + 0xb46c6cd8U, 0xfa5656acU, 0x07f4f4f3U, 0x25eaeacfU, + 0xaf6565caU, 0x8e7a7af4U, 0xe9aeae47U, 0x18080810U, + 0xd5baba6fU, 0x887878f0U, 0x6f25254aU, 0x722e2e5cU, + 0x241c1c38U, 0xf1a6a657U, 0xc7b4b473U, 0x51c6c697U, + 0x23e8e8cbU, 0x7cdddda1U, 0x9c7474e8U, 0x211f1f3eU, + 0xdd4b4b96U, 0xdcbdbd61U, 0x868b8b0dU, 0x858a8a0fU, + 0x907070e0U, 0x423e3e7cU, 0xc4b5b571U, 0xaa6666ccU, + 0xd8484890U, 0x05030306U, 0x01f6f6f7U, 0x120e0e1cU, + 0xa36161c2U, 0x5f35356aU, 0xf95757aeU, 0xd0b9b969U, + 0x91868617U, 0x58c1c199U, 0x271d1d3aU, 0xb99e9e27U, + 0x38e1e1d9U, 0x13f8f8ebU, 0xb398982bU, 0x33111122U, + 0xbb6969d2U, 0x70d9d9a9U, 0x898e8e07U, 0xa7949433U, + 0xb69b9b2dU, 0x221e1e3cU, 0x92878715U, 0x20e9e9c9U, + 0x49cece87U, 0xff5555aaU, 0x78282850U, 0x7adfdfa5U, + 0x8f8c8c03U, 0xf8a1a159U, 0x80898909U, 0x170d0d1aU, + 0xdabfbf65U, 0x31e6e6d7U, 0xc6424284U, 0xb86868d0U, + 0xc3414182U, 0xb0999929U, 0x772d2d5aU, 0x110f0f1eU, + 0xcbb0b07bU, 0xfc5454a8U, 0xd6bbbb6dU, 0x3a16162cU, + 0x6363c6a5U, 0x7c7cf884U, 0x7777ee99U, 0x7b7bf68dU, + 0xf2f2ff0dU, 0x6b6bd6bdU, 0x6f6fdeb1U, 0xc5c59154U, + 0x30306050U, 0x01010203U, 0x6767cea9U, 0x2b2b567dU, + 0xfefee719U, 0xd7d7b562U, 0xabab4de6U, 0x7676ec9aU, + 0xcaca8f45U, 0x82821f9dU, 0xc9c98940U, 0x7d7dfa87U, + 0xfafaef15U, 0x5959b2ebU, 0x47478ec9U, 0xf0f0fb0bU, + 0xadad41ecU, 0xd4d4b367U, 0xa2a25ffdU, 0xafaf45eaU, + 0x9c9c23bfU, 0xa4a453f7U, 0x7272e496U, 0xc0c09b5bU, + 0xb7b775c2U, 0xfdfde11cU, 0x93933daeU, 0x26264c6aU, + 0x36366c5aU, 0x3f3f7e41U, 0xf7f7f502U, 0xcccc834fU, + 0x3434685cU, 0xa5a551f4U, 0xe5e5d134U, 0xf1f1f908U, + 0x7171e293U, 0xd8d8ab73U, 0x31316253U, 0x15152a3fU, + 0x0404080cU, 0xc7c79552U, 0x23234665U, 0xc3c39d5eU, + 0x18183028U, 0x969637a1U, 0x05050a0fU, 0x9a9a2fb5U, + 0x07070e09U, 0x12122436U, 0x80801b9bU, 0xe2e2df3dU, + 0xebebcd26U, 0x27274e69U, 0xb2b27fcdU, 0x7575ea9fU, + 0x0909121bU, 0x83831d9eU, 0x2c2c5874U, 0x1a1a342eU, + 0x1b1b362dU, 0x6e6edcb2U, 0x5a5ab4eeU, 0xa0a05bfbU, + 0x5252a4f6U, 0x3b3b764dU, 0xd6d6b761U, 0xb3b37dceU, + 0x2929527bU, 0xe3e3dd3eU, 0x2f2f5e71U, 0x84841397U, + 0x5353a6f5U, 0xd1d1b968U, 0x00000000U, 0xededc12cU, + 0x20204060U, 0xfcfce31fU, 0xb1b179c8U, 0x5b5bb6edU, + 0x6a6ad4beU, 0xcbcb8d46U, 0xbebe67d9U, 0x3939724bU, + 0x4a4a94deU, 0x4c4c98d4U, 0x5858b0e8U, 0xcfcf854aU, + 0xd0d0bb6bU, 0xefefc52aU, 0xaaaa4fe5U, 0xfbfbed16U, + 0x434386c5U, 0x4d4d9ad7U, 0x33336655U, 0x85851194U, + 0x45458acfU, 0xf9f9e910U, 0x02020406U, 0x7f7ffe81U, + 0x5050a0f0U, 0x3c3c7844U, 0x9f9f25baU, 0xa8a84be3U, + 0x5151a2f3U, 0xa3a35dfeU, 0x404080c0U, 0x8f8f058aU, + 0x92923fadU, 0x9d9d21bcU, 0x38387048U, 0xf5f5f104U, + 0xbcbc63dfU, 0xb6b677c1U, 0xdadaaf75U, 0x21214263U, + 0x10102030U, 0xffffe51aU, 0xf3f3fd0eU, 0xd2d2bf6dU, + 0xcdcd814cU, 0x0c0c1814U, 0x13132635U, 0xececc32fU, + 0x5f5fbee1U, 0x979735a2U, 0x444488ccU, 0x17172e39U, + 0xc4c49357U, 0xa7a755f2U, 0x7e7efc82U, 0x3d3d7a47U, + 0x6464c8acU, 0x5d5dbae7U, 0x1919322bU, 0x7373e695U, + 0x6060c0a0U, 0x81811998U, 0x4f4f9ed1U, 0xdcdca37fU, + 0x22224466U, 0x2a2a547eU, 0x90903babU, 0x88880b83U, + 0x46468ccaU, 0xeeeec729U, 0xb8b86bd3U, 0x1414283cU, + 0xdedea779U, 0x5e5ebce2U, 0x0b0b161dU, 0xdbdbad76U, + 0xe0e0db3bU, 0x32326456U, 0x3a3a744eU, 0x0a0a141eU, + 0x494992dbU, 0x06060c0aU, 0x2424486cU, 0x5c5cb8e4U, + 0xc2c29f5dU, 0xd3d3bd6eU, 0xacac43efU, 0x6262c4a6U, + 0x919139a8U, 0x959531a4U, 0xe4e4d337U, 0x7979f28bU, + 0xe7e7d532U, 0xc8c88b43U, 0x37376e59U, 0x6d6ddab7U, + 0x8d8d018cU, 0xd5d5b164U, 0x4e4e9cd2U, 0xa9a949e0U, + 0x6c6cd8b4U, 0x5656acfaU, 0xf4f4f307U, 0xeaeacf25U, + 0x6565caafU, 0x7a7af48eU, 0xaeae47e9U, 0x08081018U, + 0xbaba6fd5U, 0x7878f088U, 0x25254a6fU, 0x2e2e5c72U, + 0x1c1c3824U, 0xa6a657f1U, 0xb4b473c7U, 0xc6c69751U, + 0xe8e8cb23U, 0xdddda17cU, 0x7474e89cU, 0x1f1f3e21U, + 0x4b4b96ddU, 0xbdbd61dcU, 0x8b8b0d86U, 0x8a8a0f85U, + 0x7070e090U, 0x3e3e7c42U, 0xb5b571c4U, 0x6666ccaaU, + 0x484890d8U, 0x03030605U, 0xf6f6f701U, 0x0e0e1c12U, + 0x6161c2a3U, 0x35356a5fU, 0x5757aef9U, 0xb9b969d0U, + 0x86861791U, 0xc1c19958U, 0x1d1d3a27U, 0x9e9e27b9U, + 0xe1e1d938U, 0xf8f8eb13U, 0x98982bb3U, 0x11112233U, + 0x6969d2bbU, 0xd9d9a970U, 0x8e8e0789U, 0x949433a7U, + 0x9b9b2db6U, 0x1e1e3c22U, 0x87871592U, 0xe9e9c920U, + 0xcece8749U, 0x5555aaffU, 0x28285078U, 0xdfdfa57aU, + 0x8c8c038fU, 0xa1a159f8U, 0x89890980U, 0x0d0d1a17U, + 0xbfbf65daU, 0xe6e6d731U, 0x424284c6U, 0x6868d0b8U, + 0x414182c3U, 0x999929b0U, 0x2d2d5a77U, 0x0f0f1e11U, + 0xb0b07bcbU, 0x5454a8fcU, 0xbbbb6dd6U, 0x16162c3aU, + 0x63c6a563U, 0x7cf8847cU, 0x77ee9977U, 0x7bf68d7bU, + 0xf2ff0df2U, 0x6bd6bd6bU, 0x6fdeb16fU, 0xc59154c5U, + 0x30605030U, 0x01020301U, 0x67cea967U, 0x2b567d2bU, + 0xfee719feU, 0xd7b562d7U, 0xab4de6abU, 0x76ec9a76U, + 0xca8f45caU, 0x821f9d82U, 0xc98940c9U, 0x7dfa877dU, + 0xfaef15faU, 0x59b2eb59U, 0x478ec947U, 0xf0fb0bf0U, + 0xad41ecadU, 0xd4b367d4U, 0xa25ffda2U, 0xaf45eaafU, + 0x9c23bf9cU, 0xa453f7a4U, 0x72e49672U, 0xc09b5bc0U, + 0xb775c2b7U, 0xfde11cfdU, 0x933dae93U, 0x264c6a26U, + 0x366c5a36U, 0x3f7e413fU, 0xf7f502f7U, 0xcc834fccU, + 0x34685c34U, 0xa551f4a5U, 0xe5d134e5U, 0xf1f908f1U, + 0x71e29371U, 0xd8ab73d8U, 0x31625331U, 0x152a3f15U, + 0x04080c04U, 0xc79552c7U, 0x23466523U, 0xc39d5ec3U, + 0x18302818U, 0x9637a196U, 0x050a0f05U, 0x9a2fb59aU, + 0x070e0907U, 0x12243612U, 0x801b9b80U, 0xe2df3de2U, + 0xebcd26ebU, 0x274e6927U, 0xb27fcdb2U, 0x75ea9f75U, + 0x09121b09U, 0x831d9e83U, 0x2c58742cU, 0x1a342e1aU, + 0x1b362d1bU, 0x6edcb26eU, 0x5ab4ee5aU, 0xa05bfba0U, + 0x52a4f652U, 0x3b764d3bU, 0xd6b761d6U, 0xb37dceb3U, + 0x29527b29U, 0xe3dd3ee3U, 0x2f5e712fU, 0x84139784U, + 0x53a6f553U, 0xd1b968d1U, 0x00000000U, 0xedc12cedU, + 0x20406020U, 0xfce31ffcU, 0xb179c8b1U, 0x5bb6ed5bU, + 0x6ad4be6aU, 0xcb8d46cbU, 0xbe67d9beU, 0x39724b39U, + 0x4a94de4aU, 0x4c98d44cU, 0x58b0e858U, 0xcf854acfU, + 0xd0bb6bd0U, 0xefc52aefU, 0xaa4fe5aaU, 0xfbed16fbU, + 0x4386c543U, 0x4d9ad74dU, 0x33665533U, 0x85119485U, + 0x458acf45U, 0xf9e910f9U, 0x02040602U, 0x7ffe817fU, + 0x50a0f050U, 0x3c78443cU, 0x9f25ba9fU, 0xa84be3a8U, + 0x51a2f351U, 0xa35dfea3U, 0x4080c040U, 0x8f058a8fU, + 0x923fad92U, 0x9d21bc9dU, 0x38704838U, 0xf5f104f5U, + 0xbc63dfbcU, 0xb677c1b6U, 0xdaaf75daU, 0x21426321U, + 0x10203010U, 0xffe51affU, 0xf3fd0ef3U, 0xd2bf6dd2U, + 0xcd814ccdU, 0x0c18140cU, 0x13263513U, 0xecc32fecU, + 0x5fbee15fU, 0x9735a297U, 0x4488cc44U, 0x172e3917U, + 0xc49357c4U, 0xa755f2a7U, 0x7efc827eU, 0x3d7a473dU, + 0x64c8ac64U, 0x5dbae75dU, 0x19322b19U, 0x73e69573U, + 0x60c0a060U, 0x81199881U, 0x4f9ed14fU, 0xdca37fdcU, + 0x22446622U, 0x2a547e2aU, 0x903bab90U, 0x880b8388U, + 0x468cca46U, 0xeec729eeU, 0xb86bd3b8U, 0x14283c14U, + 0xdea779deU, 0x5ebce25eU, 0x0b161d0bU, 0xdbad76dbU, + 0xe0db3be0U, 0x32645632U, 0x3a744e3aU, 0x0a141e0aU, + 0x4992db49U, 0x060c0a06U, 0x24486c24U, 0x5cb8e45cU, + 0xc29f5dc2U, 0xd3bd6ed3U, 0xac43efacU, 0x62c4a662U, + 0x9139a891U, 0x9531a495U, 0xe4d337e4U, 0x79f28b79U, + 0xe7d532e7U, 0xc88b43c8U, 0x376e5937U, 0x6ddab76dU, + 0x8d018c8dU, 0xd5b164d5U, 0x4e9cd24eU, 0xa949e0a9U, + 0x6cd8b46cU, 0x56acfa56U, 0xf4f307f4U, 0xeacf25eaU, + 0x65caaf65U, 0x7af48e7aU, 0xae47e9aeU, 0x08101808U, + 0xba6fd5baU, 0x78f08878U, 0x254a6f25U, 0x2e5c722eU, + 0x1c38241cU, 0xa657f1a6U, 0xb473c7b4U, 0xc69751c6U, + 0xe8cb23e8U, 0xdda17cddU, 0x74e89c74U, 0x1f3e211fU, + 0x4b96dd4bU, 0xbd61dcbdU, 0x8b0d868bU, 0x8a0f858aU, + 0x70e09070U, 0x3e7c423eU, 0xb571c4b5U, 0x66ccaa66U, + 0x4890d848U, 0x03060503U, 0xf6f701f6U, 0x0e1c120eU, + 0x61c2a361U, 0x356a5f35U, 0x57aef957U, 0xb969d0b9U, + 0x86179186U, 0xc19958c1U, 0x1d3a271dU, 0x9e27b99eU, + 0xe1d938e1U, 0xf8eb13f8U, 0x982bb398U, 0x11223311U, + 0x69d2bb69U, 0xd9a970d9U, 0x8e07898eU, 0x9433a794U, + 0x9b2db69bU, 0x1e3c221eU, 0x87159287U, 0xe9c920e9U, + 0xce8749ceU, 0x55aaff55U, 0x28507828U, 0xdfa57adfU, + 0x8c038f8cU, 0xa159f8a1U, 0x89098089U, 0x0d1a170dU, + 0xbf65dabfU, 0xe6d731e6U, 0x4284c642U, 0x68d0b868U, + 0x4182c341U, 0x9929b099U, 0x2d5a772dU, 0x0f1e110fU, + 0xb07bcbb0U, 0x54a8fc54U, 0xbb6dd6bbU, 0x162c3a16U, + 0xc6a56363U, 0xf8847c7cU, 0xee997777U, 0xf68d7b7bU, + 0xff0df2f2U, 0xd6bd6b6bU, 0xdeb16f6fU, 0x9154c5c5U, + 0x60503030U, 0x02030101U, 0xcea96767U, 0x567d2b2bU, + 0xe719fefeU, 0xb562d7d7U, 0x4de6ababU, 0xec9a7676U, + 0x8f45cacaU, 0x1f9d8282U, 0x8940c9c9U, 0xfa877d7dU, + 0xef15fafaU, 0xb2eb5959U, 0x8ec94747U, 0xfb0bf0f0U, + 0x41ecadadU, 0xb367d4d4U, 0x5ffda2a2U, 0x45eaafafU, + 0x23bf9c9cU, 0x53f7a4a4U, 0xe4967272U, 0x9b5bc0c0U, + 0x75c2b7b7U, 0xe11cfdfdU, 0x3dae9393U, 0x4c6a2626U, + 0x6c5a3636U, 0x7e413f3fU, 0xf502f7f7U, 0x834fccccU, + 0x685c3434U, 0x51f4a5a5U, 0xd134e5e5U, 0xf908f1f1U, + 0xe2937171U, 0xab73d8d8U, 0x62533131U, 0x2a3f1515U, + 0x080c0404U, 0x9552c7c7U, 0x46652323U, 0x9d5ec3c3U, + 0x30281818U, 0x37a19696U, 0x0a0f0505U, 0x2fb59a9aU, + 0x0e090707U, 0x24361212U, 0x1b9b8080U, 0xdf3de2e2U, + 0xcd26ebebU, 0x4e692727U, 0x7fcdb2b2U, 0xea9f7575U, + 0x121b0909U, 0x1d9e8383U, 0x58742c2cU, 0x342e1a1aU, + 0x362d1b1bU, 0xdcb26e6eU, 0xb4ee5a5aU, 0x5bfba0a0U, + 0xa4f65252U, 0x764d3b3bU, 0xb761d6d6U, 0x7dceb3b3U, + 0x527b2929U, 0xdd3ee3e3U, 0x5e712f2fU, 0x13978484U, + 0xa6f55353U, 0xb968d1d1U, 0x00000000U, 0xc12cededU, + 0x40602020U, 0xe31ffcfcU, 0x79c8b1b1U, 0xb6ed5b5bU, + 0xd4be6a6aU, 0x8d46cbcbU, 0x67d9bebeU, 0x724b3939U, + 0x94de4a4aU, 0x98d44c4cU, 0xb0e85858U, 0x854acfcfU, + 0xbb6bd0d0U, 0xc52aefefU, 0x4fe5aaaaU, 0xed16fbfbU, + 0x86c54343U, 0x9ad74d4dU, 0x66553333U, 0x11948585U, + 0x8acf4545U, 0xe910f9f9U, 0x04060202U, 0xfe817f7fU, + 0xa0f05050U, 0x78443c3cU, 0x25ba9f9fU, 0x4be3a8a8U, + 0xa2f35151U, 0x5dfea3a3U, 0x80c04040U, 0x058a8f8fU, + 0x3fad9292U, 0x21bc9d9dU, 0x70483838U, 0xf104f5f5U, + 0x63dfbcbcU, 0x77c1b6b6U, 0xaf75dadaU, 0x42632121U, + 0x20301010U, 0xe51affffU, 0xfd0ef3f3U, 0xbf6dd2d2U, + 0x814ccdcdU, 0x18140c0cU, 0x26351313U, 0xc32fececU, + 0xbee15f5fU, 0x35a29797U, 0x88cc4444U, 0x2e391717U, + 0x9357c4c4U, 0x55f2a7a7U, 0xfc827e7eU, 0x7a473d3dU, + 0xc8ac6464U, 0xbae75d5dU, 0x322b1919U, 0xe6957373U, + 0xc0a06060U, 0x19988181U, 0x9ed14f4fU, 0xa37fdcdcU, + 0x44662222U, 0x547e2a2aU, 0x3bab9090U, 0x0b838888U, + 0x8cca4646U, 0xc729eeeeU, 0x6bd3b8b8U, 0x283c1414U, + 0xa779dedeU, 0xbce25e5eU, 0x161d0b0bU, 0xad76dbdbU, + 0xdb3be0e0U, 0x64563232U, 0x744e3a3aU, 0x141e0a0aU, + 0x92db4949U, 0x0c0a0606U, 0x486c2424U, 0xb8e45c5cU, + 0x9f5dc2c2U, 0xbd6ed3d3U, 0x43efacacU, 0xc4a66262U, + 0x39a89191U, 0x31a49595U, 0xd337e4e4U, 0xf28b7979U, + 0xd532e7e7U, 0x8b43c8c8U, 0x6e593737U, 0xdab76d6dU, + 0x018c8d8dU, 0xb164d5d5U, 0x9cd24e4eU, 0x49e0a9a9U, + 0xd8b46c6cU, 0xacfa5656U, 0xf307f4f4U, 0xcf25eaeaU, + 0xcaaf6565U, 0xf48e7a7aU, 0x47e9aeaeU, 0x10180808U, + 0x6fd5babaU, 0xf0887878U, 0x4a6f2525U, 0x5c722e2eU, + 0x38241c1cU, 0x57f1a6a6U, 0x73c7b4b4U, 0x9751c6c6U, + 0xcb23e8e8U, 0xa17cddddU, 0xe89c7474U, 0x3e211f1fU, + 0x96dd4b4bU, 0x61dcbdbdU, 0x0d868b8bU, 0x0f858a8aU, + 0xe0907070U, 0x7c423e3eU, 0x71c4b5b5U, 0xccaa6666U, + 0x90d84848U, 0x06050303U, 0xf701f6f6U, 0x1c120e0eU, + 0xc2a36161U, 0x6a5f3535U, 0xaef95757U, 0x69d0b9b9U, + 0x17918686U, 0x9958c1c1U, 0x3a271d1dU, 0x27b99e9eU, + 0xd938e1e1U, 0xeb13f8f8U, 0x2bb39898U, 0x22331111U, + 0xd2bb6969U, 0xa970d9d9U, 0x07898e8eU, 0x33a79494U, + 0x2db69b9bU, 0x3c221e1eU, 0x15928787U, 0xc920e9e9U, + 0x8749ceceU, 0xaaff5555U, 0x50782828U, 0xa57adfdfU, + 0x038f8c8cU, 0x59f8a1a1U, 0x09808989U, 0x1a170d0dU, + 0x65dabfbfU, 0xd731e6e6U, 0x84c64242U, 0xd0b86868U, + 0x82c34141U, 0x29b09999U, 0x5a772d2dU, 0x1e110f0fU, + 0x7bcbb0b0U, 0xa8fc5454U, 0x6dd6bbbbU, 0x2c3a1616U +}; + +#define t_fn0(x) (sharedMemory[ (x)]) +#define t_fn1(x) (sharedMemory[256 + (x)]) +#define t_fn2(x) (sharedMemory[512 + (x)]) +#define t_fn3(x) (sharedMemory[768 + (x)]) + + +#define round(dummy,y,x,k) \ + y[0] = (k)[0] ^ (t_fn0(x[0] & 0xff) ^ t_fn1((x[1] >> 8) & 0xff) ^ t_fn2((x[2] >> 16) & 0xff) ^ t_fn3((x[3] >> 24) & 0xff)); \ + y[1] = (k)[1] ^ (t_fn0(x[1] & 0xff) ^ t_fn1((x[2] >> 8) & 0xff) ^ t_fn2((x[3] >> 16) & 0xff) ^ t_fn3((x[0] >> 24) & 0xff)); \ + y[2] = (k)[2] ^ (t_fn0(x[2] & 0xff) ^ t_fn1((x[3] >> 8) & 0xff) ^ t_fn2((x[0] >> 16) & 0xff) ^ t_fn3((x[1] >> 24) & 0xff)); \ + y[3] = (k)[3] ^ (t_fn0(x[3] & 0xff) ^ t_fn1((x[0] >> 8) & 0xff) ^ t_fn2((x[1] >> 16) & 0xff) ^ t_fn3((x[2] >> 24) & 0xff)); + +__device__ __forceinline__ static void cn_aes_single_round(uint32_t * __restrict__ sharedMemory, const uint32_t * __restrict__ in, uint32_t * __restrict__ out, const uint32_t * __restrict__ expandedKey) +{ + out[0] = expandedKey[0] ^ t_fn0(in[0] & 0xff) ^ t_fn1((in[1] >> 8) & 0xff) ^ t_fn2((in[2] >> 16) & 0xff) ^ t_fn3((in[3] >> 24) & 0xff); + out[1] = expandedKey[1] ^ t_fn0(in[1] & 0xff) ^ t_fn1((in[2] >> 8) & 0xff) ^ t_fn2((in[3] >> 16) & 0xff) ^ t_fn3((in[0] >> 24) & 0xff); + out[2] = expandedKey[2] ^ t_fn0(in[2] & 0xff) ^ t_fn1((in[3] >> 8) & 0xff) ^ t_fn2((in[0] >> 16) & 0xff) ^ t_fn3((in[1] >> 24) & 0xff); + out[3] = expandedKey[3] ^ t_fn0(in[3] & 0xff) ^ t_fn1((in[0] >> 8) & 0xff) ^ t_fn2((in[1] >> 16) & 0xff) ^ t_fn3((in[2] >> 24) & 0xff); +} + +__device__ __forceinline__ static void cn_aes_pseudo_round_mut(const uint32_t * __restrict__ sharedMemory, uint32_t * __restrict__ val, const uint32_t * __restrict__ expandedKey) +{ + uint32_t b1[4]; + round(sharedMemory, b1, val, expandedKey); + round(sharedMemory, val, b1, expandedKey + 1 * N_COLS); + round(sharedMemory, b1, val, expandedKey + 2 * N_COLS); + round(sharedMemory, val, b1, expandedKey + 3 * N_COLS); + round(sharedMemory, b1, val, expandedKey + 4 * N_COLS); + round(sharedMemory, val, b1, expandedKey + 5 * N_COLS); + round(sharedMemory, b1, val, expandedKey + 6 * N_COLS); + round(sharedMemory, val, b1, expandedKey + 7 * N_COLS); + round(sharedMemory, b1, val, expandedKey + 8 * N_COLS); + round(sharedMemory, val, b1, expandedKey + 9 * N_COLS); +} + +__device__ __forceinline__ static void cn_aes_gpu_init(uint32_t *sharedMemory) +{ + if(blockDim.x >= 32) + { + if(threadIdx.x < 32) + { + for(int i = 0; i < 1024; i += 32) + { + sharedMemory[threadIdx.x + i] = d_t_fn[threadIdx.x + i]; + } + } + } + else + { + if(threadIdx.x < 4) + { + for(int i = 0; i < 1024; i += 4) + { + sharedMemory[threadIdx.x + i] = d_t_fn[threadIdx.x + i]; + } + } + } +} diff --git a/cryptonight/cuda_cryptonight_blake.cu b/cryptonight/cuda_cryptonight_blake.cu index d811fd5..f3a111a 100755 --- a/cryptonight/cuda_cryptonight_blake.cu +++ b/cryptonight/cuda_cryptonight_blake.cu @@ -1,176 +1,175 @@ - -typedef struct { - uint32_t h[8], s[4], t[2]; - int buflen, nullt; - uint8_t buf[64]; -} blake_state; - -#define U8TO32(p) \ - (((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \ - ((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) )) -#define U32TO8(p, v) \ - (p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \ - (p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) ); -#define BLAKE_ROT(x,n) (((x)<<(32-n))|((x)>>(n))) -#define BLAKE_G(a,b,c,d,e) \ - v[a] += (m[d_blake_sigma[i][e]] ^ d_blake_cst[d_blake_sigma[i][e+1]]) + v[b]; \ - v[d] = BLAKE_ROT(v[d] ^ v[a],16); \ - v[c] += v[d]; \ - v[b] = BLAKE_ROT(v[b] ^ v[c],12); \ - v[a] += (m[d_blake_sigma[i][e+1]] ^ d_blake_cst[d_blake_sigma[i][e]])+v[b]; \ - v[d] = BLAKE_ROT(v[d] ^ v[a], 8); \ - v[c] += v[d]; \ - v[b] = BLAKE_ROT(v[b] ^ v[c], 7); - -__constant__ uint8_t d_blake_sigma[14][16]; -__constant__ uint32_t d_blake_cst[16]; - -const uint8_t h_blake_sigma[14][16] = { - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15}, - {14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3}, - {11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4}, - { 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8}, - { 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13}, - { 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9}, - {12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11}, - {13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10}, - { 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5}, - {10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0}, - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15}, - {14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3}, - {11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4}, - { 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8} -}; - -const uint32_t h_blake_cst[16] = { - 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, - 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89, - 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, - 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917 -}; - -__device__ void cn_blake_compress(blake_state *S, const uint8_t *block) { - uint32_t v[16], m[16], i; - - for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4); - for (i = 0; i < 8; ++i) v[i] = S->h[i]; - v[ 8] = S->s[0] ^ 0x243F6A88; - v[ 9] = S->s[1] ^ 0x85A308D3; - v[10] = S->s[2] ^ 0x13198A2E; - v[11] = S->s[3] ^ 0x03707344; - v[12] = 0xA4093822; - v[13] = 0x299F31D0; - v[14] = 0x082EFA98; - v[15] = 0xEC4E6C89; - - if (S->nullt == 0) { - v[12] ^= S->t[0]; - v[13] ^= S->t[0]; - v[14] ^= S->t[1]; - v[15] ^= S->t[1]; - } - - for (i = 0; i < 14; ++i) { - BLAKE_G(0, 4, 8, 12, 0); - BLAKE_G(1, 5, 9, 13, 2); - BLAKE_G(2, 6, 10, 14, 4); - BLAKE_G(3, 7, 11, 15, 6); - BLAKE_G(3, 4, 9, 14, 14); - BLAKE_G(2, 7, 8, 13, 12); - BLAKE_G(0, 5, 10, 15, 8); - BLAKE_G(1, 6, 11, 12, 10); - } - - for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i]; - for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4]; -} - -__device__ void cn_blake_update(blake_state *S, const uint8_t *data, uint64_t datalen) -{ - int left = S->buflen >> 3; - int fill = 64 - left; - - if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) { - memcpy((void *) (S->buf + left), (void *) data, fill); - S->t[0] += 512; - if (S->t[0] == 0) S->t[1]++; - cn_blake_compress(S, S->buf); - data += fill; - datalen -= (fill << 3); - left = 0; - } - - while (datalen >= 512) { - S->t[0] += 512; - if (S->t[0] == 0) S->t[1]++; - cn_blake_compress(S, data); - data += 64; - datalen -= 512; - } - - if (datalen > 0) { - memcpy((void *) (S->buf + left), (void *) data, datalen >> 3); - S->buflen = (left << 3) + datalen; - } else { - S->buflen = 0; - } -} - -__device__ void cn_blake_final(blake_state *S, uint8_t *digest) -{ - const uint8_t padding[] = { - 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - }; - uint8_t pa = 0x81, pb = 0x01; - uint8_t msglen[8]; - uint32_t lo = S->t[0] + S->buflen, hi = S->t[1]; - if (lo < (unsigned) S->buflen) hi++; - U32TO8(msglen + 0, hi); - U32TO8(msglen + 4, lo); - - if (S->buflen == 440) { - S->t[0] -= 8; - cn_blake_update(S, &pa, 8); - } else { - if (S->buflen < 440) { - if (S->buflen == 0) S->nullt = 1; - S->t[0] -= 440 - S->buflen; - cn_blake_update(S, padding, 440 - S->buflen); - } else { - S->t[0] -= 512 - S->buflen; - cn_blake_update(S, padding, 512 - S->buflen); - S->t[0] -= 440; - cn_blake_update(S, padding + 1, 440); - S->nullt = 1; - } - cn_blake_update(S, &pb, 8); - S->t[0] -= 8; - } - S->t[0] -= 64; - cn_blake_update(S, msglen, 64); - - U32TO8(digest + 0, S->h[0]); - U32TO8(digest + 4, S->h[1]); - U32TO8(digest + 8, S->h[2]); - U32TO8(digest + 12, S->h[3]); - U32TO8(digest + 16, S->h[4]); - U32TO8(digest + 20, S->h[5]); - U32TO8(digest + 24, S->h[6]); - U32TO8(digest + 28, S->h[7]); -} - -__device__ void cn_blake(const uint8_t *in, uint64_t inlen, uint8_t *out) -{ - blake_state bs; - blake_state *S = (blake_state *)&bs; - - S->h[0] = 0x6A09E667; S->h[1] = 0xBB67AE85; S->h[2] = 0x3C6EF372; - S->h[3] = 0xA54FF53A; S->h[4] = 0x510E527F; S->h[5] = 0x9B05688C; - S->h[6] = 0x1F83D9AB; S->h[7] = 0x5BE0CD19; - S->t[0] = S->t[1] = S->buflen = S->nullt = 0; - S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0; - - cn_blake_update(S, (uint8_t *)in, inlen * 8); - cn_blake_final(S, (uint8_t *)out); -} + +typedef struct { + uint32_t h[8], s[4], t[2]; + int buflen, nullt; + uint8_t buf[64]; +} blake_state; + +#define U8TO32(p) \ + (((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \ + ((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) )) +#define U32TO8(p, v) \ + (p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \ + (p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) ); +#define BLAKE_ROT(x,n) ROTR32(x, n) +#define BLAKE_G(a,b,c,d,e) \ + v[a] += (m[d_blake_sigma[i][e]] ^ d_blake_cst[d_blake_sigma[i][e+1]]) + v[b]; \ + v[d] = BLAKE_ROT(v[d] ^ v[a],16); \ + v[c] += v[d]; \ + v[b] = BLAKE_ROT(v[b] ^ v[c],12); \ + v[a] += (m[d_blake_sigma[i][e+1]] ^ d_blake_cst[d_blake_sigma[i][e]])+v[b]; \ + v[d] = BLAKE_ROT(v[d] ^ v[a], 8); \ + v[c] += v[d]; \ + v[b] = BLAKE_ROT(v[b] ^ v[c], 7); + +__constant__ uint8_t d_blake_sigma[14][16] = +{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, + {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, + {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}, + {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13}, + {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9}, + {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11}, + {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10}, + {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5}, + {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, + {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, + {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8} +}; +__constant__ uint32_t d_blake_cst[16] += { + 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, + 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89, + 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, + 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917 +}; + +__device__ void cn_blake_compress(blake_state * __restrict__ S, const uint8_t * __restrict__ block) +{ + uint32_t v[16], m[16], i; + + for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4); + for (i = 0; i < 8; ++i) v[i] = S->h[i]; + v[ 8] = S->s[0] ^ 0x243F6A88; + v[ 9] = S->s[1] ^ 0x85A308D3; + v[10] = S->s[2] ^ 0x13198A2E; + v[11] = S->s[3] ^ 0x03707344; + v[12] = 0xA4093822; + v[13] = 0x299F31D0; + v[14] = 0x082EFA98; + v[15] = 0xEC4E6C89; + + if (S->nullt == 0) { + v[12] ^= S->t[0]; + v[13] ^= S->t[0]; + v[14] ^= S->t[1]; + v[15] ^= S->t[1]; + } + + for (i = 0; i < 14; ++i) { + BLAKE_G(0, 4, 8, 12, 0); + BLAKE_G(1, 5, 9, 13, 2); + BLAKE_G(2, 6, 10, 14, 4); + BLAKE_G(3, 7, 11, 15, 6); + BLAKE_G(3, 4, 9, 14, 14); + BLAKE_G(2, 7, 8, 13, 12); + BLAKE_G(0, 5, 10, 15, 8); + BLAKE_G(1, 6, 11, 12, 10); + } + + for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i]; + for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4]; +} + +__device__ void cn_blake_update(blake_state * __restrict__ S, const uint8_t * __restrict__ data, uint64_t datalen) +{ + int left = S->buflen >> 3; + int fill = 64 - left; + + if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) { + memcpy((void *) (S->buf + left), (void *) data, fill); + S->t[0] += 512; + if (S->t[0] == 0) S->t[1]++; + cn_blake_compress(S, S->buf); + data += fill; + datalen -= (fill << 3); + left = 0; + } + + while (datalen >= 512) { + S->t[0] += 512; + if (S->t[0] == 0) S->t[1]++; + cn_blake_compress(S, data); + data += 64; + datalen -= 512; + } + + if (datalen > 0) { + memcpy((void *) (S->buf + left), (void *) data, datalen >> 3); + S->buflen = (left << 3) + datalen; + } else { + S->buflen = 0; + } +} + +__device__ void cn_blake_final(blake_state * __restrict__ S, uint8_t * __restrict__ digest) +{ + const uint8_t padding[] = { + 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + }; + uint8_t pa = 0x81, pb = 0x01; + uint8_t msglen[8]; + uint32_t lo = S->t[0] + S->buflen, hi = S->t[1]; + if (lo < (unsigned) S->buflen) hi++; + U32TO8(msglen + 0, hi); + U32TO8(msglen + 4, lo); + + if (S->buflen == 440) { + S->t[0] -= 8; + cn_blake_update(S, &pa, 8); + } else { + if (S->buflen < 440) { + if (S->buflen == 0) S->nullt = 1; + S->t[0] -= 440 - S->buflen; + cn_blake_update(S, padding, 440 - S->buflen); + } else { + S->t[0] -= 512 - S->buflen; + cn_blake_update(S, padding, 512 - S->buflen); + S->t[0] -= 440; + cn_blake_update(S, padding + 1, 440); + S->nullt = 1; + } + cn_blake_update(S, &pb, 8); + S->t[0] -= 8; + } + S->t[0] -= 64; + cn_blake_update(S, msglen, 64); + + U32TO8(digest + 0, S->h[0]); + U32TO8(digest + 4, S->h[1]); + U32TO8(digest + 8, S->h[2]); + U32TO8(digest + 12, S->h[3]); + U32TO8(digest + 16, S->h[4]); + U32TO8(digest + 20, S->h[5]); + U32TO8(digest + 24, S->h[6]); + U32TO8(digest + 28, S->h[7]); +} + +__device__ void cn_blake(const uint8_t * __restrict__ in, uint64_t inlen, uint8_t * __restrict__ out) +{ + blake_state bs; + blake_state *S = (blake_state *)&bs; + + S->h[0] = 0x6A09E667; S->h[1] = 0xBB67AE85; S->h[2] = 0x3C6EF372; + S->h[3] = 0xA54FF53A; S->h[4] = 0x510E527F; S->h[5] = 0x9B05688C; + S->h[6] = 0x1F83D9AB; S->h[7] = 0x5BE0CD19; + S->t[0] = S->t[1] = S->buflen = S->nullt = 0; + S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0; + + cn_blake_update(S, (uint8_t *)in, inlen * 8); + cn_blake_final(S, (uint8_t *)out); +} diff --git a/cryptonight/cuda_cryptonight_core.cu b/cryptonight/cuda_cryptonight_core.cu index bfe8621..56f4739 100755 --- a/cryptonight/cuda_cryptonight_core.cu +++ b/cryptonight/cuda_cryptonight_core.cu @@ -10,236 +10,253 @@ #include #endif -extern int device_arch[8][2]; -extern int device_bfactor[8]; -extern int device_bsleep[8]; +extern int device_arch[MAX_GPU][2]; +extern int device_bfactor[MAX_GPU]; +extern int device_bsleep[MAX_GPU]; + +#if !defined SHFL +#if CUDART_VERSION >= 9010 +#define SHFL(x, y, z) __shfl_sync(0xffffffff, (x), (y), (z)) +#else +#define SHFL(x, y, z) __shfl((x), (y), (z)) +#endif +#endif #include "cuda_cryptonight_aes.cu" __device__ __forceinline__ uint64_t cuda_mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) { - *product_hi = __umul64hi(multiplier, multiplicand); - return(multiplier * multiplicand); + *product_hi = __umul64hi(multiplier, multiplicand); + return(multiplier * multiplicand); } -__global__ void cryptonight_core_gpu_phase1(int threads, uint32_t *long_state, struct cryptonight_gpu_ctx *ctx) +template< typename T > +__device__ __forceinline__ T loadGlobal64(T * const addr) { - __shared__ uint32_t sharedMemory[1024]; + T x; + asm volatile( + "ld.global.cg.u64 %0, [%1];" : "=l"(x) : "l"(addr) + ); + return x; +} - cn_aes_gpu_init(sharedMemory); +template< typename T > +__device__ __forceinline__ T loadGlobal32(T * const addr) +{ + T x; + asm volatile( + "ld.global.cg.u32 %0, [%1];" : "=r"(x) : "l"(addr) + ); + return x; +} - __syncthreads(); +template< typename T > +__device__ __forceinline__ void storeGlobal32(T* addr, T const & val) +{ + asm volatile( + "st.global.cg.u32 [%0], %1;" : : "l"(addr), "r"(val) + ); - int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3; - int sub = (threadIdx.x & 7) << 2; - - if (thread < threads) - { - uint32_t key[40], text[4], i; - - MEMCPY8(key, ctx[thread].key1, 20); - MEMCPY8(text, &ctx[thread].state[sub + 16], 2); - - for(i = 0; i < 0x80000; i += 32) - { - cn_aes_pseudo_round_mut(sharedMemory, text, key); - MEMCPY8(&long_state[(thread << 19) + sub + i], text, 2); - } - } } -__global__ void cryptonight_core_gpu_phase2(int threads, int bfactor, int partidx, uint32_t *d_long_state, struct cryptonight_gpu_ctx *d_ctx) +__global__ void cryptonight_core_gpu_phase1(int threads, uint32_t * __restrict__ long_state, uint32_t * __restrict__ ctx_state, uint32_t * __restrict__ ctx_key1) { __shared__ uint32_t sharedMemory[1024]; - cn_aes_gpu_init(sharedMemory); + const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3; + if(thread < threads) + { + cn_aes_gpu_init(sharedMemory); + __syncthreads(); - __syncthreads(); + const int sub = (threadIdx.x & 7) << 2; + uint32_t *longstate = &long_state[(thread << 19) + sub]; + + uint32_t key[40], text[4]; + + MEMCPY8(key, ctx_key1 + thread * 40, 20); + MEMCPY8(text, ctx_state + thread * 50 + sub + 16, 2); -#if __CUDA_ARCH__ >= 300 - - int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 2; - int sub = threadIdx.x & 3; - - if (thread < threads) - { - int i, j, k; - int batchsize = ITER >> (2+bfactor); - int start = partidx * batchsize; - int end = start + batchsize; - uint32_t * __restrict__ long_state = &d_long_state[thread << 19]; - struct cryptonight_gpu_ctx *ctx = &d_ctx[thread]; - uint32_t a, b, c, x[4]; - uint32_t t1[4], t2[4], res; - uint64_t reshi, reslo; - - a = ctx->a[sub]; - b = ctx->b[sub]; - - for (i = start; i < end; ++i) { - - //j = ((uint32_t *)a)[0] & 0x1FFFF0; - j = (__shfl((int)a, 0, 4) & 0x1FFFF0) >> 2; - - //cn_aes_single_round(sharedMemory, &long_state[j], c, a); - x[0] = long_state[j + sub]; - x[1] = __shfl((int)x[0], sub+1, 4); - x[2] = __shfl((int)x[0], sub+2, 4); - x[3] = __shfl((int)x[0], sub+3, 4); - c = a ^ - t_fn0(x[0] & 0xff) ^ - t_fn1((x[1] >> 8) & 0xff) ^ - t_fn2((x[2] >> 16) & 0xff) ^ - t_fn3((x[3] >> 24) & 0xff); - - //XOR_BLOCKS_DST(c, b, &long_state[j]); - long_state[j + sub] = c ^ b; - - //MUL_SUM_XOR_DST(c, a, &long_state[((uint32_t *)c)[0] & 0x1FFFF0]); - j = (__shfl((int)c, 0, 4) & 0x1FFFF0) >> 2; - for( k = 0; k < 2; k++ ) t1[k] = __shfl((int)c, k, 4); - for( k = 0; k < 4; k++ ) t2[k] = __shfl((int)a, k, 4); - asm( - "mad.lo.u64 %0, %2, %3, %4;\n\t" - "mad.hi.u64 %1, %2, %3, %5;\n\t" - : "=l"(reslo), "=l"(reshi) - : "l"(((uint64_t *)t1)[0]), "l"(((uint64_t *)long_state)[j >> 1]), "l"(((uint64_t *)t2)[1]), "l"(((uint64_t *)t2)[0])); - res = (sub & 2 ? reslo : reshi) >> (sub&1 ? 32 : 0); - a = long_state[j + sub] ^ res; - long_state[j + sub] = res; - - //j = ((uint32_t *)a)[0] & 0x1FFFF0; - j = (__shfl((int)a, 0, 4) & 0x1FFFF0) >> 2; - - //cn_aes_single_round(sharedMemory, &long_state[j], b, a); - x[0] = long_state[j + sub]; - x[1] = __shfl((int)x[0], sub+1, 4); - x[2] = __shfl((int)x[0], sub+2, 4); - x[3] = __shfl((int)x[0], sub+3, 4); - b = a ^ - t_fn0(x[0] & 0xff) ^ - t_fn1((x[1] >> 8) & 0xff) ^ - t_fn2((x[2] >> 16) & 0xff) ^ - t_fn3((x[3] >> 24) & 0xff); - - //XOR_BLOCKS_DST(b, c, &long_state[j]); - long_state[j + sub] = c ^ b; - - //MUL_SUM_XOR_DST(b, a, &long_state[((uint32_t *)b)[0] & 0x1FFFF0]); - j = (__shfl((int)b, 0, 4) & 0x1FFFF0) >> 2; - for( k = 0; k < 2; k++ ) t1[k] = __shfl((int)b, k, 4); - for( k = 0; k < 4; k++ ) t2[k] = __shfl((int)a, k, 4); - asm( - "mad.lo.u64 %0, %2, %3, %4;\n\t" - "mad.hi.u64 %1, %2, %3, %5;\n\t" - : "=l"(reslo), "=l"(reshi) - : "l"(((uint64_t *)t1)[0]), "l"(((uint64_t *)long_state)[j >> 1]), "l"(((uint64_t *)t2)[1]), "l"(((uint64_t *)t2)[0])); - res = (sub & 2 ? reslo : reshi) >> (sub&1 ? 32 : 0); - a = long_state[j + sub] ^ res; - long_state[j + sub] = res; - } - - if( bfactor > 0 ) { - - ctx->a[sub] = a; - ctx->b[sub] = b; - } - } - -#else // __CUDA_ARCH__ < 300 - - int thread = blockDim.x * blockIdx.x + threadIdx.x; - - if (thread < threads) - { - int i, j; - int batchsize = ITER >> (2+bfactor); - int start = partidx * batchsize; - int end = start + batchsize; - uint32_t *long_state = &d_long_state[thread << 19]; - struct cryptonight_gpu_ctx *ctx = &d_ctx[thread]; - uint32_t a[4], b[4], c[4]; - - MEMCPY8(a, ctx->a, 2); - MEMCPY8(b, ctx->b, 2); - - for (i = start; i < end; ++i) { - - j = (a[0] & 0x1FFFF0) >> 2; - cn_aes_single_round(sharedMemory, (uint8_t *)&long_state[j], c, a); - XOR_BLOCKS_DST(c, b, &long_state[j]); - MUL_SUM_XOR_DST(c, a, (uint8_t *)&long_state[(c[0] & 0x1FFFF0) >> 2]); - j = (a[0] & 0x1FFFF0) >> 2; - cn_aes_single_round(sharedMemory, (uint8_t *)&long_state[j], b, a); - XOR_BLOCKS_DST(b, c, &long_state[j]); - MUL_SUM_XOR_DST(b, a, &long_state[(b[0] & 0x1FFFF0) >> 2]); - } - - if( bfactor > 0 ) { - - MEMCPY8(ctx->a, a, 2); - MEMCPY8(ctx->b, b, 2); - } - } - -#endif // __CUDA_ARCH__ >= 300 + for(int i = 0; i < 0x80000; i += 32) + { + cn_aes_pseudo_round_mut(sharedMemory, text, key); + MEMCPY8(&longstate[i], text, 2); + } + } } -__global__ void cryptonight_core_gpu_phase3(int threads, uint32_t *long_state, struct cryptonight_gpu_ctx *ctx) +__device__ __forceinline__ uint32_t variant1_1(int variant, algo_t opt_algo, const uint32_t src) { - __shared__ uint32_t sharedMemory[1024]; + if(variant > 0) + { + const uint8_t tmp = src >> 24; + if(variant == 2 && opt_algo == algo_stellite) + { + const uint32_t table = 0x00075312; + const uint8_t index = (((tmp >> 4) & 6) | (tmp & 1)) << 1; + return (src & 0x00ffffff) | ((tmp ^ ((table >> index) & 0x30)) << 24); + } + else + { + const uint32_t table = 0x00075310; + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + return (src & 0x00ffffff) | ((tmp ^ ((table >> index) & 0x30)) << 24); + } + } + return src; +} - cn_aes_gpu_init(sharedMemory); +__device__ __forceinline__ void MUL_SUM_XOR_DST(uint64_t a, uint64_t *__restrict__ c, uint64_t *__restrict__ dst) +{ + uint64_t hi = __umul64hi(a, dst[0]) + c[0]; + uint64_t lo = a * dst[0] + c[1]; + c[0] = dst[0] ^ hi; + c[1] = dst[1] ^ lo; + dst[0] = hi; + dst[1] = lo; +} + +__global__ void cryptonight_core_gpu_phase2(uint32_t threads, int bfactor, int partidx, uint32_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b, int variant, const uint32_t * d_tweak1_2, algo_t opt_algo) +{ + __shared__ uint32_t sharedMemory[1024]; + cn_aes_gpu_init(sharedMemory); __syncthreads(); - int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3; - int sub = (threadIdx.x & 7) << 2; - - if (thread < threads) - { - uint32_t key[40], text[4], i, j; - MEMCPY8(key, ctx[thread].key2, 20); - MEMCPY8(text, &ctx[thread].state[sub + 16], 2); - - for (i = 0; i < 0x80000; i += 32) - { - for(j = 0; j < 4; ++j) - text[j] ^= long_state[(thread << 19) + sub + i + j]; - - cn_aes_pseudo_round_mut(sharedMemory, text, key); - } - - MEMCPY8(&ctx[thread].state[sub + 16], text, 2); - } + const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 2; + if (thread >= threads) + return; + + uint32_t tweak1_2[2]; + if (variant > 0) + { + tweak1_2[0] = d_tweak1_2[thread * 2]; + tweak1_2[1] = d_tweak1_2[thread * 2 + 1]; + } + + const int sub = threadIdx.x & 3; + const int sub2 = threadIdx.x & 2; + + int i, k; + uint32_t j; + const int batchsize = 1<<20 >> (2 + bfactor); + const int start = partidx * batchsize; + const int end = start + batchsize; + uint32_t * long_state = &d_long_state[thread << 19]; + uint32_t * ctx_a = d_ctx_a + thread * 4; + uint32_t * ctx_b = d_ctx_b + thread * 4; + uint32_t a, d[2]; + uint32_t t1[2], t2[2], res; + + a = ctx_a[sub]; + d[1] = ctx_b[sub]; +#pragma unroll 2 + for (i = start; i < end; ++i) + { +#pragma unroll 2 + for (int x = 0; x < 2; ++x) + { + j = ((SHFL(a, 0, 4) & 0x1FFFF0) >> 2) + sub; + + const uint32_t x_0 = loadGlobal32(long_state + j); + const uint32_t x_1 = SHFL(x_0, sub + 1, 4); + const uint32_t x_2 = SHFL(x_0, sub + 2, 4); + const uint32_t x_3 = SHFL(x_0, sub + 3, 4); + d[x] = a ^ + t_fn0(x_0 & 0xff) ^ + t_fn1((x_1 >> 8) & 0xff) ^ + t_fn2((x_2 >> 16) & 0xff) ^ + t_fn3((x_3 >> 24)); + + + //XOR_BLOCKS_DST(c, b, &long_state[j]); + t1[0] = SHFL(d[x], 0, 4); + //long_state[j] = d[0] ^ d[1]; + const uint32_t z = d[0] ^ d[1]; + storeGlobal32(long_state + j, (variant > 0 && sub == 2) ? variant1_1(variant, opt_algo, z) : z); + + //MUL_SUM_XOR_DST(c, a, &long_state[((uint32_t *)c)[0] & 0x1FFFF0]); + j = ((*t1 & 0x1FFFF0) >> 2) + sub; + + uint32_t yy[2]; + *((uint64_t*)yy) = loadGlobal64(((uint64_t *)long_state) + (j >> 1)); + uint32_t zz[2]; + zz[0] = SHFL(yy[0], 0, 4); + zz[1] = SHFL(yy[1], 0, 4); + + t1[1] = SHFL(d[x], 1, 4); +#pragma unroll + for (k = 0; k < 2; k++) + t2[k] = SHFL(a, k + sub2, 4); + + *((uint64_t *)t2) += sub2 ? (*((uint64_t *)t1) * *((uint64_t*)zz)) : __umul64hi(*((uint64_t *)t1), *((uint64_t*)zz)); + + res = *((uint64_t *)t2) >> (sub & 1 ? 32 : 0); + + storeGlobal32(long_state + j, (variant > 0 && sub2) ? (tweak1_2[sub & 1] ^ res) : res); + a = (sub & 1 ? yy[1] : yy[0]) ^ res; + } + } + + if (bfactor > 0) + { + ctx_a[sub] = a; + ctx_b[sub] = d[1]; + } } - -__host__ void cryptonight_core_cpu_init(int thr_id, int threads) +__global__ void cryptonight_core_gpu_phase3(int threads, const uint32_t * __restrict__ long_state, uint32_t * __restrict__ d_ctx_state, const uint32_t * __restrict__ d_ctx_key2) { - cn_aes_cpu_init(); + __shared__ uint32_t sharedMemory[1024]; + + cn_aes_gpu_init(sharedMemory); + __syncthreads(); + + const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3; + + if(thread < threads) + { + const int sub = (threadIdx.x & 7) << 2; + const uint32_t *longstate = &long_state[(thread << 19) + sub]; + uint32_t key[40], text[4], i, j; + MEMCPY8(key, d_ctx_key2 + thread * 40, 20); + MEMCPY8(text, d_ctx_state + thread * 50 + sub + 16, 2); + + for(i = 0; i < 0x80000; i += 32) + { +#pragma unroll + for(j = 0; j < 4; ++j) + text[j] ^= longstate[i + j]; + + cn_aes_pseudo_round_mut(sharedMemory, text, key); + } + + MEMCPY8(d_ctx_state + thread * 50 + sub + 16, text, 2); + } } -__host__ void cryptonight_core_cpu_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, struct cryptonight_gpu_ctx *d_ctx) +__host__ void cryptonight_core_cpu_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint32_t *d_ctx_tweak1_2, algo_t opt_algo) { - dim3 grid(blocks); - dim3 block(threads); - dim3 block4(threads << 2); - dim3 block8(threads << 3); - - size_t shared_size = 1024; - int i, partcount = 1 << device_bfactor[thr_id]; - - cryptonight_core_gpu_phase1<<>>(blocks*threads, d_long_state, d_ctx); - cudaDeviceSynchronize(); - if( partcount > 1 ) usleep(device_bsleep[thr_id]); - - for( i = 0; i < partcount; i++ ) { - cryptonight_core_gpu_phase2<<= 3 ? block4 : block), shared_size>>>(blocks*threads, device_bfactor[thr_id], i, d_long_state, d_ctx); - cudaDeviceSynchronize(); - if( partcount > 1 ) usleep(device_bsleep[thr_id]); - } - - cryptonight_core_gpu_phase3<<>>(blocks*threads, d_long_state, d_ctx); - cudaDeviceSynchronize(); + dim3 grid(blocks); + dim3 block(threads); + dim3 block4(threads << 2); + dim3 block8(threads << 3); + + int i, partcount = 1 << device_bfactor[thr_id]; + + cryptonight_core_gpu_phase1 <<< grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key1); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + if(partcount > 1) usleep(device_bsleep[thr_id]); + + for(i = 0; i < partcount; i++) + { + cryptonight_core_gpu_phase2 <<< grid, block4 >>>(blocks*threads, device_bfactor[thr_id], i, d_long_state, d_ctx_a, d_ctx_b, variant, d_ctx_tweak1_2, opt_algo); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaDeviceSynchronize(); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + if(partcount > 1) usleep(device_bsleep[thr_id]); + } + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cryptonight_core_gpu_phase3 <<< grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key2); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); } diff --git a/cryptonight/cuda_cryptonight_extra.cu b/cryptonight/cuda_cryptonight_extra.cu index 5e6392f..0522f2f 100755 --- a/cryptonight/cuda_cryptonight_extra.cu +++ b/cryptonight/cuda_cryptonight_extra.cu @@ -12,9 +12,9 @@ typedef unsigned char BitSequence; typedef unsigned long long DataLength; -static uint32_t *d_input[8]; -static uint32_t *d_target[8]; -static uint32_t *d_resultNonce[8]; +static uint32_t *d_input[MAX_GPU]; +static uint32_t *d_target[MAX_GPU]; +static uint32_t *d_resultNonce[MAX_GPU]; #include "cuda_cryptonight_keccak.cu" #include "cuda_cryptonight_blake.cu" @@ -22,182 +22,199 @@ static uint32_t *d_resultNonce[8]; #include "cuda_cryptonight_jh.cu" #include "cuda_cryptonight_skein.cu" -__constant__ uint8_t d_sub_byte[16][16]; - -const uint8_t sub_byte[16][16] = { - { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76 }, - { 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0 }, - { 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15 }, - { 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75 }, - { 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84 }, - { 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf }, - { 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8 }, - { 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2 }, - { 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73 }, - { 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb }, - { 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79 }, - { 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08 }, - { 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a }, - { 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e }, - { 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf }, - { 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 } +__constant__ uint8_t d_sub_byte[16][16] = +{ + {0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76}, + {0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0}, + {0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15}, + {0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75}, + {0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84}, + {0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf}, + {0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8}, + {0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2}, + {0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73}, + {0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb}, + {0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79}, + {0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08}, + {0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a}, + {0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e}, + {0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf}, + {0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16} }; -__device__ __forceinline__ void cryptonight_aes_set_key( uint32_t *key, const uint32_t *data ) +__device__ __forceinline__ void cryptonight_aes_set_key(uint32_t * __restrict__ key, const uint32_t * __restrict__ data) { - int i, j; - const int key_base = 8; - uint8_t temp[4]; - const uint32_t aes_gf[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; - - MEMSET4(key, 0, 40); - MEMCPY4(key, data, 8); - - for( i = key_base; i < 40; i++ ) { - + int i, j; + uint8_t temp[4]; + const uint32_t aes_gf[10] = + { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 + }; + + MEMCPY4(key, data, 8); +#pragma unroll + for(i = 8; i < 40; i++) + { *(uint32_t *)temp = key[i - 1]; - - if( i % key_base == 0 ) { - - *(uint32_t *)temp = ROTR32(*(uint32_t *)temp, 8); - - for( j = 0; j < 4; j++ ) - temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f]; - - *(uint32_t *)temp ^= aes_gf[i / key_base - 1]; + if(i % 8 == 0) + { + *(uint32_t *)temp = ROTR32(*(uint32_t *)temp, 8); + for(j = 0; j < 4; j++) + temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f]; + *(uint32_t *)temp ^= aes_gf[i / 8 - 1]; } - else if( i % key_base == 4 ) - for( j = 0; j < 4; j++ ) - temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f]; - - key[i] = key[(i - key_base)] ^ *(uint32_t *)temp; + else + if(i % 8 == 4) +#pragma unroll + for(j = 0; j < 4; j++) + temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f]; + key[i] = key[(i - 8)] ^ *(uint32_t *)temp; } } -__global__ void cryptonight_extra_gpu_prepare(int threads, uint32_t *d_input, uint32_t startNonce, struct cryptonight_gpu_ctx *d_ctx) +__global__ void cryptonight_extra_gpu_prepare(int threads, const uint32_t * __restrict__ d_input, uint32_t startNonce, uint32_t * __restrict__ d_ctx_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b, uint32_t * __restrict__ d_ctx_key1, uint32_t * __restrict__ d_ctx_key2, int variant, uint32_t * d_ctx_tweak1_2) { - int thread = (blockDim.x * blockIdx.x + threadIdx.x); - - if (thread < threads) - { - struct cryptonight_gpu_ctx ctx; - uint32_t input[19]; - - MEMCPY4(input, d_input, 19); - *((uint32_t *)(((char *)input) + 39)) = startNonce + thread; - - cn_keccak((uint8_t *)input, (uint8_t *)ctx.state); - cryptonight_aes_set_key(ctx.key1, ctx.state); - cryptonight_aes_set_key(ctx.key2, ctx.state+8); - XOR_BLOCKS_DST(ctx.state, ctx.state+8, ctx.a); - XOR_BLOCKS_DST(ctx.state+4, ctx.state+12, ctx.b); - - memcpy(&d_ctx[thread], &ctx, sizeof(struct cryptonight_gpu_ctx)); - } + int thread = (blockDim.x * blockIdx.x + threadIdx.x); + + if(thread < threads) + { + uint64_t ctx_state[25]; + uint32_t ctx_a[4]; + uint32_t ctx_b[4]; + uint32_t ctx_key1[40] = {0}; + uint32_t ctx_key2[40] = {0}; + uint32_t input[19]; + uint32_t tweak1_2[2]; + + MEMCPY4(input, d_input, 19); + + uint32_t nonce = startNonce + thread; + *(((uint8_t *)input) + 39) = nonce & 0xff; + *(((uint8_t *)input) + 40) = (nonce >> 8) & 0xff; + *(((uint8_t *)input) + 41) = (nonce >> 16) & 0xff; + *(((uint8_t *)input) + 42) = (nonce >> 24) & 0xff; + + cn_keccak(input, ctx_state); + cryptonight_aes_set_key(ctx_key1, (uint32_t*)ctx_state); + cryptonight_aes_set_key(ctx_key2, (uint32_t*)(ctx_state + 4)); + XOR_BLOCKS_DST(ctx_state, ctx_state + 4, ctx_a); + XOR_BLOCKS_DST(ctx_state + 2, ctx_state + 6, ctx_b); + + if (variant > 0) + { + tweak1_2[0] = (input[8] >> 24) | (input[9] << 8); + tweak1_2[0] ^= (ctx_state[24] & 0xffffffff); + tweak1_2[1] = (input[9] >> 24) | (input[10] << 8); + tweak1_2[1] ^= (ctx_state[24] >> 32); + MEMCPY4(d_ctx_tweak1_2 + thread * 2, tweak1_2, 2); + } + + MEMCPY4(d_ctx_state + thread * 50, ctx_state, 50); + MEMCPY4(d_ctx_a + thread * 4, ctx_a, 4); + MEMCPY4(d_ctx_b + thread * 4, ctx_b, 4); + MEMCPY4(d_ctx_key1 + thread * 40, ctx_key1, 40); + MEMCPY4(d_ctx_key2 + thread * 40, ctx_key2, 40); + } } -__global__ void cryptonight_extra_gpu_final(int threads, uint32_t startNonce, uint32_t *d_target, uint32_t *resNonce, struct cryptonight_gpu_ctx *d_ctx) +__global__ void cryptonight_extra_gpu_final(int threads, uint32_t startNonce, const uint32_t * __restrict__ d_target, uint32_t * __restrict__ resNonce, uint32_t * __restrict__ d_ctx_state) { - int thread = (blockDim.x * blockIdx.x + threadIdx.x); - - if (thread < threads) - { - int i; - uint32_t nonce = startNonce + thread; - struct cryptonight_gpu_ctx *ctx = &d_ctx[thread]; - uint32_t hash[8]; - uint32_t state[50]; - - MEMCPY8(state, &ctx->state, 25); - cn_keccakf((uint64_t *)state); - - switch( ((uint8_t *)state)[0] & 0x03 ) { - case 0: - cn_blake((const uint8_t *)state, 200, (uint8_t *)hash); - break; - case 1: - cn_groestl((const BitSequence *)state, 200, (BitSequence *)hash); - break; - case 2: - cn_jh((const BitSequence *)state, 200, (BitSequence *)hash); - break; - case 3: - cn_skein((const BitSequence *)state, 200, (BitSequence *)hash); - break; - default: - break; - } - - int position = -1; - bool rc = true; + const int thread = blockDim.x * blockIdx.x + threadIdx.x; + + if(thread < threads) + { + int i; + const uint32_t nonce = startNonce + thread; + const uint32_t * __restrict__ ctx_state = d_ctx_state + thread * 50; + uint32_t hash[8]; + uint32_t state[50]; + +#pragma unroll + for(i = 0; i < 50; i++) + state[i] = ctx_state[i]; + + cn_keccakf2((uint64_t *)state); + + int branch = ((uint8_t *)state)[0] & 0x03; + if(branch == 0) + cn_blake((const uint8_t *)state, 200, (uint8_t *)hash); + if(branch == 1) + cn_groestl((const BitSequence *)state, 200, (BitSequence *)hash); + if(branch == 2) + cn_jh((const BitSequence *)state, 200, (BitSequence *)hash); + if(branch == 3) + cn_skein((const BitSequence *)state, 200, (BitSequence *)hash); + + int position = -1; + bool rc = true; #pragma unroll 8 - for (i = 7; i >= 0; i--) { - if (hash[i] > d_target[i]) { - if(position < i) { - position = i; - rc = false; - } - } - if (hash[i] < d_target[i]) { - if(position < i) { - position = i; - rc = true; - } - } - } - - if(rc == true) - if(resNonce[0] > nonce) - resNonce[0] = nonce; - } + for(i = 7; i >= 0; i--) + { + if(hash[i] > d_target[i]) + { + if(position < i) + { + position = i; + rc = false; + } + } + if(hash[i] < d_target[i]) + { + if(position < i) + { + position = i; + rc = true; + } + } + } + + if(rc == true) + { + uint32_t tmp = atomicExch(resNonce, nonce); + if(tmp != 0xffffffff) + resNonce[1] = tmp; + } + } } __host__ void cryptonight_extra_cpu_setData(int thr_id, const void *data, const void *pTargetIn) { - cudaMemcpy(d_input[thr_id], data, 19*sizeof(uint32_t), cudaMemcpyHostToDevice); - cudaMemcpy(d_target[thr_id], pTargetIn, 8*sizeof(uint32_t), cudaMemcpyHostToDevice); + cudaMemcpy(d_input[thr_id], data, 19 * sizeof(uint32_t), cudaMemcpyHostToDevice); + cudaMemcpy(d_target[thr_id], pTargetIn, 8 * sizeof(uint32_t), cudaMemcpyHostToDevice); + cudaMemset(d_resultNonce[thr_id], 0xFF, 2 * sizeof(uint32_t)); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); } __host__ void cryptonight_extra_cpu_init(int thr_id) { - cudaMalloc(&d_input[thr_id], 19*sizeof(uint32_t)); - cudaMalloc(&d_target[thr_id], 8*sizeof(uint32_t)); - cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t)); - cudaMemcpyToSymbol(keccakf_rndc, h_keccakf_rndc, sizeof(h_keccakf_rndc), 0, cudaMemcpyHostToDevice); - cudaMemcpyToSymbol(d_sub_byte, sub_byte, sizeof(sub_byte), 0, cudaMemcpyHostToDevice); - cudaMemcpyToSymbol(d_blake_sigma, h_blake_sigma, sizeof(h_blake_sigma), 0, cudaMemcpyHostToDevice); - cudaMemcpyToSymbol(d_blake_cst, h_blake_cst, sizeof(h_blake_cst), 0, cudaMemcpyHostToDevice); - cudaMemcpyToSymbol(d_groestl_T, h_groestl_T, sizeof(h_groestl_T), 0, cudaMemcpyHostToDevice); - cudaMemcpyToSymbol(d_JH256_H0, h_JH256_H0, sizeof(h_JH256_H0), 0, cudaMemcpyHostToDevice); - cudaMemcpyToSymbol(d_E8_rc, h_E8_rc, sizeof(h_E8_rc), 0, cudaMemcpyHostToDevice); + cudaMalloc(&d_input[thr_id], 19 * sizeof(uint32_t)); + cudaMalloc(&d_target[thr_id], 8 * sizeof(uint32_t)); + cudaMalloc(&d_resultNonce[thr_id], 2*sizeof(uint32_t)); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); } -__host__ void cryptonight_extra_cpu_prepare(int thr_id, int threads, uint32_t startNonce, struct cryptonight_gpu_ctx *d_ctx) +__host__ void cryptonight_extra_cpu_prepare(int thr_id, int threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint32_t *d_ctx_tweak1_2) { - int threadsperblock = 128; - size_t shared_size = 0; + int threadsperblock = 128; - dim3 grid((threads + threadsperblock-1)/threadsperblock); - dim3 block(threadsperblock); + dim3 grid((threads + threadsperblock - 1) / threadsperblock); + dim3 block(threadsperblock); - cryptonight_extra_gpu_prepare<<>>(threads, d_input[thr_id], startNonce, d_ctx); - cudaDeviceSynchronize(); + cryptonight_extra_gpu_prepare << > >(threads, d_input[thr_id], startNonce, d_ctx_state, d_ctx_a, d_ctx_b, d_ctx_key1, d_ctx_key2, variant, d_ctx_tweak1_2); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); } -__host__ void cryptonight_extra_cpu_final(int thr_id, int threads, uint32_t startNonce, uint32_t *resnonce, struct cryptonight_gpu_ctx *d_ctx) +__host__ void cryptonight_extra_cpu_final(int thr_id, int threads, uint32_t startNonce, uint32_t *resnonce, uint32_t *d_ctx_state) { - int threadsperblock = 128; - size_t shared_size = 0; + int threadsperblock = 128; - dim3 grid((threads + threadsperblock-1)/threadsperblock); - dim3 block(threadsperblock); + dim3 grid((threads + threadsperblock - 1) / threadsperblock); + dim3 block(threadsperblock); - cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t)); - - cryptonight_extra_gpu_final<<>>(threads, startNonce, d_target[thr_id], d_resultNonce[thr_id], d_ctx); - cudaDeviceSynchronize(); - - cudaMemcpy(resnonce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cryptonight_extra_gpu_final << > >(threads, startNonce, d_target[thr_id], d_resultNonce[thr_id], d_ctx_state); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); + cudaMemcpy(resnonce, d_resultNonce[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost); + exit_if_cudaerror(thr_id, __FILE__, __LINE__); } - diff --git a/cryptonight/cuda_cryptonight_groestl.cu b/cryptonight/cuda_cryptonight_groestl.cu index f14c905..ed151fb 100755 --- a/cryptonight/cuda_cryptonight_groestl.cu +++ b/cryptonight/cuda_cryptonight_groestl.cu @@ -1,344 +1,345 @@ - -#define GROESTL_ROWS 8 -#define GROESTL_LENGTHFIELDLEN GROESTL_ROWS -#define GROESTL_COLS512 8 - -#define GROESTL_SIZE512 (GROESTL_ROWS*GROESTL_COLS512) - -#define GROESTL_ROUNDS512 10 -#define GROESTL_HASH_BIT_LEN 256 - -#define GROESTL_ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) - - -#define li_32(h) 0x##h##u -#define GROESTL_EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) -#define u32BIG(a) \ - ((GROESTL_ROTL32(a,8) & li_32(00FF00FF)) | \ - (GROESTL_ROTL32(a,24) & li_32(FF00FF00))) - - -typedef struct { - uint32_t chaining[GROESTL_SIZE512/sizeof(uint32_t)]; - uint32_t block_counter1, block_counter2; - BitSequence buffer[GROESTL_SIZE512]; - int buf_ptr; - int bits_in_last_byte; -} groestlHashState; - - - -__constant__ uint32_t d_groestl_T[512]; - -const uint32_t h_groestl_T[512] = {0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0xd17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc -, 0x50f09060, 0x6050c0f0, 0x3050702, 0x2030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5 -, 0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0xb1de6fb, 0xfb0bed1d -, 0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded -, 0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1 -, 0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441 -, 0xc141c08, 0x80c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0xf111b0a, 0xa0f1411, 0xb5c4eb2f, 0x2fb55ec4 -, 0x91b150e, 0xe091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba -, 0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616 -, 0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2 -, 0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0x0, 0x0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c -, 0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de -, 0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7 -, 0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x60a0e04, 0x406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e -, 0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x58a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x40cfdf1, 0xf104f90c -, 0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0xe12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7 -, 0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b -, 0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4 -, 0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e -, 0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a -, 0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0xa1e120c, 0xc0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37 -, 0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86 -, 0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x18c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b -, 0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028 -, 0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3 -, 0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0xd861a91, 0x85949b0f, 0xf851e94 -, 0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x50f0906, 0x6050c0f, 0x103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836 -, 0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0 -, 0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x7890e80, 0xa7f2c133, 0x33a766f2 -, 0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e -, 0x8f8a8903, 0x38f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3 -, 0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e}; - -#define GROESTL_ROTATE_COLUMN_DOWN(v1, v2, amount_bytes, temp_var) {temp_var = (v1<<(8*amount_bytes))|(v2>>(8*(4-amount_bytes))); \ - v2 = (v2<<(8*amount_bytes))|(v1>>(8*(4-amount_bytes))); \ - v1 = temp_var;} - -#define GROESTL_COLUMN(x,y,i,c0,c1,c2,c3,c4,c5,c6,c7,tv1,tv2,tu,tl,t) \ - tu = d_groestl_T[2*(uint32_t)x[4*c0+0]]; \ - tl = d_groestl_T[2*(uint32_t)x[4*c0+0]+1]; \ - tv1 = d_groestl_T[2*(uint32_t)x[4*c1+1]]; \ - tv2 = d_groestl_T[2*(uint32_t)x[4*c1+1]+1]; \ - GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \ - tu ^= tv1; \ - tl ^= tv2; \ - tv1 = d_groestl_T[2*(uint32_t)x[4*c2+2]]; \ - tv2 = d_groestl_T[2*(uint32_t)x[4*c2+2]+1]; \ - GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \ - tu ^= tv1; \ - tl ^= tv2; \ - tv1 = d_groestl_T[2*(uint32_t)x[4*c3+3]]; \ - tv2 = d_groestl_T[2*(uint32_t)x[4*c3+3]+1]; \ - GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \ - tu ^= tv1; \ - tl ^= tv2; \ - tl ^= d_groestl_T[2*(uint32_t)x[4*c4+0]]; \ - tu ^= d_groestl_T[2*(uint32_t)x[4*c4+0]+1]; \ - tv1 = d_groestl_T[2*(uint32_t)x[4*c5+1]]; \ - tv2 = d_groestl_T[2*(uint32_t)x[4*c5+1]+1]; \ - GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \ - tl ^= tv1; \ - tu ^= tv2; \ - tv1 = d_groestl_T[2*(uint32_t)x[4*c6+2]]; \ - tv2 = d_groestl_T[2*(uint32_t)x[4*c6+2]+1]; \ - GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \ - tl ^= tv1; \ - tu ^= tv2; \ - tv1 = d_groestl_T[2*(uint32_t)x[4*c7+3]]; \ - tv2 = d_groestl_T[2*(uint32_t)x[4*c7+3]+1]; \ - GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \ - tl ^= tv1; \ - tu ^= tv2; \ - y[i] = tu; \ - y[i+1] = tl; - -__device__ void cn_groestl_RND512P(uint8_t *x, uint32_t *y, uint32_t r) -{ - uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp; - uint32_t* x32 = (uint32_t*)x; - x32[ 0] ^= 0x00000000^r; - x32[ 2] ^= 0x00000010^r; - x32[ 4] ^= 0x00000020^r; - x32[ 6] ^= 0x00000030^r; - x32[ 8] ^= 0x00000040^r; - x32[10] ^= 0x00000050^r; - x32[12] ^= 0x00000060^r; - x32[14] ^= 0x00000070^r; - GROESTL_COLUMN(x,y, 0, 0, 2, 4, 6, 9, 11, 13, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 2, 2, 4, 6, 8, 11, 13, 15, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 4, 4, 6, 8, 10, 13, 15, 1, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 6, 6, 8, 10, 12, 15, 1, 3, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 8, 8, 10, 12, 14, 1, 3, 5, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y,10, 10, 12, 14, 0, 3, 5, 7, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y,12, 12, 14, 0, 2, 5, 7, 9, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y,14, 14, 0, 2, 4, 7, 9, 11, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); -} - -__device__ void cn_groestl_RND512Q(uint8_t *x, uint32_t *y, uint32_t r) -{ - uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp; - uint32_t* x32 = (uint32_t*)x; - x32[ 0] = ~x32[ 0]; - x32[ 1] ^= 0xffffffff^r; - x32[ 2] = ~x32[ 2]; - x32[ 3] ^= 0xefffffff^r; - x32[ 4] = ~x32[ 4]; - x32[ 5] ^= 0xdfffffff^r; - x32[ 6] = ~x32[ 6]; - x32[ 7] ^= 0xcfffffff^r; - x32[ 8] = ~x32[ 8]; - x32[ 9] ^= 0xbfffffff^r; - x32[10] = ~x32[10]; - x32[11] ^= 0xafffffff^r; - x32[12] = ~x32[12]; - x32[13] ^= 0x9fffffff^r; - x32[14] = ~x32[14]; - x32[15] ^= 0x8fffffff^r; - GROESTL_COLUMN(x,y, 0, 2, 6, 10, 14, 1, 5, 9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 2, 4, 8, 12, 0, 3, 7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 4, 6, 10, 14, 2, 5, 9, 13, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 6, 8, 12, 0, 4, 7, 11, 15, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y, 8, 10, 14, 2, 6, 9, 13, 1, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y,10, 12, 0, 4, 8, 11, 15, 3, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y,12, 14, 2, 6, 10, 13, 1, 5, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); - GROESTL_COLUMN(x,y,14, 0, 4, 8, 12, 15, 3, 7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); -} - -__device__ void cn_groestl_F512(uint32_t *h, const uint32_t *m) -{ - int i; - uint32_t Ptmp[2*GROESTL_COLS512]; - uint32_t Qtmp[2*GROESTL_COLS512]; - uint32_t y[2*GROESTL_COLS512]; - uint32_t z[2*GROESTL_COLS512]; - - for (i = 0; i < 2*GROESTL_COLS512; i++) { - z[i] = m[i]; - Ptmp[i] = h[i]^m[i]; - } - - cn_groestl_RND512Q((uint8_t*)z, y, 0x00000000); - cn_groestl_RND512Q((uint8_t*)y, z, 0x01000000); - cn_groestl_RND512Q((uint8_t*)z, y, 0x02000000); - cn_groestl_RND512Q((uint8_t*)y, z, 0x03000000); - cn_groestl_RND512Q((uint8_t*)z, y, 0x04000000); - cn_groestl_RND512Q((uint8_t*)y, z, 0x05000000); - cn_groestl_RND512Q((uint8_t*)z, y, 0x06000000); - cn_groestl_RND512Q((uint8_t*)y, z, 0x07000000); - cn_groestl_RND512Q((uint8_t*)z, y, 0x08000000); - cn_groestl_RND512Q((uint8_t*)y, Qtmp, 0x09000000); - - cn_groestl_RND512P((uint8_t*)Ptmp, y, 0x00000000); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000001); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000002); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000003); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000004); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000005); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000006); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000007); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000008); - cn_groestl_RND512P((uint8_t*)y, Ptmp, 0x00000009); - - for (i = 0; i < 2*GROESTL_COLS512; i++) - h[i] ^= Ptmp[i]^Qtmp[i]; -} - -__device__ void cn_groestl_outputtransformation(groestlHashState *ctx) -{ - int j; - uint32_t temp[2*GROESTL_COLS512]; - uint32_t y[2*GROESTL_COLS512]; - uint32_t z[2*GROESTL_COLS512]; - - for (j = 0; j < 2*GROESTL_COLS512; j++) - temp[j] = ctx->chaining[j]; - - cn_groestl_RND512P((uint8_t*)temp, y, 0x00000000); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000001); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000002); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000003); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000004); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000005); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000006); - cn_groestl_RND512P((uint8_t*)y, z, 0x00000007); - cn_groestl_RND512P((uint8_t*)z, y, 0x00000008); - cn_groestl_RND512P((uint8_t*)y, temp, 0x00000009); - - for (j = 0; j < 2*GROESTL_COLS512; j++) - ctx->chaining[j] ^= temp[j]; -} - -__device__ void cn_groestl_transform(groestlHashState *ctx, - const uint8_t *input, - int msglen) -{ - for (; msglen >= GROESTL_SIZE512; msglen -= GROESTL_SIZE512, input += GROESTL_SIZE512) { - cn_groestl_F512(ctx->chaining,(uint32_t*)input); - ctx->block_counter1++; - if (ctx->block_counter1 == 0) ctx->block_counter2++; - } -} - -__device__ void cn_groestl_final(groestlHashState* ctx, - BitSequence* output) -{ - int i, j = 0, hashbytelen = GROESTL_HASH_BIT_LEN/8; - uint8_t *s = (BitSequence*)ctx->chaining; - - if (ctx->bits_in_last_byte) { - ctx->buffer[(int)ctx->buf_ptr-1] &= ((1<bits_in_last_byte)-1)<<(8-ctx->bits_in_last_byte); - ctx->buffer[(int)ctx->buf_ptr-1] ^= 0x1<<(7-ctx->bits_in_last_byte); - ctx->bits_in_last_byte = 0; - } - else ctx->buffer[(int)ctx->buf_ptr++] = 0x80; - - if (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) { - while (ctx->buf_ptr < GROESTL_SIZE512) { - ctx->buffer[(int)ctx->buf_ptr++] = 0; - } - cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512); - ctx->buf_ptr = 0; - } - while (ctx->buf_ptr < GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) { - ctx->buffer[(int)ctx->buf_ptr++] = 0; - } - - ctx->block_counter1++; - if (ctx->block_counter1 == 0) ctx->block_counter2++; - ctx->buf_ptr = GROESTL_SIZE512; - - while (ctx->buf_ptr > GROESTL_SIZE512-(int)sizeof(uint32_t)) { - ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter1; - ctx->block_counter1 >>= 8; - } - while (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) { - ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter2; - ctx->block_counter2 >>= 8; - } - cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512); - cn_groestl_outputtransformation(ctx); - - for (i = GROESTL_SIZE512-hashbytelen; i < GROESTL_SIZE512; i++,j++) { - output[j] = s[i]; - } - - for (i = 0; i < GROESTL_COLS512; i++) { - ctx->chaining[i] = 0; - } - for (i = 0; i < GROESTL_SIZE512; i++) { - ctx->buffer[i] = 0; - } -} - -__device__ void cn_groestl_update(groestlHashState* ctx, - const BitSequence* input, DataLength databitlen) -{ - int index = 0; - int msglen = (int)(databitlen/8); - int rem = (int)(databitlen%8); - - if (ctx->buf_ptr) { - while (ctx->buf_ptr < GROESTL_SIZE512 && index < msglen) { - ctx->buffer[(int)ctx->buf_ptr++] = input[index++]; - } - if (ctx->buf_ptr < GROESTL_SIZE512) { - if (rem) { - ctx->bits_in_last_byte = rem; - ctx->buffer[(int)ctx->buf_ptr++] = input[index]; - } - return; - } - - ctx->buf_ptr = 0; - cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512); - } - - cn_groestl_transform(ctx, input+index, msglen-index); - index += ((msglen-index)/GROESTL_SIZE512)*GROESTL_SIZE512; - - while (index < msglen) { - ctx->buffer[(int)ctx->buf_ptr++] = input[index++]; - } - - if (rem) { - ctx->bits_in_last_byte = rem; - ctx->buffer[(int)ctx->buf_ptr++] = input[index]; - } -} - -__device__ void cn_groestl_init(groestlHashState* ctx) -{ - int i = 0; - - for(;i<(GROESTL_SIZE512/sizeof(uint32_t));i++) - ctx->chaining[i] = 0; - - ctx->chaining[2*GROESTL_COLS512-1] = u32BIG((uint32_t)GROESTL_HASH_BIT_LEN); - ctx->buf_ptr = 0; - ctx->block_counter1 = 0; - ctx->block_counter2 = 0; - ctx->bits_in_last_byte = 0; -} - -__device__ void cn_groestl(const BitSequence *data, DataLength len, BitSequence *hashval) -{ - DataLength databitlen = len << 3; - groestlHashState context; - - cn_groestl_init(&context); - cn_groestl_update(&context, data, databitlen); - cn_groestl_final(&context, hashval); -} + +#define GROESTL_ROWS 8 +#define GROESTL_LENGTHFIELDLEN GROESTL_ROWS +#define GROESTL_COLS512 8 + +#define GROESTL_SIZE512 (GROESTL_ROWS*GROESTL_COLS512) + +#define GROESTL_ROUNDS512 10 +#define GROESTL_HASH_BIT_LEN 256 + +#define GROESTL_ROTL32(v, n) ROTL32(v, n) + + +#define li_32(h) 0x##h##u +#define GROESTL_EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) +#define u32BIG(a) \ + ((GROESTL_ROTL32(a,8) & li_32(00FF00FF)) | \ + (GROESTL_ROTL32(a,24) & li_32(FF00FF00))) + + +typedef struct { + uint32_t chaining[GROESTL_SIZE512/sizeof(uint32_t)]; + uint32_t block_counter1, block_counter2; + BitSequence buffer[GROESTL_SIZE512]; + int buf_ptr; + int bits_in_last_byte; +} groestlHashState; + + + +__constant__ uint32_t d_groestl_T[512] = +{ + 0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0xd17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc +, 0x50f09060, 0x6050c0f0, 0x3050702, 0x2030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5 +, 0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0xb1de6fb, 0xfb0bed1d +, 0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded +, 0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1 +, 0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441 +, 0xc141c08, 0x80c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0xf111b0a, 0xa0f1411, 0xb5c4eb2f, 0x2fb55ec4 +, 0x91b150e, 0xe091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba +, 0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616 +, 0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2 +, 0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0x0, 0x0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c +, 0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de +, 0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7 +, 0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x60a0e04, 0x406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e +, 0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x58a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x40cfdf1, 0xf104f90c +, 0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0xe12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7 +, 0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b +, 0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4 +, 0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e +, 0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a +, 0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0xa1e120c, 0xc0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37 +, 0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86 +, 0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x18c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b +, 0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028 +, 0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3 +, 0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0xd861a91, 0x85949b0f, 0xf851e94 +, 0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x50f0906, 0x6050c0f, 0x103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836 +, 0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0 +, 0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x7890e80, 0xa7f2c133, 0x33a766f2 +, 0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e +, 0x8f8a8903, 0x38f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3 +, 0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e +}; + +#define GROESTL_ROTATE_COLUMN_DOWN(v1, v2, amount_bytes, temp_var) {temp_var = (v1<<(8*amount_bytes))|(v2>>(8*(4-amount_bytes))); \ + v2 = (v2<<(8*amount_bytes))|(v1>>(8*(4-amount_bytes))); \ + v1 = temp_var;} + +#define GROESTL_COLUMN(x,y,i,c0,c1,c2,c3,c4,c5,c6,c7,tv1,tv2,tu,tl,t) \ + tu = d_groestl_T[2*(uint32_t)x[4*c0+0]]; \ + tl = d_groestl_T[2*(uint32_t)x[4*c0+0]+1]; \ + tv1 = d_groestl_T[2*(uint32_t)x[4*c1+1]]; \ + tv2 = d_groestl_T[2*(uint32_t)x[4*c1+1]+1]; \ + GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \ + tu ^= tv1; \ + tl ^= tv2; \ + tv1 = d_groestl_T[2*(uint32_t)x[4*c2+2]]; \ + tv2 = d_groestl_T[2*(uint32_t)x[4*c2+2]+1]; \ + GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \ + tu ^= tv1; \ + tl ^= tv2; \ + tv1 = d_groestl_T[2*(uint32_t)x[4*c3+3]]; \ + tv2 = d_groestl_T[2*(uint32_t)x[4*c3+3]+1]; \ + GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \ + tu ^= tv1; \ + tl ^= tv2; \ + tl ^= d_groestl_T[2*(uint32_t)x[4*c4+0]]; \ + tu ^= d_groestl_T[2*(uint32_t)x[4*c4+0]+1]; \ + tv1 = d_groestl_T[2*(uint32_t)x[4*c5+1]]; \ + tv2 = d_groestl_T[2*(uint32_t)x[4*c5+1]+1]; \ + GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \ + tl ^= tv1; \ + tu ^= tv2; \ + tv1 = d_groestl_T[2*(uint32_t)x[4*c6+2]]; \ + tv2 = d_groestl_T[2*(uint32_t)x[4*c6+2]+1]; \ + GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \ + tl ^= tv1; \ + tu ^= tv2; \ + tv1 = d_groestl_T[2*(uint32_t)x[4*c7+3]]; \ + tv2 = d_groestl_T[2*(uint32_t)x[4*c7+3]+1]; \ + GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \ + tl ^= tv1; \ + tu ^= tv2; \ + y[i] = tu; \ + y[i+1] = tl; + +__device__ void cn_groestl_RND512P(uint8_t * __restrict__ x, uint32_t * __restrict__ y, uint32_t r) +{ + uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp; + uint32_t* x32 = (uint32_t*)x; + x32[ 0] ^= 0x00000000^r; + x32[ 2] ^= 0x00000010^r; + x32[ 4] ^= 0x00000020^r; + x32[ 6] ^= 0x00000030^r; + x32[ 8] ^= 0x00000040^r; + x32[10] ^= 0x00000050^r; + x32[12] ^= 0x00000060^r; + x32[14] ^= 0x00000070^r; + GROESTL_COLUMN(x,y, 0, 0, 2, 4, 6, 9, 11, 13, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 2, 2, 4, 6, 8, 11, 13, 15, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 4, 4, 6, 8, 10, 13, 15, 1, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 6, 6, 8, 10, 12, 15, 1, 3, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 8, 8, 10, 12, 14, 1, 3, 5, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y,10, 10, 12, 14, 0, 3, 5, 7, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y,12, 12, 14, 0, 2, 5, 7, 9, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y,14, 14, 0, 2, 4, 7, 9, 11, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); +} + +__device__ void cn_groestl_RND512Q(uint8_t * __restrict__ x, uint32_t * __restrict__ y, uint32_t r) +{ + uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp; + uint32_t* x32 = (uint32_t*)x; + x32[ 0] = ~x32[ 0]; + x32[ 1] ^= 0xffffffff^r; + x32[ 2] = ~x32[ 2]; + x32[ 3] ^= 0xefffffff^r; + x32[ 4] = ~x32[ 4]; + x32[ 5] ^= 0xdfffffff^r; + x32[ 6] = ~x32[ 6]; + x32[ 7] ^= 0xcfffffff^r; + x32[ 8] = ~x32[ 8]; + x32[ 9] ^= 0xbfffffff^r; + x32[10] = ~x32[10]; + x32[11] ^= 0xafffffff^r; + x32[12] = ~x32[12]; + x32[13] ^= 0x9fffffff^r; + x32[14] = ~x32[14]; + x32[15] ^= 0x8fffffff^r; + GROESTL_COLUMN(x,y, 0, 2, 6, 10, 14, 1, 5, 9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 2, 4, 8, 12, 0, 3, 7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 4, 6, 10, 14, 2, 5, 9, 13, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 6, 8, 12, 0, 4, 7, 11, 15, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y, 8, 10, 14, 2, 6, 9, 13, 1, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y,10, 12, 0, 4, 8, 11, 15, 3, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y,12, 14, 2, 6, 10, 13, 1, 5, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); + GROESTL_COLUMN(x,y,14, 0, 4, 8, 12, 15, 3, 7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); +} + +__device__ void cn_groestl_F512(uint32_t * __restrict__ h, const uint32_t * __restrict__ m) +{ + int i; + uint32_t Ptmp[2*GROESTL_COLS512]; + uint32_t Qtmp[2*GROESTL_COLS512]; + uint32_t y[2*GROESTL_COLS512]; + uint32_t z[2*GROESTL_COLS512]; + + for (i = 0; i < 2*GROESTL_COLS512; i++) { + z[i] = m[i]; + Ptmp[i] = h[i]^m[i]; + } + + cn_groestl_RND512Q((uint8_t*)z, y, 0x00000000); + cn_groestl_RND512Q((uint8_t*)y, z, 0x01000000); + cn_groestl_RND512Q((uint8_t*)z, y, 0x02000000); + cn_groestl_RND512Q((uint8_t*)y, z, 0x03000000); + cn_groestl_RND512Q((uint8_t*)z, y, 0x04000000); + cn_groestl_RND512Q((uint8_t*)y, z, 0x05000000); + cn_groestl_RND512Q((uint8_t*)z, y, 0x06000000); + cn_groestl_RND512Q((uint8_t*)y, z, 0x07000000); + cn_groestl_RND512Q((uint8_t*)z, y, 0x08000000); + cn_groestl_RND512Q((uint8_t*)y, Qtmp, 0x09000000); + + cn_groestl_RND512P((uint8_t*)Ptmp, y, 0x00000000); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000001); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000002); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000003); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000004); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000005); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000006); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000007); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000008); + cn_groestl_RND512P((uint8_t*)y, Ptmp, 0x00000009); + + for (i = 0; i < 2*GROESTL_COLS512; i++) + h[i] ^= Ptmp[i]^Qtmp[i]; +} + +__device__ void cn_groestl_outputtransformation(groestlHashState *ctx) +{ + int j; + uint32_t temp[2*GROESTL_COLS512]; + uint32_t y[2*GROESTL_COLS512]; + uint32_t z[2*GROESTL_COLS512]; + + for (j = 0; j < 2*GROESTL_COLS512; j++) + temp[j] = ctx->chaining[j]; + + cn_groestl_RND512P((uint8_t*)temp, y, 0x00000000); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000001); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000002); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000003); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000004); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000005); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000006); + cn_groestl_RND512P((uint8_t*)y, z, 0x00000007); + cn_groestl_RND512P((uint8_t*)z, y, 0x00000008); + cn_groestl_RND512P((uint8_t*)y, temp, 0x00000009); + + for (j = 0; j < 2*GROESTL_COLS512; j++) + ctx->chaining[j] ^= temp[j]; +} + +__device__ void cn_groestl_transform(groestlHashState * __restrict__ ctx, + const uint8_t * __restrict__ input, + int msglen) +{ + for (; msglen >= GROESTL_SIZE512; msglen -= GROESTL_SIZE512, input += GROESTL_SIZE512) { + cn_groestl_F512(ctx->chaining,(uint32_t*)input); + ctx->block_counter1++; + if (ctx->block_counter1 == 0) ctx->block_counter2++; + } +} + +__device__ void cn_groestl_final(groestlHashState* __restrict__ ctx, + BitSequence* __restrict__ output) +{ + int i, j = 0, hashbytelen = GROESTL_HASH_BIT_LEN/8; + uint8_t *s = (BitSequence*)ctx->chaining; + + if (ctx->bits_in_last_byte) { + ctx->buffer[(int)ctx->buf_ptr-1] &= ((1<bits_in_last_byte)-1)<<(8-ctx->bits_in_last_byte); + ctx->buffer[(int)ctx->buf_ptr-1] ^= 0x1<<(7-ctx->bits_in_last_byte); + ctx->bits_in_last_byte = 0; + } + else ctx->buffer[(int)ctx->buf_ptr++] = 0x80; + + if (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) { + while (ctx->buf_ptr < GROESTL_SIZE512) { + ctx->buffer[(int)ctx->buf_ptr++] = 0; + } + cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512); + ctx->buf_ptr = 0; + } + while (ctx->buf_ptr < GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) { + ctx->buffer[(int)ctx->buf_ptr++] = 0; + } + + ctx->block_counter1++; + if (ctx->block_counter1 == 0) ctx->block_counter2++; + ctx->buf_ptr = GROESTL_SIZE512; + + while (ctx->buf_ptr > GROESTL_SIZE512-(int)sizeof(uint32_t)) { + ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter1; + ctx->block_counter1 >>= 8; + } + while (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) { + ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter2; + ctx->block_counter2 >>= 8; + } + cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512); + cn_groestl_outputtransformation(ctx); + + for (i = GROESTL_SIZE512-hashbytelen; i < GROESTL_SIZE512; i++,j++) { + output[j] = s[i]; + } + + for (i = 0; i < GROESTL_COLS512; i++) { + ctx->chaining[i] = 0; + } + for (i = 0; i < GROESTL_SIZE512; i++) { + ctx->buffer[i] = 0; + } +} + +__device__ void cn_groestl_update(groestlHashState* __restrict__ ctx, + const BitSequence* __restrict__ input, DataLength databitlen) +{ + int index = 0; + int msglen = (int)(databitlen/8); + int rem = (int)(databitlen%8); + + if (ctx->buf_ptr) { + while (ctx->buf_ptr < GROESTL_SIZE512 && index < msglen) { + ctx->buffer[(int)ctx->buf_ptr++] = input[index++]; + } + if (ctx->buf_ptr < GROESTL_SIZE512) { + if (rem) { + ctx->bits_in_last_byte = rem; + ctx->buffer[(int)ctx->buf_ptr++] = input[index]; + } + return; + } + + ctx->buf_ptr = 0; + cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512); + } + + cn_groestl_transform(ctx, input+index, msglen-index); + index += ((msglen-index)/GROESTL_SIZE512)*GROESTL_SIZE512; + + while (index < msglen) { + ctx->buffer[(int)ctx->buf_ptr++] = input[index++]; + } + + if (rem) { + ctx->bits_in_last_byte = rem; + ctx->buffer[(int)ctx->buf_ptr++] = input[index]; + } +} + +__device__ void cn_groestl_init(groestlHashState* ctx) +{ + int i = 0; + + for(;i<(GROESTL_SIZE512/sizeof(uint32_t));i++) + ctx->chaining[i] = 0; + + ctx->chaining[2*GROESTL_COLS512-1] = u32BIG((uint32_t)GROESTL_HASH_BIT_LEN); + ctx->buf_ptr = 0; + ctx->block_counter1 = 0; + ctx->block_counter2 = 0; + ctx->bits_in_last_byte = 0; +} + +__device__ void cn_groestl(const BitSequence * __restrict__ data, DataLength len, BitSequence * __restrict__ hashval) +{ + DataLength databitlen = len << 3; + groestlHashState context; + + cn_groestl_init(&context); + cn_groestl_update(&context, data, databitlen); + cn_groestl_final(&context, hashval); +} diff --git a/cryptonight/cuda_cryptonight_jh.cu b/cryptonight/cuda_cryptonight_jh.cu index 98c1b01..b65ec88 100755 --- a/cryptonight/cuda_cryptonight_jh.cu +++ b/cryptonight/cuda_cryptonight_jh.cu @@ -1,268 +1,276 @@ - -typedef struct { - int hashbitlen; - unsigned long long databitlen; - unsigned long long datasize_in_buffer; - uint64_t x[8][2]; - unsigned char buffer[64]; -} jhHashState; - -__constant__ unsigned char d_JH256_H0[512]; -__constant__ unsigned char d_E8_rc[42][32]; - -const unsigned char h_JH256_H0[128]={0xeb,0x98,0xa3,0x41,0x2c,0x20,0xd3,0xeb,0x92,0xcd,0xbe,0x7b,0x9c,0xb2,0x45,0xc1,0x1c,0x93,0x51,0x91,0x60,0xd4,0xc7,0xfa,0x26,0x0,0x82,0xd6,0x7e,0x50,0x8a,0x3,0xa4,0x23,0x9e,0x26,0x77,0x26,0xb9,0x45,0xe0,0xfb,0x1a,0x48,0xd4,0x1a,0x94,0x77,0xcd,0xb5,0xab,0x26,0x2,0x6b,0x17,0x7a,0x56,0xf0,0x24,0x42,0xf,0xff,0x2f,0xa8,0x71,0xa3,0x96,0x89,0x7f,0x2e,0x4d,0x75,0x1d,0x14,0x49,0x8,0xf7,0x7d,0xe2,0x62,0x27,0x76,0x95,0xf7,0x76,0x24,0x8f,0x94,0x87,0xd5,0xb6,0x57,0x47,0x80,0x29,0x6c,0x5c,0x5e,0x27,0x2d,0xac,0x8e,0xd,0x6c,0x51,0x84,0x50,0xc6,0x57,0x5,0x7a,0xf,0x7b,0xe4,0xd3,0x67,0x70,0x24,0x12,0xea,0x89,0xe3,0xab,0x13,0xd3,0x1c,0xd7,0x69}; - -const unsigned char h_E8_rc[42][32]={ -{0x72,0xd5,0xde,0xa2,0xdf,0x15,0xf8,0x67,0x7b,0x84,0x15,0xa,0xb7,0x23,0x15,0x57,0x81,0xab,0xd6,0x90,0x4d,0x5a,0x87,0xf6,0x4e,0x9f,0x4f,0xc5,0xc3,0xd1,0x2b,0x40}, -{0xea,0x98,0x3a,0xe0,0x5c,0x45,0xfa,0x9c,0x3,0xc5,0xd2,0x99,0x66,0xb2,0x99,0x9a,0x66,0x2,0x96,0xb4,0xf2,0xbb,0x53,0x8a,0xb5,0x56,0x14,0x1a,0x88,0xdb,0xa2,0x31}, -{0x3,0xa3,0x5a,0x5c,0x9a,0x19,0xe,0xdb,0x40,0x3f,0xb2,0xa,0x87,0xc1,0x44,0x10,0x1c,0x5,0x19,0x80,0x84,0x9e,0x95,0x1d,0x6f,0x33,0xeb,0xad,0x5e,0xe7,0xcd,0xdc}, -{0x10,0xba,0x13,0x92,0x2,0xbf,0x6b,0x41,0xdc,0x78,0x65,0x15,0xf7,0xbb,0x27,0xd0,0xa,0x2c,0x81,0x39,0x37,0xaa,0x78,0x50,0x3f,0x1a,0xbf,0xd2,0x41,0x0,0x91,0xd3}, -{0x42,0x2d,0x5a,0xd,0xf6,0xcc,0x7e,0x90,0xdd,0x62,0x9f,0x9c,0x92,0xc0,0x97,0xce,0x18,0x5c,0xa7,0xb,0xc7,0x2b,0x44,0xac,0xd1,0xdf,0x65,0xd6,0x63,0xc6,0xfc,0x23}, -{0x97,0x6e,0x6c,0x3,0x9e,0xe0,0xb8,0x1a,0x21,0x5,0x45,0x7e,0x44,0x6c,0xec,0xa8,0xee,0xf1,0x3,0xbb,0x5d,0x8e,0x61,0xfa,0xfd,0x96,0x97,0xb2,0x94,0x83,0x81,0x97}, -{0x4a,0x8e,0x85,0x37,0xdb,0x3,0x30,0x2f,0x2a,0x67,0x8d,0x2d,0xfb,0x9f,0x6a,0x95,0x8a,0xfe,0x73,0x81,0xf8,0xb8,0x69,0x6c,0x8a,0xc7,0x72,0x46,0xc0,0x7f,0x42,0x14}, -{0xc5,0xf4,0x15,0x8f,0xbd,0xc7,0x5e,0xc4,0x75,0x44,0x6f,0xa7,0x8f,0x11,0xbb,0x80,0x52,0xde,0x75,0xb7,0xae,0xe4,0x88,0xbc,0x82,0xb8,0x0,0x1e,0x98,0xa6,0xa3,0xf4}, -{0x8e,0xf4,0x8f,0x33,0xa9,0xa3,0x63,0x15,0xaa,0x5f,0x56,0x24,0xd5,0xb7,0xf9,0x89,0xb6,0xf1,0xed,0x20,0x7c,0x5a,0xe0,0xfd,0x36,0xca,0xe9,0x5a,0x6,0x42,0x2c,0x36}, -{0xce,0x29,0x35,0x43,0x4e,0xfe,0x98,0x3d,0x53,0x3a,0xf9,0x74,0x73,0x9a,0x4b,0xa7,0xd0,0xf5,0x1f,0x59,0x6f,0x4e,0x81,0x86,0xe,0x9d,0xad,0x81,0xaf,0xd8,0x5a,0x9f}, -{0xa7,0x5,0x6,0x67,0xee,0x34,0x62,0x6a,0x8b,0xb,0x28,0xbe,0x6e,0xb9,0x17,0x27,0x47,0x74,0x7,0x26,0xc6,0x80,0x10,0x3f,0xe0,0xa0,0x7e,0x6f,0xc6,0x7e,0x48,0x7b}, -{0xd,0x55,0xa,0xa5,0x4a,0xf8,0xa4,0xc0,0x91,0xe3,0xe7,0x9f,0x97,0x8e,0xf1,0x9e,0x86,0x76,0x72,0x81,0x50,0x60,0x8d,0xd4,0x7e,0x9e,0x5a,0x41,0xf3,0xe5,0xb0,0x62}, -{0xfc,0x9f,0x1f,0xec,0x40,0x54,0x20,0x7a,0xe3,0xe4,0x1a,0x0,0xce,0xf4,0xc9,0x84,0x4f,0xd7,0x94,0xf5,0x9d,0xfa,0x95,0xd8,0x55,0x2e,0x7e,0x11,0x24,0xc3,0x54,0xa5}, -{0x5b,0xdf,0x72,0x28,0xbd,0xfe,0x6e,0x28,0x78,0xf5,0x7f,0xe2,0xf,0xa5,0xc4,0xb2,0x5,0x89,0x7c,0xef,0xee,0x49,0xd3,0x2e,0x44,0x7e,0x93,0x85,0xeb,0x28,0x59,0x7f}, -{0x70,0x5f,0x69,0x37,0xb3,0x24,0x31,0x4a,0x5e,0x86,0x28,0xf1,0x1d,0xd6,0xe4,0x65,0xc7,0x1b,0x77,0x4,0x51,0xb9,0x20,0xe7,0x74,0xfe,0x43,0xe8,0x23,0xd4,0x87,0x8a}, -{0x7d,0x29,0xe8,0xa3,0x92,0x76,0x94,0xf2,0xdd,0xcb,0x7a,0x9,0x9b,0x30,0xd9,0xc1,0x1d,0x1b,0x30,0xfb,0x5b,0xdc,0x1b,0xe0,0xda,0x24,0x49,0x4f,0xf2,0x9c,0x82,0xbf}, -{0xa4,0xe7,0xba,0x31,0xb4,0x70,0xbf,0xff,0xd,0x32,0x44,0x5,0xde,0xf8,0xbc,0x48,0x3b,0xae,0xfc,0x32,0x53,0xbb,0xd3,0x39,0x45,0x9f,0xc3,0xc1,0xe0,0x29,0x8b,0xa0}, -{0xe5,0xc9,0x5,0xfd,0xf7,0xae,0x9,0xf,0x94,0x70,0x34,0x12,0x42,0x90,0xf1,0x34,0xa2,0x71,0xb7,0x1,0xe3,0x44,0xed,0x95,0xe9,0x3b,0x8e,0x36,0x4f,0x2f,0x98,0x4a}, -{0x88,0x40,0x1d,0x63,0xa0,0x6c,0xf6,0x15,0x47,0xc1,0x44,0x4b,0x87,0x52,0xaf,0xff,0x7e,0xbb,0x4a,0xf1,0xe2,0xa,0xc6,0x30,0x46,0x70,0xb6,0xc5,0xcc,0x6e,0x8c,0xe6}, -{0xa4,0xd5,0xa4,0x56,0xbd,0x4f,0xca,0x0,0xda,0x9d,0x84,0x4b,0xc8,0x3e,0x18,0xae,0x73,0x57,0xce,0x45,0x30,0x64,0xd1,0xad,0xe8,0xa6,0xce,0x68,0x14,0x5c,0x25,0x67}, -{0xa3,0xda,0x8c,0xf2,0xcb,0xe,0xe1,0x16,0x33,0xe9,0x6,0x58,0x9a,0x94,0x99,0x9a,0x1f,0x60,0xb2,0x20,0xc2,0x6f,0x84,0x7b,0xd1,0xce,0xac,0x7f,0xa0,0xd1,0x85,0x18}, -{0x32,0x59,0x5b,0xa1,0x8d,0xdd,0x19,0xd3,0x50,0x9a,0x1c,0xc0,0xaa,0xa5,0xb4,0x46,0x9f,0x3d,0x63,0x67,0xe4,0x4,0x6b,0xba,0xf6,0xca,0x19,0xab,0xb,0x56,0xee,0x7e}, -{0x1f,0xb1,0x79,0xea,0xa9,0x28,0x21,0x74,0xe9,0xbd,0xf7,0x35,0x3b,0x36,0x51,0xee,0x1d,0x57,0xac,0x5a,0x75,0x50,0xd3,0x76,0x3a,0x46,0xc2,0xfe,0xa3,0x7d,0x70,0x1}, -{0xf7,0x35,0xc1,0xaf,0x98,0xa4,0xd8,0x42,0x78,0xed,0xec,0x20,0x9e,0x6b,0x67,0x79,0x41,0x83,0x63,0x15,0xea,0x3a,0xdb,0xa8,0xfa,0xc3,0x3b,0x4d,0x32,0x83,0x2c,0x83}, -{0xa7,0x40,0x3b,0x1f,0x1c,0x27,0x47,0xf3,0x59,0x40,0xf0,0x34,0xb7,0x2d,0x76,0x9a,0xe7,0x3e,0x4e,0x6c,0xd2,0x21,0x4f,0xfd,0xb8,0xfd,0x8d,0x39,0xdc,0x57,0x59,0xef}, -{0x8d,0x9b,0xc,0x49,0x2b,0x49,0xeb,0xda,0x5b,0xa2,0xd7,0x49,0x68,0xf3,0x70,0xd,0x7d,0x3b,0xae,0xd0,0x7a,0x8d,0x55,0x84,0xf5,0xa5,0xe9,0xf0,0xe4,0xf8,0x8e,0x65}, -{0xa0,0xb8,0xa2,0xf4,0x36,0x10,0x3b,0x53,0xc,0xa8,0x7,0x9e,0x75,0x3e,0xec,0x5a,0x91,0x68,0x94,0x92,0x56,0xe8,0x88,0x4f,0x5b,0xb0,0x5c,0x55,0xf8,0xba,0xbc,0x4c}, -{0xe3,0xbb,0x3b,0x99,0xf3,0x87,0x94,0x7b,0x75,0xda,0xf4,0xd6,0x72,0x6b,0x1c,0x5d,0x64,0xae,0xac,0x28,0xdc,0x34,0xb3,0x6d,0x6c,0x34,0xa5,0x50,0xb8,0x28,0xdb,0x71}, -{0xf8,0x61,0xe2,0xf2,0x10,0x8d,0x51,0x2a,0xe3,0xdb,0x64,0x33,0x59,0xdd,0x75,0xfc,0x1c,0xac,0xbc,0xf1,0x43,0xce,0x3f,0xa2,0x67,0xbb,0xd1,0x3c,0x2,0xe8,0x43,0xb0}, -{0x33,0xa,0x5b,0xca,0x88,0x29,0xa1,0x75,0x7f,0x34,0x19,0x4d,0xb4,0x16,0x53,0x5c,0x92,0x3b,0x94,0xc3,0xe,0x79,0x4d,0x1e,0x79,0x74,0x75,0xd7,0xb6,0xee,0xaf,0x3f}, -{0xea,0xa8,0xd4,0xf7,0xbe,0x1a,0x39,0x21,0x5c,0xf4,0x7e,0x9,0x4c,0x23,0x27,0x51,0x26,0xa3,0x24,0x53,0xba,0x32,0x3c,0xd2,0x44,0xa3,0x17,0x4a,0x6d,0xa6,0xd5,0xad}, -{0xb5,0x1d,0x3e,0xa6,0xaf,0xf2,0xc9,0x8,0x83,0x59,0x3d,0x98,0x91,0x6b,0x3c,0x56,0x4c,0xf8,0x7c,0xa1,0x72,0x86,0x60,0x4d,0x46,0xe2,0x3e,0xcc,0x8,0x6e,0xc7,0xf6}, -{0x2f,0x98,0x33,0xb3,0xb1,0xbc,0x76,0x5e,0x2b,0xd6,0x66,0xa5,0xef,0xc4,0xe6,0x2a,0x6,0xf4,0xb6,0xe8,0xbe,0xc1,0xd4,0x36,0x74,0xee,0x82,0x15,0xbc,0xef,0x21,0x63}, -{0xfd,0xc1,0x4e,0xd,0xf4,0x53,0xc9,0x69,0xa7,0x7d,0x5a,0xc4,0x6,0x58,0x58,0x26,0x7e,0xc1,0x14,0x16,0x6,0xe0,0xfa,0x16,0x7e,0x90,0xaf,0x3d,0x28,0x63,0x9d,0x3f}, -{0xd2,0xc9,0xf2,0xe3,0x0,0x9b,0xd2,0xc,0x5f,0xaa,0xce,0x30,0xb7,0xd4,0xc,0x30,0x74,0x2a,0x51,0x16,0xf2,0xe0,0x32,0x98,0xd,0xeb,0x30,0xd8,0xe3,0xce,0xf8,0x9a}, -{0x4b,0xc5,0x9e,0x7b,0xb5,0xf1,0x79,0x92,0xff,0x51,0xe6,0x6e,0x4,0x86,0x68,0xd3,0x9b,0x23,0x4d,0x57,0xe6,0x96,0x67,0x31,0xcc,0xe6,0xa6,0xf3,0x17,0xa,0x75,0x5}, -{0xb1,0x76,0x81,0xd9,0x13,0x32,0x6c,0xce,0x3c,0x17,0x52,0x84,0xf8,0x5,0xa2,0x62,0xf4,0x2b,0xcb,0xb3,0x78,0x47,0x15,0x47,0xff,0x46,0x54,0x82,0x23,0x93,0x6a,0x48}, -{0x38,0xdf,0x58,0x7,0x4e,0x5e,0x65,0x65,0xf2,0xfc,0x7c,0x89,0xfc,0x86,0x50,0x8e,0x31,0x70,0x2e,0x44,0xd0,0xb,0xca,0x86,0xf0,0x40,0x9,0xa2,0x30,0x78,0x47,0x4e}, -{0x65,0xa0,0xee,0x39,0xd1,0xf7,0x38,0x83,0xf7,0x5e,0xe9,0x37,0xe4,0x2c,0x3a,0xbd,0x21,0x97,0xb2,0x26,0x1,0x13,0xf8,0x6f,0xa3,0x44,0xed,0xd1,0xef,0x9f,0xde,0xe7}, -{0x8b,0xa0,0xdf,0x15,0x76,0x25,0x92,0xd9,0x3c,0x85,0xf7,0xf6,0x12,0xdc,0x42,0xbe,0xd8,0xa7,0xec,0x7c,0xab,0x27,0xb0,0x7e,0x53,0x8d,0x7d,0xda,0xaa,0x3e,0xa8,0xde}, -{0xaa,0x25,0xce,0x93,0xbd,0x2,0x69,0xd8,0x5a,0xf6,0x43,0xfd,0x1a,0x73,0x8,0xf9,0xc0,0x5f,0xef,0xda,0x17,0x4a,0x19,0xa5,0x97,0x4d,0x66,0x33,0x4c,0xfd,0x21,0x6a}, -{0x35,0xb4,0x98,0x31,0xdb,0x41,0x15,0x70,0xea,0x1e,0xf,0xbb,0xed,0xcd,0x54,0x9b,0x9a,0xd0,0x63,0xa1,0x51,0x97,0x40,0x72,0xf6,0x75,0x9d,0xbf,0x91,0x47,0x6f,0xe2}}; - - -#define JH_SWAP1(x) (x) = ((((x) & 0x5555555555555555ULL) << 1) | (((x) & 0xaaaaaaaaaaaaaaaaULL) >> 1)); -#define JH_SWAP2(x) (x) = ((((x) & 0x3333333333333333ULL) << 2) | (((x) & 0xccccccccccccccccULL) >> 2)); -#define JH_SWAP4(x) (x) = ((((x) & 0x0f0f0f0f0f0f0f0fULL) << 4) | (((x) & 0xf0f0f0f0f0f0f0f0ULL) >> 4)); -#define JH_SWAP8(x) (x) = ((((x) & 0x00ff00ff00ff00ffULL) << 8) | (((x) & 0xff00ff00ff00ff00ULL) >> 8)); -#define JH_SWAP16(x) (x) = ((((x) & 0x0000ffff0000ffffULL) << 16) | (((x) & 0xffff0000ffff0000ULL) >> 16)); -#define JH_SWAP32(x) (x) = (((x) << 32) | ((x) >> 32)); - -#define JH_L(m0,m1,m2,m3,m4,m5,m6,m7) \ - (m4) ^= (m1); \ - (m5) ^= (m2); \ - (m6) ^= (m0) ^ (m3); \ - (m7) ^= (m0); \ - (m0) ^= (m5); \ - (m1) ^= (m6); \ - (m2) ^= (m4) ^ (m7); \ - (m3) ^= (m4); - -#define JH_SS(m0,m1,m2,m3,m4,m5,m6,m7,cc0,cc1) \ - m3 = ~(m3); \ - m7 = ~(m7); \ - m0 ^= ((~(m2)) & (cc0)); \ - m4 ^= ((~(m6)) & (cc1)); \ - temp0 = (cc0) ^ ((m0) & (m1));\ - temp1 = (cc1) ^ ((m4) & (m5));\ - m0 ^= ((m2) & (m3)); \ - m4 ^= ((m6) & (m7)); \ - m3 ^= ((~(m1)) & (m2)); \ - m7 ^= ((~(m5)) & (m6)); \ - m1 ^= ((m0) & (m2)); \ - m5 ^= ((m4) & (m6)); \ - m2 ^= ((m0) & (~(m3))); \ - m6 ^= ((m4) & (~(m7))); \ - m0 ^= ((m1) | (m3)); \ - m4 ^= ((m5) | (m7)); \ - m3 ^= ((m1) & (m2)); \ - m7 ^= ((m5) & (m6)); \ - m1 ^= (temp0 & (m0)); \ - m5 ^= (temp1 & (m4)); \ - m2 ^= temp0; \ - m6 ^= temp1; - -__device__ void cn_jh_E8(jhHashState *state) -{ - uint64_t i,roundnumber,temp0,temp1; - - for (roundnumber = 0; roundnumber < 42; roundnumber = roundnumber+7) { - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+0])[i],((uint64_t *)d_E8_rc[roundnumber+0])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - JH_SWAP1(state->x[1][i]); JH_SWAP1(state->x[3][i]); JH_SWAP1(state->x[5][i]); JH_SWAP1(state->x[7][i]); - } - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+1])[i],((uint64_t *)d_E8_rc[roundnumber+1])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - JH_SWAP2(state->x[1][i]); JH_SWAP2(state->x[3][i]); JH_SWAP2(state->x[5][i]); JH_SWAP2(state->x[7][i]); - } - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+2])[i],((uint64_t *)d_E8_rc[roundnumber+2])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - JH_SWAP4(state->x[1][i]); JH_SWAP4(state->x[3][i]); JH_SWAP4(state->x[5][i]); JH_SWAP4(state->x[7][i]); - } - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+3])[i],((uint64_t *)d_E8_rc[roundnumber+3])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - JH_SWAP8(state->x[1][i]); JH_SWAP8(state->x[3][i]); JH_SWAP8(state->x[5][i]); JH_SWAP8(state->x[7][i]); - } - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+4])[i],((uint64_t *)d_E8_rc[roundnumber+4])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - JH_SWAP16(state->x[1][i]); JH_SWAP16(state->x[3][i]); JH_SWAP16(state->x[5][i]); JH_SWAP16(state->x[7][i]); - } - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+5])[i],((uint64_t *)d_E8_rc[roundnumber+5])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - JH_SWAP32(state->x[1][i]); JH_SWAP32(state->x[3][i]); JH_SWAP32(state->x[5][i]); JH_SWAP32(state->x[7][i]); - } - - for (i = 0; i < 2; i++) { - JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+6])[i],((uint64_t *)d_E8_rc[roundnumber+6])[i+2] ); - JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); - } - - for (i = 1; i < 8; i = i+2) { - temp0 = state->x[i][0]; state->x[i][0] = state->x[i][1]; state->x[i][1] = temp0; - } - } -} - -__device__ void cn_jh_F8(jhHashState *state) -{ - uint64_t i; - - for (i = 0; i < 8; i++) state->x[i >> 1][i & 1] ^= ((uint64_t *)state->buffer)[i]; - - cn_jh_E8(state); - - for (i = 0; i < 8; i++) state->x[(8+i) >> 1][(8+i) & 1] ^= ((uint64_t *)state->buffer)[i]; -} - -__device__ void cn_jh_update(jhHashState *state, const BitSequence *data, DataLength databitlen) -{ - DataLength index; - - state->databitlen += databitlen; - index = 0; - - if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) < 512) ) { - if ( (databitlen & 7) == 0 ) { - memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)) ; - } - else memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)+1) ; - state->datasize_in_buffer += databitlen; - databitlen = 0; - } - - if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) >= 512) ) { - memcpy( state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3) ) ; - index = 64-(state->datasize_in_buffer >> 3); - databitlen = databitlen - (512 - state->datasize_in_buffer); - cn_jh_F8(state); - state->datasize_in_buffer = 0; - } - - for ( ; databitlen >= 512; index = index+64, databitlen = databitlen - 512) { - memcpy(state->buffer, data+index, 64); - cn_jh_F8(state); - } - - if ( databitlen > 0) { - if ((databitlen & 7) == 0) - memcpy(state->buffer, data+index, (databitlen & 0x1ff) >> 3); - else - memcpy(state->buffer, data+index, ((databitlen & 0x1ff) >> 3)+1); - state->datasize_in_buffer = databitlen; - } -} - -/*pad the message, process the padded block(s), truncate the hash value H to obtain the message digest*/ -__device__ void cn_jh_final(jhHashState *state, BitSequence *hashval) -{ - unsigned int i; - //uint32_t *bufptr = (uint32_t *)state->buffer; - - if ( (state->databitlen & 0x1ff) == 0 ) { - /*pad the message when databitlen is multiple of 512 bits, then process the padded block*/ - memset(state->buffer, 0, 64); - //for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000; - state->buffer[0] = 0x80; - state->buffer[63] = state->databitlen & 0xff; - state->buffer[62] = (state->databitlen >> 8) & 0xff; - state->buffer[61] = (state->databitlen >> 16) & 0xff; - state->buffer[60] = (state->databitlen >> 24) & 0xff; - state->buffer[59] = (state->databitlen >> 32) & 0xff; - state->buffer[58] = (state->databitlen >> 40) & 0xff; - state->buffer[57] = (state->databitlen >> 48) & 0xff; - state->buffer[56] = (state->databitlen >> 56) & 0xff; - cn_jh_F8(state); - } - else { - /*set the rest of the bytes in the buffer to 0*/ - if ( (state->datasize_in_buffer & 7) == 0) - for (i = (state->databitlen & 0x1ff) >> 3; i < 64; i++) state->buffer[i] = 0; - else - for (i = ((state->databitlen & 0x1ff) >> 3)+1; i < 64; i++) state->buffer[i] = 0; - - /*pad and process the partial block when databitlen is not multiple of 512 bits, then hash the padded blocks*/ - state->buffer[((state->databitlen & 0x1ff) >> 3)] |= 1 << (7- (state->databitlen & 7)); - - cn_jh_F8(state); - memset(state->buffer, 0, 64); - //for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000; - state->buffer[63] = state->databitlen & 0xff; - state->buffer[62] = (state->databitlen >> 8) & 0xff; - state->buffer[61] = (state->databitlen >> 16) & 0xff; - state->buffer[60] = (state->databitlen >> 24) & 0xff; - state->buffer[59] = (state->databitlen >> 32) & 0xff; - state->buffer[58] = (state->databitlen >> 40) & 0xff; - state->buffer[57] = (state->databitlen >> 48) & 0xff; - state->buffer[56] = (state->databitlen >> 56) & 0xff; - cn_jh_F8(state); - } - - memcpy(hashval,(unsigned char*)state->x+64+32,32); -} - -__device__ void cn_jh_init(jhHashState *state, int hashbitlen) -{ - state->databitlen = 0; - state->datasize_in_buffer = 0; - state->hashbitlen = hashbitlen; - memcpy(state->x, d_JH256_H0, 128); -} - -__device__ void cn_jh(const BitSequence *data, DataLength len, BitSequence *hashval) -{ - int hashbitlen = 256; - DataLength databitlen = len << 3; - jhHashState state; - - cn_jh_init(&state, hashbitlen); - cn_jh_update(&state, data, databitlen); - cn_jh_final(&state, hashval); -} + +typedef struct { + int hashbitlen; + unsigned long long databitlen; + unsigned long long datasize_in_buffer; + uint64_t x[8][2]; + unsigned char buffer[64]; +} jhHashState; + +__constant__ unsigned char d_JH256_H0[512] = +{ + 0xeb, 0x98, 0xa3, 0x41, 0x2c, 0x20, 0xd3, 0xeb, 0x92, 0xcd, 0xbe, 0x7b, 0x9c, 0xb2, 0x45, 0xc1, + 0x1c, 0x93, 0x51, 0x91, 0x60, 0xd4, 0xc7, 0xfa, 0x26, 0x0, 0x82, 0xd6, 0x7e, 0x50, 0x8a, 0x3, + 0xa4, 0x23, 0x9e, 0x26, 0x77, 0x26, 0xb9, 0x45, 0xe0, 0xfb, 0x1a, 0x48, 0xd4, 0x1a, 0x94, 0x77, + 0xcd, 0xb5, 0xab, 0x26, 0x2, 0x6b, 0x17, 0x7a, 0x56, 0xf0, 0x24, 0x42, 0xf, 0xff, 0x2f, 0xa8, + 0x71, 0xa3, 0x96, 0x89, 0x7f, 0x2e, 0x4d, 0x75, 0x1d, 0x14, 0x49, 0x8, 0xf7, 0x7d, 0xe2, 0x62, + 0x27, 0x76, 0x95, 0xf7, 0x76, 0x24, 0x8f, 0x94, 0x87, 0xd5, 0xb6, 0x57, 0x47, 0x80, 0x29, 0x6c, + 0x5c, 0x5e, 0x27, 0x2d, 0xac, 0x8e, 0xd, 0x6c, 0x51, 0x84, 0x50, 0xc6, 0x57, 0x5, 0x7a, 0xf, + 0x7b, 0xe4, 0xd3, 0x67, 0x70, 0x24, 0x12, 0xea, 0x89, 0xe3, 0xab, 0x13, 0xd3, 0x1c, 0xd7, 0x69 +}; + +__constant__ unsigned char d_E8_rc[42][32] = +{ + {0x72, 0xd5, 0xde, 0xa2, 0xdf, 0x15, 0xf8, 0x67, 0x7b, 0x84, 0x15, 0xa, 0xb7, 0x23, 0x15, 0x57, 0x81, 0xab, 0xd6, 0x90, 0x4d, 0x5a, 0x87, 0xf6, 0x4e, 0x9f, 0x4f, 0xc5, 0xc3, 0xd1, 0x2b, 0x40}, + {0xea, 0x98, 0x3a, 0xe0, 0x5c, 0x45, 0xfa, 0x9c, 0x3, 0xc5, 0xd2, 0x99, 0x66, 0xb2, 0x99, 0x9a, 0x66, 0x2, 0x96, 0xb4, 0xf2, 0xbb, 0x53, 0x8a, 0xb5, 0x56, 0x14, 0x1a, 0x88, 0xdb, 0xa2, 0x31}, + {0x3, 0xa3, 0x5a, 0x5c, 0x9a, 0x19, 0xe, 0xdb, 0x40, 0x3f, 0xb2, 0xa, 0x87, 0xc1, 0x44, 0x10, 0x1c, 0x5, 0x19, 0x80, 0x84, 0x9e, 0x95, 0x1d, 0x6f, 0x33, 0xeb, 0xad, 0x5e, 0xe7, 0xcd, 0xdc}, + {0x10, 0xba, 0x13, 0x92, 0x2, 0xbf, 0x6b, 0x41, 0xdc, 0x78, 0x65, 0x15, 0xf7, 0xbb, 0x27, 0xd0, 0xa, 0x2c, 0x81, 0x39, 0x37, 0xaa, 0x78, 0x50, 0x3f, 0x1a, 0xbf, 0xd2, 0x41, 0x0, 0x91, 0xd3}, + {0x42, 0x2d, 0x5a, 0xd, 0xf6, 0xcc, 0x7e, 0x90, 0xdd, 0x62, 0x9f, 0x9c, 0x92, 0xc0, 0x97, 0xce, 0x18, 0x5c, 0xa7, 0xb, 0xc7, 0x2b, 0x44, 0xac, 0xd1, 0xdf, 0x65, 0xd6, 0x63, 0xc6, 0xfc, 0x23}, + {0x97, 0x6e, 0x6c, 0x3, 0x9e, 0xe0, 0xb8, 0x1a, 0x21, 0x5, 0x45, 0x7e, 0x44, 0x6c, 0xec, 0xa8, 0xee, 0xf1, 0x3, 0xbb, 0x5d, 0x8e, 0x61, 0xfa, 0xfd, 0x96, 0x97, 0xb2, 0x94, 0x83, 0x81, 0x97}, + {0x4a, 0x8e, 0x85, 0x37, 0xdb, 0x3, 0x30, 0x2f, 0x2a, 0x67, 0x8d, 0x2d, 0xfb, 0x9f, 0x6a, 0x95, 0x8a, 0xfe, 0x73, 0x81, 0xf8, 0xb8, 0x69, 0x6c, 0x8a, 0xc7, 0x72, 0x46, 0xc0, 0x7f, 0x42, 0x14}, + {0xc5, 0xf4, 0x15, 0x8f, 0xbd, 0xc7, 0x5e, 0xc4, 0x75, 0x44, 0x6f, 0xa7, 0x8f, 0x11, 0xbb, 0x80, 0x52, 0xde, 0x75, 0xb7, 0xae, 0xe4, 0x88, 0xbc, 0x82, 0xb8, 0x0, 0x1e, 0x98, 0xa6, 0xa3, 0xf4}, + {0x8e, 0xf4, 0x8f, 0x33, 0xa9, 0xa3, 0x63, 0x15, 0xaa, 0x5f, 0x56, 0x24, 0xd5, 0xb7, 0xf9, 0x89, 0xb6, 0xf1, 0xed, 0x20, 0x7c, 0x5a, 0xe0, 0xfd, 0x36, 0xca, 0xe9, 0x5a, 0x6, 0x42, 0x2c, 0x36}, + {0xce, 0x29, 0x35, 0x43, 0x4e, 0xfe, 0x98, 0x3d, 0x53, 0x3a, 0xf9, 0x74, 0x73, 0x9a, 0x4b, 0xa7, 0xd0, 0xf5, 0x1f, 0x59, 0x6f, 0x4e, 0x81, 0x86, 0xe, 0x9d, 0xad, 0x81, 0xaf, 0xd8, 0x5a, 0x9f}, + {0xa7, 0x5, 0x6, 0x67, 0xee, 0x34, 0x62, 0x6a, 0x8b, 0xb, 0x28, 0xbe, 0x6e, 0xb9, 0x17, 0x27, 0x47, 0x74, 0x7, 0x26, 0xc6, 0x80, 0x10, 0x3f, 0xe0, 0xa0, 0x7e, 0x6f, 0xc6, 0x7e, 0x48, 0x7b}, + {0xd, 0x55, 0xa, 0xa5, 0x4a, 0xf8, 0xa4, 0xc0, 0x91, 0xe3, 0xe7, 0x9f, 0x97, 0x8e, 0xf1, 0x9e, 0x86, 0x76, 0x72, 0x81, 0x50, 0x60, 0x8d, 0xd4, 0x7e, 0x9e, 0x5a, 0x41, 0xf3, 0xe5, 0xb0, 0x62}, + {0xfc, 0x9f, 0x1f, 0xec, 0x40, 0x54, 0x20, 0x7a, 0xe3, 0xe4, 0x1a, 0x0, 0xce, 0xf4, 0xc9, 0x84, 0x4f, 0xd7, 0x94, 0xf5, 0x9d, 0xfa, 0x95, 0xd8, 0x55, 0x2e, 0x7e, 0x11, 0x24, 0xc3, 0x54, 0xa5}, + {0x5b, 0xdf, 0x72, 0x28, 0xbd, 0xfe, 0x6e, 0x28, 0x78, 0xf5, 0x7f, 0xe2, 0xf, 0xa5, 0xc4, 0xb2, 0x5, 0x89, 0x7c, 0xef, 0xee, 0x49, 0xd3, 0x2e, 0x44, 0x7e, 0x93, 0x85, 0xeb, 0x28, 0x59, 0x7f}, + {0x70, 0x5f, 0x69, 0x37, 0xb3, 0x24, 0x31, 0x4a, 0x5e, 0x86, 0x28, 0xf1, 0x1d, 0xd6, 0xe4, 0x65, 0xc7, 0x1b, 0x77, 0x4, 0x51, 0xb9, 0x20, 0xe7, 0x74, 0xfe, 0x43, 0xe8, 0x23, 0xd4, 0x87, 0x8a}, + {0x7d, 0x29, 0xe8, 0xa3, 0x92, 0x76, 0x94, 0xf2, 0xdd, 0xcb, 0x7a, 0x9, 0x9b, 0x30, 0xd9, 0xc1, 0x1d, 0x1b, 0x30, 0xfb, 0x5b, 0xdc, 0x1b, 0xe0, 0xda, 0x24, 0x49, 0x4f, 0xf2, 0x9c, 0x82, 0xbf}, + {0xa4, 0xe7, 0xba, 0x31, 0xb4, 0x70, 0xbf, 0xff, 0xd, 0x32, 0x44, 0x5, 0xde, 0xf8, 0xbc, 0x48, 0x3b, 0xae, 0xfc, 0x32, 0x53, 0xbb, 0xd3, 0x39, 0x45, 0x9f, 0xc3, 0xc1, 0xe0, 0x29, 0x8b, 0xa0}, + {0xe5, 0xc9, 0x5, 0xfd, 0xf7, 0xae, 0x9, 0xf, 0x94, 0x70, 0x34, 0x12, 0x42, 0x90, 0xf1, 0x34, 0xa2, 0x71, 0xb7, 0x1, 0xe3, 0x44, 0xed, 0x95, 0xe9, 0x3b, 0x8e, 0x36, 0x4f, 0x2f, 0x98, 0x4a}, + {0x88, 0x40, 0x1d, 0x63, 0xa0, 0x6c, 0xf6, 0x15, 0x47, 0xc1, 0x44, 0x4b, 0x87, 0x52, 0xaf, 0xff, 0x7e, 0xbb, 0x4a, 0xf1, 0xe2, 0xa, 0xc6, 0x30, 0x46, 0x70, 0xb6, 0xc5, 0xcc, 0x6e, 0x8c, 0xe6}, + {0xa4, 0xd5, 0xa4, 0x56, 0xbd, 0x4f, 0xca, 0x0, 0xda, 0x9d, 0x84, 0x4b, 0xc8, 0x3e, 0x18, 0xae, 0x73, 0x57, 0xce, 0x45, 0x30, 0x64, 0xd1, 0xad, 0xe8, 0xa6, 0xce, 0x68, 0x14, 0x5c, 0x25, 0x67}, + {0xa3, 0xda, 0x8c, 0xf2, 0xcb, 0xe, 0xe1, 0x16, 0x33, 0xe9, 0x6, 0x58, 0x9a, 0x94, 0x99, 0x9a, 0x1f, 0x60, 0xb2, 0x20, 0xc2, 0x6f, 0x84, 0x7b, 0xd1, 0xce, 0xac, 0x7f, 0xa0, 0xd1, 0x85, 0x18}, + {0x32, 0x59, 0x5b, 0xa1, 0x8d, 0xdd, 0x19, 0xd3, 0x50, 0x9a, 0x1c, 0xc0, 0xaa, 0xa5, 0xb4, 0x46, 0x9f, 0x3d, 0x63, 0x67, 0xe4, 0x4, 0x6b, 0xba, 0xf6, 0xca, 0x19, 0xab, 0xb, 0x56, 0xee, 0x7e}, + {0x1f, 0xb1, 0x79, 0xea, 0xa9, 0x28, 0x21, 0x74, 0xe9, 0xbd, 0xf7, 0x35, 0x3b, 0x36, 0x51, 0xee, 0x1d, 0x57, 0xac, 0x5a, 0x75, 0x50, 0xd3, 0x76, 0x3a, 0x46, 0xc2, 0xfe, 0xa3, 0x7d, 0x70, 0x1}, + {0xf7, 0x35, 0xc1, 0xaf, 0x98, 0xa4, 0xd8, 0x42, 0x78, 0xed, 0xec, 0x20, 0x9e, 0x6b, 0x67, 0x79, 0x41, 0x83, 0x63, 0x15, 0xea, 0x3a, 0xdb, 0xa8, 0xfa, 0xc3, 0x3b, 0x4d, 0x32, 0x83, 0x2c, 0x83}, + {0xa7, 0x40, 0x3b, 0x1f, 0x1c, 0x27, 0x47, 0xf3, 0x59, 0x40, 0xf0, 0x34, 0xb7, 0x2d, 0x76, 0x9a, 0xe7, 0x3e, 0x4e, 0x6c, 0xd2, 0x21, 0x4f, 0xfd, 0xb8, 0xfd, 0x8d, 0x39, 0xdc, 0x57, 0x59, 0xef}, + {0x8d, 0x9b, 0xc, 0x49, 0x2b, 0x49, 0xeb, 0xda, 0x5b, 0xa2, 0xd7, 0x49, 0x68, 0xf3, 0x70, 0xd, 0x7d, 0x3b, 0xae, 0xd0, 0x7a, 0x8d, 0x55, 0x84, 0xf5, 0xa5, 0xe9, 0xf0, 0xe4, 0xf8, 0x8e, 0x65}, + {0xa0, 0xb8, 0xa2, 0xf4, 0x36, 0x10, 0x3b, 0x53, 0xc, 0xa8, 0x7, 0x9e, 0x75, 0x3e, 0xec, 0x5a, 0x91, 0x68, 0x94, 0x92, 0x56, 0xe8, 0x88, 0x4f, 0x5b, 0xb0, 0x5c, 0x55, 0xf8, 0xba, 0xbc, 0x4c}, + {0xe3, 0xbb, 0x3b, 0x99, 0xf3, 0x87, 0x94, 0x7b, 0x75, 0xda, 0xf4, 0xd6, 0x72, 0x6b, 0x1c, 0x5d, 0x64, 0xae, 0xac, 0x28, 0xdc, 0x34, 0xb3, 0x6d, 0x6c, 0x34, 0xa5, 0x50, 0xb8, 0x28, 0xdb, 0x71}, + {0xf8, 0x61, 0xe2, 0xf2, 0x10, 0x8d, 0x51, 0x2a, 0xe3, 0xdb, 0x64, 0x33, 0x59, 0xdd, 0x75, 0xfc, 0x1c, 0xac, 0xbc, 0xf1, 0x43, 0xce, 0x3f, 0xa2, 0x67, 0xbb, 0xd1, 0x3c, 0x2, 0xe8, 0x43, 0xb0}, + {0x33, 0xa, 0x5b, 0xca, 0x88, 0x29, 0xa1, 0x75, 0x7f, 0x34, 0x19, 0x4d, 0xb4, 0x16, 0x53, 0x5c, 0x92, 0x3b, 0x94, 0xc3, 0xe, 0x79, 0x4d, 0x1e, 0x79, 0x74, 0x75, 0xd7, 0xb6, 0xee, 0xaf, 0x3f}, + {0xea, 0xa8, 0xd4, 0xf7, 0xbe, 0x1a, 0x39, 0x21, 0x5c, 0xf4, 0x7e, 0x9, 0x4c, 0x23, 0x27, 0x51, 0x26, 0xa3, 0x24, 0x53, 0xba, 0x32, 0x3c, 0xd2, 0x44, 0xa3, 0x17, 0x4a, 0x6d, 0xa6, 0xd5, 0xad}, + {0xb5, 0x1d, 0x3e, 0xa6, 0xaf, 0xf2, 0xc9, 0x8, 0x83, 0x59, 0x3d, 0x98, 0x91, 0x6b, 0x3c, 0x56, 0x4c, 0xf8, 0x7c, 0xa1, 0x72, 0x86, 0x60, 0x4d, 0x46, 0xe2, 0x3e, 0xcc, 0x8, 0x6e, 0xc7, 0xf6}, + {0x2f, 0x98, 0x33, 0xb3, 0xb1, 0xbc, 0x76, 0x5e, 0x2b, 0xd6, 0x66, 0xa5, 0xef, 0xc4, 0xe6, 0x2a, 0x6, 0xf4, 0xb6, 0xe8, 0xbe, 0xc1, 0xd4, 0x36, 0x74, 0xee, 0x82, 0x15, 0xbc, 0xef, 0x21, 0x63}, + {0xfd, 0xc1, 0x4e, 0xd, 0xf4, 0x53, 0xc9, 0x69, 0xa7, 0x7d, 0x5a, 0xc4, 0x6, 0x58, 0x58, 0x26, 0x7e, 0xc1, 0x14, 0x16, 0x6, 0xe0, 0xfa, 0x16, 0x7e, 0x90, 0xaf, 0x3d, 0x28, 0x63, 0x9d, 0x3f}, + {0xd2, 0xc9, 0xf2, 0xe3, 0x0, 0x9b, 0xd2, 0xc, 0x5f, 0xaa, 0xce, 0x30, 0xb7, 0xd4, 0xc, 0x30, 0x74, 0x2a, 0x51, 0x16, 0xf2, 0xe0, 0x32, 0x98, 0xd, 0xeb, 0x30, 0xd8, 0xe3, 0xce, 0xf8, 0x9a}, + {0x4b, 0xc5, 0x9e, 0x7b, 0xb5, 0xf1, 0x79, 0x92, 0xff, 0x51, 0xe6, 0x6e, 0x4, 0x86, 0x68, 0xd3, 0x9b, 0x23, 0x4d, 0x57, 0xe6, 0x96, 0x67, 0x31, 0xcc, 0xe6, 0xa6, 0xf3, 0x17, 0xa, 0x75, 0x5}, + {0xb1, 0x76, 0x81, 0xd9, 0x13, 0x32, 0x6c, 0xce, 0x3c, 0x17, 0x52, 0x84, 0xf8, 0x5, 0xa2, 0x62, 0xf4, 0x2b, 0xcb, 0xb3, 0x78, 0x47, 0x15, 0x47, 0xff, 0x46, 0x54, 0x82, 0x23, 0x93, 0x6a, 0x48}, + {0x38, 0xdf, 0x58, 0x7, 0x4e, 0x5e, 0x65, 0x65, 0xf2, 0xfc, 0x7c, 0x89, 0xfc, 0x86, 0x50, 0x8e, 0x31, 0x70, 0x2e, 0x44, 0xd0, 0xb, 0xca, 0x86, 0xf0, 0x40, 0x9, 0xa2, 0x30, 0x78, 0x47, 0x4e}, + {0x65, 0xa0, 0xee, 0x39, 0xd1, 0xf7, 0x38, 0x83, 0xf7, 0x5e, 0xe9, 0x37, 0xe4, 0x2c, 0x3a, 0xbd, 0x21, 0x97, 0xb2, 0x26, 0x1, 0x13, 0xf8, 0x6f, 0xa3, 0x44, 0xed, 0xd1, 0xef, 0x9f, 0xde, 0xe7}, + {0x8b, 0xa0, 0xdf, 0x15, 0x76, 0x25, 0x92, 0xd9, 0x3c, 0x85, 0xf7, 0xf6, 0x12, 0xdc, 0x42, 0xbe, 0xd8, 0xa7, 0xec, 0x7c, 0xab, 0x27, 0xb0, 0x7e, 0x53, 0x8d, 0x7d, 0xda, 0xaa, 0x3e, 0xa8, 0xde}, + {0xaa, 0x25, 0xce, 0x93, 0xbd, 0x2, 0x69, 0xd8, 0x5a, 0xf6, 0x43, 0xfd, 0x1a, 0x73, 0x8, 0xf9, 0xc0, 0x5f, 0xef, 0xda, 0x17, 0x4a, 0x19, 0xa5, 0x97, 0x4d, 0x66, 0x33, 0x4c, 0xfd, 0x21, 0x6a}, + {0x35, 0xb4, 0x98, 0x31, 0xdb, 0x41, 0x15, 0x70, 0xea, 0x1e, 0xf, 0xbb, 0xed, 0xcd, 0x54, 0x9b, 0x9a, 0xd0, 0x63, 0xa1, 0x51, 0x97, 0x40, 0x72, 0xf6, 0x75, 0x9d, 0xbf, 0x91, 0x47, 0x6f, 0xe2} +}; + +#define JH_SWAP1(x) (x) = ((((x) & 0x5555555555555555ULL) << 1) | (((x) & 0xaaaaaaaaaaaaaaaaULL) >> 1)); +#define JH_SWAP2(x) (x) = ((((x) & 0x3333333333333333ULL) << 2) | (((x) & 0xccccccccccccccccULL) >> 2)); +#define JH_SWAP4(x) (x) = ((((x) & 0x0f0f0f0f0f0f0f0fULL) << 4) | (((x) & 0xf0f0f0f0f0f0f0f0ULL) >> 4)); +#define JH_SWAP8(x) (x) = ((((x) & 0x00ff00ff00ff00ffULL) << 8) | (((x) & 0xff00ff00ff00ff00ULL) >> 8)); +#define JH_SWAP16(x) (x) = ((((x) & 0x0000ffff0000ffffULL) << 16) | (((x) & 0xffff0000ffff0000ULL) >> 16)); +#define JH_SWAP32(x) (x) = (((x) << 32) | ((x) >> 32)); + +#define JH_L(m0,m1,m2,m3,m4,m5,m6,m7) \ + (m4) ^= (m1); \ + (m5) ^= (m2); \ + (m6) ^= (m0) ^ (m3); \ + (m7) ^= (m0); \ + (m0) ^= (m5); \ + (m1) ^= (m6); \ + (m2) ^= (m4) ^ (m7); \ + (m3) ^= (m4); + +#define JH_SS(m0,m1,m2,m3,m4,m5,m6,m7,cc0,cc1) \ + m3 = ~(m3); \ + m7 = ~(m7); \ + m0 ^= ((~(m2)) & (cc0)); \ + m4 ^= ((~(m6)) & (cc1)); \ + temp0 = (cc0) ^ ((m0) & (m1));\ + temp1 = (cc1) ^ ((m4) & (m5));\ + m0 ^= ((m2) & (m3)); \ + m4 ^= ((m6) & (m7)); \ + m3 ^= ((~(m1)) & (m2)); \ + m7 ^= ((~(m5)) & (m6)); \ + m1 ^= ((m0) & (m2)); \ + m5 ^= ((m4) & (m6)); \ + m2 ^= ((m0) & (~(m3))); \ + m6 ^= ((m4) & (~(m7))); \ + m0 ^= ((m1) | (m3)); \ + m4 ^= ((m5) | (m7)); \ + m3 ^= ((m1) & (m2)); \ + m7 ^= ((m5) & (m6)); \ + m1 ^= (temp0 & (m0)); \ + m5 ^= (temp1 & (m4)); \ + m2 ^= temp0; \ + m6 ^= temp1; + +__device__ void cn_jh_E8(jhHashState *state) +{ + uint64_t i,roundnumber,temp0,temp1; + + for (roundnumber = 0; roundnumber < 42; roundnumber = roundnumber+7) { + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+0])[i],((uint64_t *)d_E8_rc[roundnumber+0])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + JH_SWAP1(state->x[1][i]); JH_SWAP1(state->x[3][i]); JH_SWAP1(state->x[5][i]); JH_SWAP1(state->x[7][i]); + } + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+1])[i],((uint64_t *)d_E8_rc[roundnumber+1])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + JH_SWAP2(state->x[1][i]); JH_SWAP2(state->x[3][i]); JH_SWAP2(state->x[5][i]); JH_SWAP2(state->x[7][i]); + } + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+2])[i],((uint64_t *)d_E8_rc[roundnumber+2])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + JH_SWAP4(state->x[1][i]); JH_SWAP4(state->x[3][i]); JH_SWAP4(state->x[5][i]); JH_SWAP4(state->x[7][i]); + } + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+3])[i],((uint64_t *)d_E8_rc[roundnumber+3])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + JH_SWAP8(state->x[1][i]); JH_SWAP8(state->x[3][i]); JH_SWAP8(state->x[5][i]); JH_SWAP8(state->x[7][i]); + } + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+4])[i],((uint64_t *)d_E8_rc[roundnumber+4])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + JH_SWAP16(state->x[1][i]); JH_SWAP16(state->x[3][i]); JH_SWAP16(state->x[5][i]); JH_SWAP16(state->x[7][i]); + } + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+5])[i],((uint64_t *)d_E8_rc[roundnumber+5])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + JH_SWAP32(state->x[1][i]); JH_SWAP32(state->x[3][i]); JH_SWAP32(state->x[5][i]); JH_SWAP32(state->x[7][i]); + } + + for (i = 0; i < 2; i++) { + JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],((uint64_t *)d_E8_rc[roundnumber+6])[i],((uint64_t *)d_E8_rc[roundnumber+6])[i+2] ); + JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]); + } + + for (i = 1; i < 8; i = i+2) { + temp0 = state->x[i][0]; state->x[i][0] = state->x[i][1]; state->x[i][1] = temp0; + } + } +} + +__device__ void cn_jh_F8(jhHashState *state) +{ + uint64_t i; + + for (i = 0; i < 8; i++) state->x[i >> 1][i & 1] ^= ((uint64_t *)state->buffer)[i]; + + cn_jh_E8(state); + + for (i = 0; i < 8; i++) state->x[(8+i) >> 1][(8+i) & 1] ^= ((uint64_t *)state->buffer)[i]; +} + +__device__ void cn_jh_update(jhHashState * __restrict__ state, const BitSequence * __restrict__ data, DataLength databitlen) +{ + DataLength index; + + state->databitlen += databitlen; + index = 0; + + if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) < 512) ) { + if ( (databitlen & 7) == 0 ) { + memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)) ; + } + else memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)+1) ; + state->datasize_in_buffer += databitlen; + databitlen = 0; + } + + if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) >= 512) ) { + memcpy( state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3) ) ; + index = 64-(state->datasize_in_buffer >> 3); + databitlen = databitlen - (512 - state->datasize_in_buffer); + cn_jh_F8(state); + state->datasize_in_buffer = 0; + } + + for ( ; databitlen >= 512; index = index+64, databitlen = databitlen - 512) { + memcpy(state->buffer, data+index, 64); + cn_jh_F8(state); + } + + if ( databitlen > 0) { + if ((databitlen & 7) == 0) + memcpy(state->buffer, data+index, (databitlen & 0x1ff) >> 3); + else + memcpy(state->buffer, data+index, ((databitlen & 0x1ff) >> 3)+1); + state->datasize_in_buffer = databitlen; + } +} + +/*pad the message, process the padded block(s), truncate the hash value H to obtain the message digest*/ +__device__ void cn_jh_final(jhHashState * __restrict__ state, BitSequence * __restrict__ hashval) +{ + unsigned int i; + //uint32_t *bufptr = (uint32_t *)state->buffer; + + if ( (state->databitlen & 0x1ff) == 0 ) { + /*pad the message when databitlen is multiple of 512 bits, then process the padded block*/ + memset(state->buffer, 0, 64); + //for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000; + state->buffer[0] = 0x80; + state->buffer[63] = state->databitlen & 0xff; + state->buffer[62] = (state->databitlen >> 8) & 0xff; + state->buffer[61] = (state->databitlen >> 16) & 0xff; + state->buffer[60] = (state->databitlen >> 24) & 0xff; + state->buffer[59] = (state->databitlen >> 32) & 0xff; + state->buffer[58] = (state->databitlen >> 40) & 0xff; + state->buffer[57] = (state->databitlen >> 48) & 0xff; + state->buffer[56] = (state->databitlen >> 56) & 0xff; + cn_jh_F8(state); + } + else { + /*set the rest of the bytes in the buffer to 0*/ + if ( (state->datasize_in_buffer & 7) == 0) + for (i = (state->databitlen & 0x1ff) >> 3; i < 64; i++) state->buffer[i] = 0; + else + for (i = ((state->databitlen & 0x1ff) >> 3)+1; i < 64; i++) state->buffer[i] = 0; + + /*pad and process the partial block when databitlen is not multiple of 512 bits, then hash the padded blocks*/ + state->buffer[((state->databitlen & 0x1ff) >> 3)] |= 1 << (7- (state->databitlen & 7)); + + cn_jh_F8(state); + memset(state->buffer, 0, 64); + //for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000; + state->buffer[63] = state->databitlen & 0xff; + state->buffer[62] = (state->databitlen >> 8) & 0xff; + state->buffer[61] = (state->databitlen >> 16) & 0xff; + state->buffer[60] = (state->databitlen >> 24) & 0xff; + state->buffer[59] = (state->databitlen >> 32) & 0xff; + state->buffer[58] = (state->databitlen >> 40) & 0xff; + state->buffer[57] = (state->databitlen >> 48) & 0xff; + state->buffer[56] = (state->databitlen >> 56) & 0xff; + cn_jh_F8(state); + } + + memcpy(hashval,(unsigned char*)state->x+64+32,32); +} + +__device__ void cn_jh_init(jhHashState *state, int hashbitlen) +{ + state->databitlen = 0; + state->datasize_in_buffer = 0; + state->hashbitlen = hashbitlen; + memcpy(state->x, d_JH256_H0, 128); +} + +__device__ void cn_jh(const BitSequence * __restrict__ data, DataLength len, BitSequence * __restrict__ hashval) +{ + int hashbitlen = 256; + DataLength databitlen = len << 3; + jhHashState state; + + cn_jh_init(&state, hashbitlen); + cn_jh_update(&state, data, databitlen); + cn_jh_final(&state, hashval); +} diff --git a/cryptonight/cuda_cryptonight_keccak.cu b/cryptonight/cuda_cryptonight_keccak.cu index 50b6dc0..9137ae2 100755 --- a/cryptonight/cuda_cryptonight_keccak.cu +++ b/cryptonight/cuda_cryptonight_keccak.cu @@ -1,106 +1,209 @@ -__constant__ uint64_t keccakf_rndc[24]; - -const uint64_t h_keccakf_rndc[24] = -{ - 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, - 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, - 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, - 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, - 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, - 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, - 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, - 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 -}; - -#if __CUDA_ARCH__ >= 350 - __forceinline__ __device__ uint64_t cuda_rotl64(const uint64_t value, const int offset) - { - uint2 result; - if(offset >= 32) - { - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); - } - else - { - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); - asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); - } - return __double_as_longlong(__hiloint2double(result.y, result.x)); - } - #define rotl64_1(x, y) (cuda_rotl64((x), (y))) -#else - #define rotl64_1(x, y) ((x) << (y) | ((x) >> (64 - (y)))) -#endif - -#define rotl64_2(x, y) rotl64_1(((x) >> 32) | ((x) << 32), (y)) -#define bitselect(a, b, c) ((a) ^ ((c) & ((b) ^ (a)))) - -__device__ __forceinline__ void cn_keccakf(uint64_t *s) -{ - uint8_t i; - - for (i = 0; i < 24; ++i) - { - uint64_t bc[5], tmpxor[5], tmp1, tmp2, x; - - for(x = 0; x < 5; x++) - tmpxor[x] = s[x] ^ s[x + 5] ^ s[x + 10] ^ s[x + 15] ^ s[x + 20]; - - bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1); - bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1); - bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1); - bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1); - bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1); - - tmp1 = s[1] ^ bc[0]; - - s[0] ^= bc[4]; - s[1] = rotl64_2(s[6] ^ bc[0], 12); - s[6] = rotl64_1(s[9] ^ bc[3], 20); - s[9] = rotl64_2(s[22] ^ bc[1], 29); - s[22] = rotl64_2(s[14] ^ bc[3], 7); - s[14] = rotl64_1(s[20] ^ bc[4], 18); - s[20] = rotl64_2(s[2] ^ bc[1], 30); - s[2] = rotl64_2(s[12] ^ bc[1], 11); - s[12] = rotl64_1(s[13] ^ bc[2], 25); - s[13] = rotl64_1(s[19] ^ bc[3], 8); - s[19] = rotl64_2(s[23] ^ bc[2], 24); - s[23] = rotl64_2(s[15] ^ bc[4], 9); - s[15] = rotl64_1(s[4] ^ bc[3], 27); - s[4] = rotl64_1(s[24] ^ bc[3], 14); - s[24] = rotl64_1(s[21] ^ bc[0], 2); - s[21] = rotl64_2(s[8] ^ bc[2], 23); - s[8] = rotl64_2(s[16] ^ bc[0], 13); - s[16] = rotl64_2(s[5] ^ bc[4], 4); - s[5] = rotl64_1(s[3] ^ bc[2], 28); - s[3] = rotl64_1(s[18] ^ bc[2], 21); - s[18] = rotl64_1(s[17] ^ bc[1], 15); - s[17] = rotl64_1(s[11] ^ bc[0], 10); - s[11] = rotl64_1(s[7] ^ bc[1], 6); - s[7] = rotl64_1(s[10] ^ bc[4], 3); - s[10] = rotl64_1(tmp1, 1); - - tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1); - tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1); - tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1); - tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1); - tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1); - s[0] ^= keccakf_rndc[i]; - } -} - -__device__ __forceinline__ void cn_keccak(const uint8_t * __restrict__ in, uint8_t * __restrict__ md) -{ - uint64_t st[25]; - - MEMCPY4(st, in, 19); - MEMSET8(&st[10], 0x00, 15); - st[9] = (st[9] & 0x00000000FFFFFFFFULL) | 0x0000000100000000ULL; - st[16] = 0x8000000000000000ULL; - - cn_keccakf(st); - - MEMCPY8(md, st, 25); - return; -} +__constant__ uint64_t keccakf_rndc[24] = +{ + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 +}; + +#if __CUDA_ARCH__ >= 350 + __forceinline__ __device__ uint64_t cuda_rotl64(const uint64_t value, const int offset) + { + uint2 result; + if(offset >= 32) + { + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); + } + else + { + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); + asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); + } + return __double_as_longlong(__hiloint2double(result.y, result.x)); + } + #define rotl64_1(x, y) (cuda_rotl64((x), (y))) +#else + #define rotl64_1(x, y) ((x) << (y) | ((x) >> (64 - (y)))) +#endif + +#define rotl64_2(x, y) rotl64_1(((x) >> 32) | ((x) << 32), (y)) +#define bitselect(a, b, c) ((a) ^ ((c) & ((b) ^ (a)))) + +__device__ __forceinline__ void cn_keccakf2(uint64_t *s) +{ + uint8_t i; + + for(i = 0; i < 24; ++i) + { + uint64_t bc[5], tmpxor[5], tmp1, tmp2; + + tmpxor[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20]; + tmpxor[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21]; + tmpxor[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22]; + tmpxor[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23]; + tmpxor[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24]; + + bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1); + bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1); + bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1); + bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1); + bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1); + + tmp1 = s[1] ^ bc[0]; + + s[0] ^= bc[4]; + s[1] = rotl64_2(s[6] ^ bc[0], 12); + s[6] = rotl64_1(s[9] ^ bc[3], 20); + s[9] = rotl64_2(s[22] ^ bc[1], 29); + s[22] = rotl64_2(s[14] ^ bc[3], 7); + s[14] = rotl64_1(s[20] ^ bc[4], 18); + s[20] = rotl64_2(s[2] ^ bc[1], 30); + s[2] = rotl64_2(s[12] ^ bc[1], 11); + s[12] = rotl64_1(s[13] ^ bc[2], 25); + s[13] = rotl64_1(s[19] ^ bc[3], 8); + s[19] = rotl64_2(s[23] ^ bc[2], 24); + s[23] = rotl64_2(s[15] ^ bc[4], 9); + s[15] = rotl64_1(s[4] ^ bc[3], 27); + s[4] = rotl64_1(s[24] ^ bc[3], 14); + s[24] = rotl64_1(s[21] ^ bc[0], 2); + s[21] = rotl64_2(s[8] ^ bc[2], 23); + s[8] = rotl64_2(s[16] ^ bc[0], 13); + s[16] = rotl64_2(s[5] ^ bc[4], 4); + s[5] = rotl64_1(s[3] ^ bc[2], 28); + s[3] = rotl64_1(s[18] ^ bc[2], 21); + s[18] = rotl64_1(s[17] ^ bc[1], 15); + s[17] = rotl64_1(s[11] ^ bc[0], 10); + s[11] = rotl64_1(s[7] ^ bc[1], 6); + s[7] = rotl64_1(s[10] ^ bc[4], 3); + s[10] = rotl64_1(tmp1, 1); + + tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1); + tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1); + tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1); + tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1); + tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1); + s[0] ^= keccakf_rndc[i]; + } +} + +__device__ __forceinline__ void cn_keccakf(uint64_t *s) +{ + uint64_t bc[5], tmpxor[5], tmp1, tmp2; + + tmpxor[0] = s[0] ^ s[5]; + tmpxor[1] = s[1] ^ s[6] ^ 0x8000000000000000ULL; + tmpxor[2] = s[2] ^ s[7]; + tmpxor[3] = s[3] ^ s[8]; + tmpxor[4] = s[4] ^ s[9]; + + bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1); + bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1); + bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1); + bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1); + bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1); + + tmp1 = s[1] ^ bc[0]; + + s[0] ^= bc[4]; + s[1] = rotl64_2(s[6] ^ bc[0], 12); + s[6] = rotl64_1(s[9] ^ bc[3], 20); + s[9] = rotl64_2(bc[1], 29); + s[22] = rotl64_2(bc[3], 7); + s[14] = rotl64_1(bc[4], 18); + s[20] = rotl64_2(s[2] ^ bc[1], 30); + s[2] = rotl64_2(bc[1], 11); + s[12] = rotl64_1(bc[2], 25); + s[13] = rotl64_1(bc[3], 8); + s[19] = rotl64_2(bc[2], 24); + s[23] = rotl64_2(bc[4], 9); + s[15] = rotl64_1(s[4] ^ bc[3], 27); + s[4] = rotl64_1(bc[3], 14); + s[24] = rotl64_1(bc[0], 2); + s[21] = rotl64_2(s[8] ^ bc[2], 23); + s[8] = rotl64_2(0x8000000000000000ULL ^ bc[0], 13); + s[16] = rotl64_2(s[5] ^ bc[4], 4); + s[5] = rotl64_1(s[3] ^ bc[2], 28); + s[3] = rotl64_1(bc[2], 21); + s[18] = rotl64_1(bc[1], 15); + s[17] = rotl64_1(bc[0], 10); + s[11] = rotl64_1(s[7] ^ bc[1], 6); + s[7] = rotl64_1(bc[4], 3); + s[10] = rotl64_1(tmp1, 1); + + tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1); + tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1); + tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1); + tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1); + tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1); + s[0] ^= 0x0000000000000001; + + for(int i = 1; i < 24; ++i) + { + tmpxor[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20]; + tmpxor[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21]; + tmpxor[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22]; + tmpxor[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23]; + tmpxor[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24]; + + bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1); + bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1); + bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1); + bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1); + bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1); + + tmp1 = s[1] ^ bc[0]; + + s[0] ^= bc[4]; + s[1] = rotl64_2(s[6] ^ bc[0], 12); + s[6] = rotl64_1(s[9] ^ bc[3], 20); + s[9] = rotl64_2(s[22] ^ bc[1], 29); + s[22] = rotl64_2(s[14] ^ bc[3], 7); + s[14] = rotl64_1(s[20] ^ bc[4], 18); + s[20] = rotl64_2(s[2] ^ bc[1], 30); + s[2] = rotl64_2(s[12] ^ bc[1], 11); + s[12] = rotl64_1(s[13] ^ bc[2], 25); + s[13] = rotl64_1(s[19] ^ bc[3], 8); + s[19] = rotl64_2(s[23] ^ bc[2], 24); + s[23] = rotl64_2(s[15] ^ bc[4], 9); + s[15] = rotl64_1(s[4] ^ bc[3], 27); + s[4] = rotl64_1(s[24] ^ bc[3], 14); + s[24] = rotl64_1(s[21] ^ bc[0], 2); + s[21] = rotl64_2(s[8] ^ bc[2], 23); + s[8] = rotl64_2(s[16] ^ bc[0], 13); + s[16] = rotl64_2(s[5] ^ bc[4], 4); + s[5] = rotl64_1(s[3] ^ bc[2], 28); + s[3] = rotl64_1(s[18] ^ bc[2], 21); + s[18] = rotl64_1(s[17] ^ bc[1], 15); + s[17] = rotl64_1(s[11] ^ bc[0], 10); + s[11] = rotl64_1(s[7] ^ bc[1], 6); + s[7] = rotl64_1(s[10] ^ bc[4], 3); + s[10] = rotl64_1(tmp1, 1); + + tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1); + tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1); + tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1); + tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1); + tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1); + s[0] ^= keccakf_rndc[i]; + } +} + +__device__ __forceinline__ void cn_keccak(const uint32_t * __restrict__ in, uint64_t * __restrict__ md) +{ + uint64_t st[25]; + + MEMCPY4(st, in, 19); + MEMSET8(&st[10], 0x00, 15); + st[9] = (st[9] & 0x00000000FFFFFFFFULL) | 0x0000000100000000ULL; + st[16] = 0x8000000000000000ULL; + + cn_keccakf(st); + + MEMCPY8(md, st, 25); + return; +} diff --git a/cryptonight/cuda_cryptonight_skein.cu b/cryptonight/cuda_cryptonight_skein.cu index e31341a..2d87f5b 100755 --- a/cryptonight/cuda_cryptonight_skein.cu +++ b/cryptonight/cuda_cryptonight_skein.cu @@ -1,339 +1,339 @@ -typedef unsigned int uint_t; /* native unsigned integer */ - -#define SKEIN_MODIFIER_WORDS ( 2) /* number of modifier (tweak) words */ - -#define SKEIN_256_STATE_WORDS ( 4) -#define SKEIN_512_STATE_WORDS ( 8) -#define SKEIN1024_STATE_WORDS (16) - -#define SKEIN_256_STATE_BYTES ( 8*SKEIN_256_STATE_WORDS) -#define SKEIN_512_STATE_BYTES ( 8*SKEIN_512_STATE_WORDS) -#define SKEIN1024_STATE_BYTES ( 8*SKEIN1024_STATE_WORDS) - -#define SKEIN_256_STATE_BITS (64*SKEIN_256_STATE_WORDS) -#define SKEIN_512_STATE_BITS (64*SKEIN_512_STATE_WORDS) -#define SKEIN1024_STATE_BITS (64*SKEIN1024_STATE_WORDS) - -#define SKEIN_256_BLOCK_BYTES ( 8*SKEIN_256_STATE_WORDS) -#define SKEIN_512_BLOCK_BYTES ( 8*SKEIN_512_STATE_WORDS) -#define SKEIN1024_BLOCK_BYTES ( 8*SKEIN1024_STATE_WORDS) - -#define SKEIN_MK_64(hi32,lo32) ((lo32) + (((uint64_t) (hi32)) << 32)) -#define SKEIN_KS_PARITY SKEIN_MK_64(0x1BD11BDA,0xA9FC1A22) - -#define SKEIN_T1_BIT(BIT) ((BIT) - 64) /* offset 64 because it's the second word */ - -#define SKEIN_T1_POS_FIRST SKEIN_T1_BIT(126) /* bits 126 : first block flag */ -#define SKEIN_T1_POS_BIT_PAD SKEIN_T1_BIT(119) /* bit 119 : partial final input byte */ -#define SKEIN_T1_POS_FINAL SKEIN_T1_BIT(127) /* bit 127 : final block flag */ -#define SKEIN_T1_POS_BLK_TYPE SKEIN_T1_BIT(120) /* bits 120..125: type field */ - -#define SKEIN_T1_FLAG_FIRST (((uint64_t) 1 ) << SKEIN_T1_POS_FIRST) -#define SKEIN_T1_FLAG_BIT_PAD (((uint64_t) 1 ) << SKEIN_T1_POS_BIT_PAD) -#define SKEIN_T1_FLAG_FINAL (((uint64_t) 1 ) << SKEIN_T1_POS_FINAL) - -#define SKEIN_BLK_TYPE_MSG (48) /* message processing */ -#define SKEIN_BLK_TYPE_OUT (63) /* output stage */ - -#define SKEIN_T1_BLK_TYPE(T) (((uint64_t) (SKEIN_BLK_TYPE_##T)) << SKEIN_T1_POS_BLK_TYPE) - -#define SKEIN_T1_BLK_TYPE_MSG SKEIN_T1_BLK_TYPE(MSG) /* message processing */ -#define SKEIN_T1_BLK_TYPE_OUT SKEIN_T1_BLK_TYPE(OUT) /* output stage */ - -#define SKEIN_T1_BLK_TYPE_OUT_FINAL (SKEIN_T1_BLK_TYPE_OUT | SKEIN_T1_FLAG_FINAL) - -#define Skein_Set_Tweak(ctxPtr,TWK_NUM,tVal) {(ctxPtr)->h.T[TWK_NUM] = (tVal);} - -#define Skein_Set_T0(ctxPtr,T0) Skein_Set_Tweak(ctxPtr,0,T0) -#define Skein_Set_T1(ctxPtr,T1) Skein_Set_Tweak(ctxPtr,1,T1) - -#define Skein_Set_T0_T1(ctxPtr,T0,T1) { \ - Skein_Set_T0(ctxPtr,(T0)); \ - Skein_Set_T1(ctxPtr,(T1)); } - -#define Skein_Start_New_Type(ctxPtr,BLK_TYPE) \ -{ Skein_Set_T0_T1(ctxPtr,0,SKEIN_T1_FLAG_FIRST | SKEIN_T1_BLK_TYPE_##BLK_TYPE); (ctxPtr)->h.bCnt=0; } - -#define Skein_Set_Bit_Pad_Flag(hdr) { (hdr).T[1] |= SKEIN_T1_FLAG_BIT_PAD; } - -#define KW_TWK_BASE (0) -#define KW_KEY_BASE (3) -#define ks (kw + KW_KEY_BASE) -#define ts (kw + KW_TWK_BASE) - -#define R512(p0,p1,p2,p3,p4,p5,p6,p7,R512ROT,rNum) \ - X##p0 += X##p1; X##p1 = ROTL64(X##p1,R512ROT##_0); X##p1 ^= X##p0; \ - X##p2 += X##p3; X##p3 = ROTL64(X##p3,R512ROT##_1); X##p3 ^= X##p2; \ - X##p4 += X##p5; X##p5 = ROTL64(X##p5,R512ROT##_2); X##p5 ^= X##p4; \ - X##p6 += X##p7; X##p7 = ROTL64(X##p7,R512ROT##_3); X##p7 ^= X##p6; - -#define I512(R) \ - X0 += ks[((R)+1) % 9]; \ - X1 += ks[((R)+2) % 9]; \ - X2 += ks[((R)+3) % 9]; \ - X3 += ks[((R)+4) % 9]; \ - X4 += ks[((R)+5) % 9]; \ - X5 += ks[((R)+6) % 9] + ts[((R)+1) % 3]; \ - X6 += ks[((R)+7) % 9] + ts[((R)+2) % 3]; \ - X7 += ks[((R)+8) % 9] + (R)+1; - - -#define R512_8_rounds(R) \ - R512(0,1,2,3,4,5,6,7,R_512_0,8*(R)+ 1); \ - R512(2,1,4,7,6,5,0,3,R_512_1,8*(R)+ 2); \ - R512(4,1,6,3,0,5,2,7,R_512_2,8*(R)+ 3); \ - R512(6,1,0,7,2,5,4,3,R_512_3,8*(R)+ 4); \ - I512(2*(R)); \ - R512(0,1,2,3,4,5,6,7,R_512_4,8*(R)+ 5); \ - R512(2,1,4,7,6,5,0,3,R_512_5,8*(R)+ 6); \ - R512(4,1,6,3,0,5,2,7,R_512_6,8*(R)+ 7); \ - R512(6,1,0,7,2,5,4,3,R_512_7,8*(R)+ 8); \ - I512(2*(R)+1); - -typedef struct -{ - size_t hashBitLen; - size_t bCnt; - uint64_t T[SKEIN_MODIFIER_WORDS]; -} Skein_Ctxt_Hdr_t; - -typedef struct { - Skein_Ctxt_Hdr_t h; - uint64_t X[SKEIN_256_STATE_WORDS]; - uint8_t b[SKEIN_256_BLOCK_BYTES]; -} Skein_256_Ctxt_t; - -typedef struct { - Skein_Ctxt_Hdr_t h; - uint64_t X[SKEIN_512_STATE_WORDS]; - uint8_t b[SKEIN_512_BLOCK_BYTES]; -} Skein_512_Ctxt_t; - -typedef struct { - Skein_Ctxt_Hdr_t h; - uint64_t X[SKEIN1024_STATE_WORDS]; - uint8_t b[SKEIN1024_BLOCK_BYTES]; -} Skein1024_Ctxt_t; - -typedef struct { - uint_t statebits; - union { - Skein_Ctxt_Hdr_t h; - Skein_256_Ctxt_t ctx_256; - Skein_512_Ctxt_t ctx_512; - Skein1024_Ctxt_t ctx1024; - } u; -} skeinHashState; - -__device__ void cn_skein_init(skeinHashState *state, size_t hashBitLen) -{ - const uint64_t SKEIN_512_IV_256[] = - { - SKEIN_MK_64(0xCCD044A1,0x2FDB3E13), - SKEIN_MK_64(0xE8359030,0x1A79A9EB), - SKEIN_MK_64(0x55AEA061,0x4F816E6F), - SKEIN_MK_64(0x2A2767A4,0xAE9B94DB), - SKEIN_MK_64(0xEC06025E,0x74DD7683), - SKEIN_MK_64(0xE7A436CD,0xC4746251), - SKEIN_MK_64(0xC36FBAF9,0x393AD185), - SKEIN_MK_64(0x3EEDBA18,0x33EDFC13) - }; - - Skein_512_Ctxt_t *ctx = &state->u.ctx_512; - - ctx->h.hashBitLen = hashBitLen; - - memcpy(ctx->X, SKEIN_512_IV_256, sizeof(ctx->X)); - - Skein_Start_New_Type(ctx, MSG); -} - -__device__ void cn_skein512_processblock(Skein_512_Ctxt_t *ctx,const uint8_t *blkPtr,size_t blkCnt,size_t byteCntAdd) -{ - enum { - R_512_0_0=46, R_512_0_1=36, R_512_0_2=19, R_512_0_3=37, - R_512_1_0=33, R_512_1_1=27, R_512_1_2=14, R_512_1_3=42, - R_512_2_0=17, R_512_2_1=49, R_512_2_2=36, R_512_2_3=39, - R_512_3_0=44, R_512_3_1= 9, R_512_3_2=54, R_512_3_3=56, - R_512_4_0=39, R_512_4_1=30, R_512_4_2=34, R_512_4_3=24, - R_512_5_0=13, R_512_5_1=50, R_512_5_2=10, R_512_5_3=17, - R_512_6_0=25, R_512_6_1=29, R_512_6_2=39, R_512_6_3=43, - R_512_7_0= 8, R_512_7_1=35, R_512_7_2=56, R_512_7_3=22 - }; - uint64_t X0,X1,X2,X3,X4,X5,X6,X7; - uint64_t w[SKEIN_512_STATE_WORDS]; - uint64_t kw[SKEIN_512_STATE_WORDS+4]; - - ts[0] = ctx->h.T[0]; - ts[1] = ctx->h.T[1]; - - do { - - ts[0] += byteCntAdd; - - ks[0] = ctx->X[0]; - ks[1] = ctx->X[1]; - ks[2] = ctx->X[2]; - ks[3] = ctx->X[3]; - ks[4] = ctx->X[4]; - ks[5] = ctx->X[5]; - ks[6] = ctx->X[6]; - ks[7] = ctx->X[7]; - ks[8] = ks[0] ^ ks[1] ^ ks[2] ^ ks[3] ^ - ks[4] ^ ks[5] ^ ks[6] ^ ks[7] ^ SKEIN_KS_PARITY; - - ts[2] = ts[0] ^ ts[1]; - - memcpy(w, blkPtr, SKEIN_512_STATE_WORDS << 3); - - X0 = w[0] + ks[0]; - X1 = w[1] + ks[1]; - X2 = w[2] + ks[2]; - X3 = w[3] + ks[3]; - X4 = w[4] + ks[4]; - X5 = w[5] + ks[5] + ts[0]; - X6 = w[6] + ks[6] + ts[1]; - X7 = w[7] + ks[7]; - - blkPtr += SKEIN_512_BLOCK_BYTES; - - R512_8_rounds( 0); - R512_8_rounds( 1); - R512_8_rounds( 2); - R512_8_rounds( 3); - R512_8_rounds( 4); - R512_8_rounds( 5); - R512_8_rounds( 6); - R512_8_rounds( 7); - R512_8_rounds( 8); - - ctx->X[0] = X0 ^ w[0]; - ctx->X[1] = X1 ^ w[1]; - ctx->X[2] = X2 ^ w[2]; - ctx->X[3] = X3 ^ w[3]; - ctx->X[4] = X4 ^ w[4]; - ctx->X[5] = X5 ^ w[5]; - ctx->X[6] = X6 ^ w[6]; - ctx->X[7] = X7 ^ w[7]; - - ts[1] &= ~SKEIN_T1_FLAG_FIRST; - } while (--blkCnt); - - ctx->h.T[0] = ts[0]; - ctx->h.T[1] = ts[1]; -} - -__device__ void cn_skein_final(skeinHashState *state, uint8_t *hashVal) -{ - size_t i,n,byteCnt; - uint64_t X[SKEIN_512_STATE_WORDS]; - Skein_512_Ctxt_t *ctx = (Skein_512_Ctxt_t *)&state->u.ctx_512; - //size_t tmp; - //uint8_t *p8; - //uint64_t *p64; - - ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; - - if (ctx->h.bCnt < SKEIN_512_BLOCK_BYTES) { - - memset(&ctx->b[ctx->h.bCnt],0,SKEIN_512_BLOCK_BYTES - ctx->h.bCnt); - //p8 = &ctx->b[ctx->h.bCnt]; - //tmp = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt; - //for( i = 0; i < tmp; i++ ) *(p8+i) = 0; - } - - cn_skein512_processblock(ctx,ctx->b,1,ctx->h.bCnt); - - byteCnt = (ctx->h.hashBitLen + 7) >> 3; - - //uint8_t b[SKEIN_512_BLOCK_BYTES] == 64 - memset(ctx->b,0,sizeof(ctx->b)); - //p64 = (uint64_t *)ctx->b; - //for( i = 0; i < 8; i++ ) *(p64+i) = 0; - - memcpy(X,ctx->X,sizeof(X)); - - for (i=0;i*SKEIN_512_BLOCK_BYTES < byteCnt;i++) { - - ((uint64_t *)ctx->b)[0]= (uint64_t)i; - Skein_Start_New_Type(ctx,OUT_FINAL); - cn_skein512_processblock(ctx,ctx->b,1,sizeof(uint64_t)); - n = byteCnt - i*SKEIN_512_BLOCK_BYTES; - if (n >= SKEIN_512_BLOCK_BYTES) - n = SKEIN_512_BLOCK_BYTES; - memcpy(hashVal+i*SKEIN_512_BLOCK_BYTES,ctx->X,n); - memcpy(ctx->X,X,sizeof(X)); /* restore the counter mode key for next time */ - } -} - -__device__ void cn_skein512_update(Skein_512_Ctxt_t *ctx, const uint8_t *msg, size_t msgByteCnt) -{ - size_t n; - - if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES) { - - if (ctx->h.bCnt) { - - n = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt; - - if (n) { - - memcpy(&ctx->b[ctx->h.bCnt],msg,n); - msgByteCnt -= n; - msg += n; - ctx->h.bCnt += n; - } - - cn_skein512_processblock(ctx,ctx->b,1,SKEIN_512_BLOCK_BYTES); - ctx->h.bCnt = 0; - } - - if (msgByteCnt > SKEIN_512_BLOCK_BYTES) { - - n = (msgByteCnt-1) / SKEIN_512_BLOCK_BYTES; - cn_skein512_processblock(ctx,msg,n,SKEIN_512_BLOCK_BYTES); - msgByteCnt -= n * SKEIN_512_BLOCK_BYTES; - msg += n * SKEIN_512_BLOCK_BYTES; - } - } - - if (msgByteCnt) { - - memcpy(&ctx->b[ctx->h.bCnt],msg,msgByteCnt); - ctx->h.bCnt += msgByteCnt; - } -} - -__device__ void cn_skein_update(skeinHashState *state, const BitSequence *data, DataLength databitlen) -{ - if ((databitlen & 7) == 0) { - - cn_skein512_update(&state->u.ctx_512,data,databitlen >> 3); - } - else { - - size_t bCnt = (databitlen >> 3) + 1; - uint8_t b,mask; - - mask = (uint8_t) (1u << (7 - (databitlen & 7))); - b = (uint8_t) ((data[bCnt-1] & (0-mask)) | mask); - - cn_skein512_update(&state->u.ctx_512,data,bCnt-1); - cn_skein512_update(&state->u.ctx_512,&b , 1 ); - - Skein_Set_Bit_Pad_Flag(state->u.h); - } -} - -__device__ void cn_skein(const BitSequence *data, DataLength len, BitSequence *hashval) -{ - int hashbitlen = 256; - DataLength databitlen = len << 3; - skeinHashState state; - - state.statebits = 64*SKEIN_512_STATE_WORDS; - - cn_skein_init(&state, hashbitlen); - cn_skein_update(&state, data, databitlen); - cn_skein_final(&state, hashval); -} +typedef unsigned int uint_t; /* native unsigned integer */ + +#define SKEIN_MODIFIER_WORDS ( 2) /* number of modifier (tweak) words */ + +#define SKEIN_256_STATE_WORDS ( 4) +#define SKEIN_512_STATE_WORDS ( 8) +#define SKEIN1024_STATE_WORDS (16) + +#define SKEIN_256_STATE_BYTES ( 8*SKEIN_256_STATE_WORDS) +#define SKEIN_512_STATE_BYTES ( 8*SKEIN_512_STATE_WORDS) +#define SKEIN1024_STATE_BYTES ( 8*SKEIN1024_STATE_WORDS) + +#define SKEIN_256_STATE_BITS (64*SKEIN_256_STATE_WORDS) +#define SKEIN_512_STATE_BITS (64*SKEIN_512_STATE_WORDS) +#define SKEIN1024_STATE_BITS (64*SKEIN1024_STATE_WORDS) + +#define SKEIN_256_BLOCK_BYTES ( 8*SKEIN_256_STATE_WORDS) +#define SKEIN_512_BLOCK_BYTES ( 8*SKEIN_512_STATE_WORDS) +#define SKEIN1024_BLOCK_BYTES ( 8*SKEIN1024_STATE_WORDS) + +#define SKEIN_MK_64(hi32,lo32) ((lo32) + (((uint64_t) (hi32)) << 32)) +#define SKEIN_KS_PARITY SKEIN_MK_64(0x1BD11BDA,0xA9FC1A22) + +#define SKEIN_T1_BIT(BIT) ((BIT) - 64) /* offset 64 because it's the second word */ + +#define SKEIN_T1_POS_FIRST SKEIN_T1_BIT(126) /* bits 126 : first block flag */ +#define SKEIN_T1_POS_BIT_PAD SKEIN_T1_BIT(119) /* bit 119 : partial final input byte */ +#define SKEIN_T1_POS_FINAL SKEIN_T1_BIT(127) /* bit 127 : final block flag */ +#define SKEIN_T1_POS_BLK_TYPE SKEIN_T1_BIT(120) /* bits 120..125: type field */ + +#define SKEIN_T1_FLAG_FIRST (((uint64_t) 1 ) << SKEIN_T1_POS_FIRST) +#define SKEIN_T1_FLAG_BIT_PAD (((uint64_t) 1 ) << SKEIN_T1_POS_BIT_PAD) +#define SKEIN_T1_FLAG_FINAL (((uint64_t) 1 ) << SKEIN_T1_POS_FINAL) + +#define SKEIN_BLK_TYPE_MSG (48) /* message processing */ +#define SKEIN_BLK_TYPE_OUT (63) /* output stage */ + +#define SKEIN_T1_BLK_TYPE(T) (((uint64_t) (SKEIN_BLK_TYPE_##T)) << SKEIN_T1_POS_BLK_TYPE) + +#define SKEIN_T1_BLK_TYPE_MSG SKEIN_T1_BLK_TYPE(MSG) /* message processing */ +#define SKEIN_T1_BLK_TYPE_OUT SKEIN_T1_BLK_TYPE(OUT) /* output stage */ + +#define SKEIN_T1_BLK_TYPE_OUT_FINAL (SKEIN_T1_BLK_TYPE_OUT | SKEIN_T1_FLAG_FINAL) + +#define Skein_Set_Tweak(ctxPtr,TWK_NUM,tVal) {(ctxPtr)->h.T[TWK_NUM] = (tVal);} + +#define Skein_Set_T0(ctxPtr,T0) Skein_Set_Tweak(ctxPtr,0,T0) +#define Skein_Set_T1(ctxPtr,T1) Skein_Set_Tweak(ctxPtr,1,T1) + +#define Skein_Set_T0_T1(ctxPtr,T0,T1) { \ + Skein_Set_T0(ctxPtr,(T0)); \ + Skein_Set_T1(ctxPtr,(T1)); } + +#define Skein_Start_New_Type(ctxPtr,BLK_TYPE) \ +{ Skein_Set_T0_T1(ctxPtr,0,SKEIN_T1_FLAG_FIRST | SKEIN_T1_BLK_TYPE_##BLK_TYPE); (ctxPtr)->h.bCnt=0; } + +#define Skein_Set_Bit_Pad_Flag(hdr) { (hdr).T[1] |= SKEIN_T1_FLAG_BIT_PAD; } + +#define KW_TWK_BASE (0) +#define KW_KEY_BASE (3) +#define ks (kw + KW_KEY_BASE) +#define ts (kw + KW_TWK_BASE) + +#define R512(p0,p1,p2,p3,p4,p5,p6,p7,R512ROT,rNum) \ + X##p0 += X##p1; X##p1 = ROTL64(X##p1,R512ROT##_0); X##p1 ^= X##p0; \ + X##p2 += X##p3; X##p3 = ROTL64(X##p3,R512ROT##_1); X##p3 ^= X##p2; \ + X##p4 += X##p5; X##p5 = ROTL64(X##p5,R512ROT##_2); X##p5 ^= X##p4; \ + X##p6 += X##p7; X##p7 = ROTL64(X##p7,R512ROT##_3); X##p7 ^= X##p6; + +#define I512(R) \ + X0 += ks[((R)+1) % 9]; \ + X1 += ks[((R)+2) % 9]; \ + X2 += ks[((R)+3) % 9]; \ + X3 += ks[((R)+4) % 9]; \ + X4 += ks[((R)+5) % 9]; \ + X5 += ks[((R)+6) % 9] + ts[((R)+1) % 3]; \ + X6 += ks[((R)+7) % 9] + ts[((R)+2) % 3]; \ + X7 += ks[((R)+8) % 9] + (R)+1; + + +#define R512_8_rounds(R) \ + R512(0,1,2,3,4,5,6,7,R_512_0,8*(R)+ 1); \ + R512(2,1,4,7,6,5,0,3,R_512_1,8*(R)+ 2); \ + R512(4,1,6,3,0,5,2,7,R_512_2,8*(R)+ 3); \ + R512(6,1,0,7,2,5,4,3,R_512_3,8*(R)+ 4); \ + I512(2*(R)); \ + R512(0,1,2,3,4,5,6,7,R_512_4,8*(R)+ 5); \ + R512(2,1,4,7,6,5,0,3,R_512_5,8*(R)+ 6); \ + R512(4,1,6,3,0,5,2,7,R_512_6,8*(R)+ 7); \ + R512(6,1,0,7,2,5,4,3,R_512_7,8*(R)+ 8); \ + I512(2*(R)+1); + +typedef struct +{ + size_t hashBitLen; + size_t bCnt; + uint64_t T[SKEIN_MODIFIER_WORDS]; +} Skein_Ctxt_Hdr_t; + +typedef struct { + Skein_Ctxt_Hdr_t h; + uint64_t X[SKEIN_256_STATE_WORDS]; + uint8_t b[SKEIN_256_BLOCK_BYTES]; +} Skein_256_Ctxt_t; + +typedef struct { + Skein_Ctxt_Hdr_t h; + uint64_t X[SKEIN_512_STATE_WORDS]; + uint8_t b[SKEIN_512_BLOCK_BYTES]; +} Skein_512_Ctxt_t; + +typedef struct { + Skein_Ctxt_Hdr_t h; + uint64_t X[SKEIN1024_STATE_WORDS]; + uint8_t b[SKEIN1024_BLOCK_BYTES]; +} Skein1024_Ctxt_t; + +typedef struct { + uint_t statebits; + union { + Skein_Ctxt_Hdr_t h; + Skein_256_Ctxt_t ctx_256; + Skein_512_Ctxt_t ctx_512; + Skein1024_Ctxt_t ctx1024; + } u; +} skeinHashState; + +__device__ void cn_skein_init(skeinHashState *state, size_t hashBitLen) +{ + const uint64_t SKEIN_512_IV_256[] = + { + SKEIN_MK_64(0xCCD044A1,0x2FDB3E13), + SKEIN_MK_64(0xE8359030,0x1A79A9EB), + SKEIN_MK_64(0x55AEA061,0x4F816E6F), + SKEIN_MK_64(0x2A2767A4,0xAE9B94DB), + SKEIN_MK_64(0xEC06025E,0x74DD7683), + SKEIN_MK_64(0xE7A436CD,0xC4746251), + SKEIN_MK_64(0xC36FBAF9,0x393AD185), + SKEIN_MK_64(0x3EEDBA18,0x33EDFC13) + }; + + Skein_512_Ctxt_t *ctx = &state->u.ctx_512; + + ctx->h.hashBitLen = hashBitLen; + + memcpy(ctx->X, SKEIN_512_IV_256, sizeof(ctx->X)); + + Skein_Start_New_Type(ctx, MSG); +} + +__device__ void cn_skein512_processblock(Skein_512_Ctxt_t * __restrict__ ctx, const uint8_t * __restrict__ blkPtr, size_t blkCnt, size_t byteCntAdd) +{ + enum { + R_512_0_0=46, R_512_0_1=36, R_512_0_2=19, R_512_0_3=37, + R_512_1_0=33, R_512_1_1=27, R_512_1_2=14, R_512_1_3=42, + R_512_2_0=17, R_512_2_1=49, R_512_2_2=36, R_512_2_3=39, + R_512_3_0=44, R_512_3_1= 9, R_512_3_2=54, R_512_3_3=56, + R_512_4_0=39, R_512_4_1=30, R_512_4_2=34, R_512_4_3=24, + R_512_5_0=13, R_512_5_1=50, R_512_5_2=10, R_512_5_3=17, + R_512_6_0=25, R_512_6_1=29, R_512_6_2=39, R_512_6_3=43, + R_512_7_0= 8, R_512_7_1=35, R_512_7_2=56, R_512_7_3=22 + }; + uint64_t X0,X1,X2,X3,X4,X5,X6,X7; + uint64_t w[SKEIN_512_STATE_WORDS]; + uint64_t kw[SKEIN_512_STATE_WORDS+4]; + + ts[0] = ctx->h.T[0]; + ts[1] = ctx->h.T[1]; + + do { + + ts[0] += byteCntAdd; + + ks[0] = ctx->X[0]; + ks[1] = ctx->X[1]; + ks[2] = ctx->X[2]; + ks[3] = ctx->X[3]; + ks[4] = ctx->X[4]; + ks[5] = ctx->X[5]; + ks[6] = ctx->X[6]; + ks[7] = ctx->X[7]; + ks[8] = ks[0] ^ ks[1] ^ ks[2] ^ ks[3] ^ + ks[4] ^ ks[5] ^ ks[6] ^ ks[7] ^ SKEIN_KS_PARITY; + + ts[2] = ts[0] ^ ts[1]; + + memcpy(w, blkPtr, SKEIN_512_STATE_WORDS << 3); + + X0 = w[0] + ks[0]; + X1 = w[1] + ks[1]; + X2 = w[2] + ks[2]; + X3 = w[3] + ks[3]; + X4 = w[4] + ks[4]; + X5 = w[5] + ks[5] + ts[0]; + X6 = w[6] + ks[6] + ts[1]; + X7 = w[7] + ks[7]; + + blkPtr += SKEIN_512_BLOCK_BYTES; + + R512_8_rounds( 0); + R512_8_rounds( 1); + R512_8_rounds( 2); + R512_8_rounds( 3); + R512_8_rounds( 4); + R512_8_rounds( 5); + R512_8_rounds( 6); + R512_8_rounds( 7); + R512_8_rounds( 8); + + ctx->X[0] = X0 ^ w[0]; + ctx->X[1] = X1 ^ w[1]; + ctx->X[2] = X2 ^ w[2]; + ctx->X[3] = X3 ^ w[3]; + ctx->X[4] = X4 ^ w[4]; + ctx->X[5] = X5 ^ w[5]; + ctx->X[6] = X6 ^ w[6]; + ctx->X[7] = X7 ^ w[7]; + + ts[1] &= ~SKEIN_T1_FLAG_FIRST; + } while (--blkCnt); + + ctx->h.T[0] = ts[0]; + ctx->h.T[1] = ts[1]; +} + +__device__ void cn_skein_final(skeinHashState * __restrict__ state, uint8_t * __restrict__ hashVal) +{ + size_t i,n,byteCnt; + uint64_t X[SKEIN_512_STATE_WORDS]; + Skein_512_Ctxt_t *ctx = (Skein_512_Ctxt_t *)&state->u.ctx_512; + //size_t tmp; + //uint8_t *p8; + //uint64_t *p64; + + ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; + + if (ctx->h.bCnt < SKEIN_512_BLOCK_BYTES) { + + memset(&ctx->b[ctx->h.bCnt],0,SKEIN_512_BLOCK_BYTES - ctx->h.bCnt); + //p8 = &ctx->b[ctx->h.bCnt]; + //tmp = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt; + //for( i = 0; i < tmp; i++ ) *(p8+i) = 0; + } + + cn_skein512_processblock(ctx,ctx->b,1,ctx->h.bCnt); + + byteCnt = (ctx->h.hashBitLen + 7) >> 3; + + //uint8_t b[SKEIN_512_BLOCK_BYTES] == 64 + memset(ctx->b,0,sizeof(ctx->b)); + //p64 = (uint64_t *)ctx->b; + //for( i = 0; i < 8; i++ ) *(p64+i) = 0; + + memcpy(X,ctx->X,sizeof(X)); + + for (i=0;i*SKEIN_512_BLOCK_BYTES < byteCnt;i++) { + + ((uint64_t *)ctx->b)[0]= (uint64_t)i; + Skein_Start_New_Type(ctx,OUT_FINAL); + cn_skein512_processblock(ctx,ctx->b,1,sizeof(uint64_t)); + n = byteCnt - i*SKEIN_512_BLOCK_BYTES; + if (n >= SKEIN_512_BLOCK_BYTES) + n = SKEIN_512_BLOCK_BYTES; + memcpy(hashVal+i*SKEIN_512_BLOCK_BYTES,ctx->X,n); + memcpy(ctx->X,X,sizeof(X)); /* restore the counter mode key for next time */ + } +} + +__device__ void cn_skein512_update(Skein_512_Ctxt_t * __restrict__ ctx, const uint8_t * __restrict__ msg, size_t msgByteCnt) +{ + size_t n; + + if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES) { + + if (ctx->h.bCnt) { + + n = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt; + + if (n) { + + memcpy(&ctx->b[ctx->h.bCnt],msg,n); + msgByteCnt -= n; + msg += n; + ctx->h.bCnt += n; + } + + cn_skein512_processblock(ctx,ctx->b,1,SKEIN_512_BLOCK_BYTES); + ctx->h.bCnt = 0; + } + + if (msgByteCnt > SKEIN_512_BLOCK_BYTES) { + + n = (msgByteCnt-1) / SKEIN_512_BLOCK_BYTES; + cn_skein512_processblock(ctx,msg,n,SKEIN_512_BLOCK_BYTES); + msgByteCnt -= n * SKEIN_512_BLOCK_BYTES; + msg += n * SKEIN_512_BLOCK_BYTES; + } + } + + if (msgByteCnt) { + + memcpy(&ctx->b[ctx->h.bCnt],msg,msgByteCnt); + ctx->h.bCnt += msgByteCnt; + } +} + +__device__ void cn_skein_update(skeinHashState * __restrict__ state, const BitSequence * __restrict__ data, DataLength databitlen) +{ + if ((databitlen & 7) == 0) { + + cn_skein512_update(&state->u.ctx_512,data,databitlen >> 3); + } + else { + + size_t bCnt = (databitlen >> 3) + 1; + uint8_t b,mask; + + mask = (uint8_t) (1u << (7 - (databitlen & 7))); + b = (uint8_t) ((data[bCnt-1] & (0-mask)) | mask); + + cn_skein512_update(&state->u.ctx_512,data,bCnt-1); + cn_skein512_update(&state->u.ctx_512,&b , 1 ); + + Skein_Set_Bit_Pad_Flag(state->u.h); + } +} + +__device__ void cn_skein(const BitSequence * __restrict__ data, DataLength len, BitSequence * __restrict__ hashval) +{ + int hashbitlen = 256; + DataLength databitlen = len << 3; + skeinHashState state; + + state.statebits = 64*SKEIN_512_STATE_WORDS; + + cn_skein_init(&state, hashbitlen); + cn_skein_update(&state, data, databitlen); + cn_skein_final(&state, hashval); +} diff --git a/depcomp b/depcomp index bd0ac08..c5f0204 100644 --- a/depcomp +++ b/depcomp @@ -686,3 +686,4 @@ exit 0 # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: + diff --git a/elist.h b/elist.h index 5dcdda5..93c0dca 100644 --- a/elist.h +++ b/elist.h @@ -181,7 +181,7 @@ static __inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) /** * list_for_each - iterate over a list diff --git a/files.txt b/files.txt deleted file mode 100644 index 5391bba..0000000 --- a/files.txt +++ /dev/null @@ -1,30 +0,0 @@ -blake512.cu -blake.c -combine.cu -compat.h -cpu-miner.c -cpuminer-config.h -cuda_blake512.h -cuda_combine.h -cuda_groestl512.h -cuda_hefty1.h -cuda_keccak512.h -cuda_sha256.h -elist.h -groestl512.cu -groestl.c -heavy.c -hefty1.c -hefty1.cu -hefty1.h -keccak512.cu -keccak.c -miner.h -scrypt.c -sha256.cu -sha2.c -sph_blake.h -sph_groestl.h -sph_keccak.h -sph_types.h -util.c diff --git a/miner.h b/miner.h index 60b77ae..7451f77 100755 --- a/miner.h +++ b/miner.h @@ -1,13 +1,12 @@ #ifndef __MINER_H__ #define __MINER_H__ -#ifdef __cplusplus -extern "C" { -#endif - +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else #include "cpuminer-config.h" +#endif -#include #include #include #include @@ -19,7 +18,7 @@ extern "C" { #define strdup(x) _strdup(x) #define strncasecmp(x,y,z) _strnicmp(x,y,z) #define strcasecmp(x,y) _stricmp(x,y) -typedef int ssize_t; +typedef SSIZE_T ssize_t; #endif #ifdef STDC_HEADERS @@ -41,10 +40,7 @@ typedef int ssize_t; # include # define alloca _alloca # elif !defined HAVE_ALLOCA -# ifdef __cplusplus -extern "C" -# endif -void *alloca (size_t); + void *alloca (size_t); # endif #endif @@ -70,6 +66,8 @@ enum { #define likely(expr) (expr) #endif +#define MAX_GPU 16 + #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #endif @@ -194,11 +192,22 @@ void sha256_init_8way(uint32_t *state); void sha256_transform_8way(uint32_t *state, const uint32_t *block, int swap); #endif +typedef enum __algo_t +{ + algo_old, + algo_monero, + algo_graft, + algo_stellite, + algo_intense, + algo_electroneum, + algo_sumokoin +} algo_t; + extern int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, - unsigned long *hashes_done); + unsigned long *hashes_done, uint32_t *results); -extern void cryptonight_hash(void* output, const void* input, size_t len); +extern int cryptonight_hash(void* output, const void* input, size_t len, int variant, algo_t opt_algo); struct thr_info { int id; @@ -211,6 +220,7 @@ struct work_restart { char padding[128 - sizeof(unsigned long)]; }; +extern bool opt_colors; extern bool opt_debug; extern bool opt_protocol; extern int opt_timeout; @@ -227,14 +237,12 @@ extern struct thr_info *thr_info; extern int longpoll_thr_id; extern int stratum_thr_id; extern struct work_restart *work_restart; -extern bool opt_trust_pool; -extern uint16_t opt_vote; -extern bool jsonrpc_2; #define JSON_RPC_LONGPOLL (1 << 0) #define JSON_RPC_QUIET_404 (1 << 1) #define JSON_RPC_IGNOREERR (1 << 2) +void color_init(); extern void applog(int prio, const char *fmt, ...); extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, const char *rpc_req, bool, bool, int *); @@ -244,6 +252,7 @@ extern int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y); extern bool fulltest(const uint32_t *hash, const uint32_t *target); extern void diff_to_target(uint32_t *target, double diff); +void exit_if_cudaerror(int thr_id, const char *file, int line); struct work { uint32_t data[32]; @@ -293,12 +302,12 @@ struct stratum_ctx { pthread_mutex_t work_lock; }; +bool stratum_keepalived(struct stratum_ctx *sctx , const char *rpc2_id); bool stratum_socket_full(struct stratum_ctx *sctx, int timeout); bool stratum_send_line(struct stratum_ctx *sctx, char *s); char *stratum_recv_line(struct stratum_ctx *sctx); bool stratum_connect(struct stratum_ctx *sctx, const char *url); void stratum_disconnect(struct stratum_ctx *sctx); -bool stratum_subscribe(struct stratum_ctx *sctx); bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass); bool stratum_handle_method(struct stratum_ctx *sctx, const char *s); @@ -314,8 +323,4 @@ extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime); extern void tq_freeze(struct thread_q *tq); extern void tq_thaw(struct thread_q *tq); -#ifdef __cplusplus -} -#endif - #endif /* __MINER_H__ */ diff --git a/missing b/missing deleted file mode 100644 index 1c8ff70..0000000 --- a/missing +++ /dev/null @@ -1,367 +0,0 @@ -#! /bin/sh -# Common stub for a few missing GNU programs while installing. - -scriptversion=2006-05-10.23 - -# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006 -# Free Software Foundation, Inc. -# Originally by Fran,cois Pinard , 1996. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program 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 General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. - -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -if test $# -eq 0; then - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 -fi - -run=: -sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' -sed_minuso='s/.* -o \([^ ]*\).*/\1/p' - -# In the cases where this matters, `missing' is being run in the -# srcdir already. -if test -f configure.ac; then - configure_ac=configure.ac -else - configure_ac=configure.in -fi - -msg="missing on your system" - -case $1 in ---run) - # Try to run requested program, and just exit if it succeeds. - run= - shift - "$@" && exit 0 - # Exit code 63 means version mismatch. This often happens - # when the user try to use an ancient version of a tool on - # a file that requires a minimum version. In this case we - # we should proceed has if the program had been absent, or - # if --run hadn't been passed. - if test $? = 63; then - run=: - msg="probably too old" - fi - ;; - - -h|--h|--he|--hel|--help) - echo "\ -$0 [OPTION]... PROGRAM [ARGUMENT]... - -Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an -error status if there is no known handling for PROGRAM. - -Options: - -h, --help display this help and exit - -v, --version output version information and exit - --run try to run the given command, and emulate it if it fails - -Supported PROGRAM values: - aclocal touch file \`aclocal.m4' - autoconf touch file \`configure' - autoheader touch file \`config.h.in' - autom4te touch the output file, or create a stub one - automake touch all \`Makefile.in' files - bison create \`y.tab.[ch]', if possible, from existing .[ch] - flex create \`lex.yy.c', if possible, from existing .c - help2man touch the output file - lex create \`lex.yy.c', if possible, from existing .c - makeinfo touch the output file - tar try tar, gnutar, gtar, then tar without non-portable flags - yacc create \`y.tab.[ch]', if possible, from existing .[ch] - -Send bug reports to ." - exit $? - ;; - - -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing $scriptversion (GNU Automake)" - exit $? - ;; - - -*) - echo 1>&2 "$0: Unknown \`$1' option" - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 - ;; - -esac - -# Now exit if we have it, but it failed. Also exit now if we -# don't have it and --version was passed (most likely to detect -# the program). -case $1 in - lex|yacc) - # Not GNU programs, they don't have --version. - ;; - - tar) - if test -n "$run"; then - echo 1>&2 "ERROR: \`tar' requires --run" - exit 1 - elif test "x$2" = "x--version" || test "x$2" = "x--help"; then - exit 1 - fi - ;; - - *) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - elif test "x$2" = "x--version" || test "x$2" = "x--help"; then - # Could not run --version or --help. This is probably someone - # running `$TOOL --version' or `$TOOL --help' to check whether - # $TOOL exists and not knowing $TOOL uses missing. - exit 1 - fi - ;; -esac - -# If it does not exist, or fails to run (possibly an outdated version), -# try to emulate it. -case $1 in - aclocal*) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`acinclude.m4' or \`${configure_ac}'. You might want - to install the \`Automake' and \`Perl' packages. Grab them from - any GNU archive site." - touch aclocal.m4 - ;; - - autoconf) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`${configure_ac}'. You might want to install the - \`Autoconf' and \`GNU m4' packages. Grab them from any GNU - archive site." - touch configure - ;; - - autoheader) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`acconfig.h' or \`${configure_ac}'. You might want - to install the \`Autoconf' and \`GNU m4' packages. Grab them - from any GNU archive site." - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` - test -z "$files" && files="config.h" - touch_files= - for f in $files; do - case $f in - *:*) touch_files="$touch_files "`echo "$f" | - sed -e 's/^[^:]*://' -e 's/:.*//'`;; - *) touch_files="$touch_files $f.in";; - esac - done - touch $touch_files - ;; - - automake*) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. - You might want to install the \`Automake' and \`Perl' packages. - Grab them from any GNU archive site." - find . -type f -name Makefile.am -print | - sed 's/\.am$/.in/' | - while read f; do touch "$f"; done - ;; - - autom4te) - echo 1>&2 "\ -WARNING: \`$1' is needed, but is $msg. - You might have modified some files without having the - proper tools for further handling them. - You can get \`$1' as part of \`Autoconf' from any GNU - archive site." - - file=`echo "$*" | sed -n "$sed_output"` - test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` - if test -f "$file"; then - touch $file - else - test -z "$file" || exec >$file - echo "#! /bin/sh" - echo "# Created by GNU Automake missing as a replacement of" - echo "# $ $@" - echo "exit 0" - chmod +x $file - exit 1 - fi - ;; - - bison|yacc) - echo 1>&2 "\ -WARNING: \`$1' $msg. You should only need it if - you modified a \`.y' file. You may need the \`Bison' package - in order for those modifications to take effect. You can get - \`Bison' from any GNU archive site." - rm -f y.tab.c y.tab.h - if test $# -ne 1; then - eval LASTARG="\${$#}" - case $LASTARG in - *.y) - SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` - if test -f "$SRCFILE"; then - cp "$SRCFILE" y.tab.c - fi - SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` - if test -f "$SRCFILE"; then - cp "$SRCFILE" y.tab.h - fi - ;; - esac - fi - if test ! -f y.tab.h; then - echo >y.tab.h - fi - if test ! -f y.tab.c; then - echo 'main() { return 0; }' >y.tab.c - fi - ;; - - lex|flex) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a \`.l' file. You may need the \`Flex' package - in order for those modifications to take effect. You can get - \`Flex' from any GNU archive site." - rm -f lex.yy.c - if test $# -ne 1; then - eval LASTARG="\${$#}" - case $LASTARG in - *.l) - SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` - if test -f "$SRCFILE"; then - cp "$SRCFILE" lex.yy.c - fi - ;; - esac - fi - if test ! -f lex.yy.c; then - echo 'main() { return 0; }' >lex.yy.c - fi - ;; - - help2man) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a dependency of a manual page. You may need the - \`Help2man' package in order for those modifications to take - effect. You can get \`Help2man' from any GNU archive site." - - file=`echo "$*" | sed -n "$sed_output"` - test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` - if test -f "$file"; then - touch $file - else - test -z "$file" || exec >$file - echo ".ab help2man is required to generate this page" - exit 1 - fi - ;; - - makeinfo) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a \`.texi' or \`.texinfo' file, or any other file - indirectly affecting the aspect of the manual. The spurious - call might also be the consequence of using a buggy \`make' (AIX, - DU, IRIX). You might want to install the \`Texinfo' package or - the \`GNU make' package. Grab either from any GNU archive site." - # The file to touch is that specified with -o ... - file=`echo "$*" | sed -n "$sed_output"` - test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` - if test -z "$file"; then - # ... or it is the one specified with @setfilename ... - infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` - file=`sed -n ' - /^@setfilename/{ - s/.* \([^ ]*\) *$/\1/ - p - q - }' $infile` - # ... or it is derived from the source name (dir/f.texi becomes f.info) - test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info - fi - # If the file does not exist, the user really needs makeinfo; - # let's fail without touching anything. - test -f $file || exit 1 - touch $file - ;; - - tar) - shift - - # We have already tried tar in the generic part. - # Look for gnutar/gtar before invocation to avoid ugly error - # messages. - if (gnutar --version > /dev/null 2>&1); then - gnutar "$@" && exit 0 - fi - if (gtar --version > /dev/null 2>&1); then - gtar "$@" && exit 0 - fi - firstarg="$1" - if shift; then - case $firstarg in - *o*) - firstarg=`echo "$firstarg" | sed s/o//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - case $firstarg in - *h*) - firstarg=`echo "$firstarg" | sed s/h//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - fi - - echo 1>&2 "\ -WARNING: I can't seem to be able to run \`tar' with the given arguments. - You may want to install GNU tar or Free paxutils, or check the - command line arguments." - exit 1 - ;; - - *) - echo 1>&2 "\ -WARNING: \`$1' is needed, and is $msg. - You might have modified some files without having the - proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequisites for installing - this package. You may also peek at any GNU archive site, in case - some other package would contain this missing \`$1' program." - exit 1 - ;; -esac - -exit 0 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" -# End: diff --git a/sha2.c b/sha2.cpp similarity index 99% rename from sha2.c rename to sha2.cpp index 8c5df1e..f384593 100644 --- a/sha2.c +++ b/sha2.cpp @@ -8,7 +8,11 @@ * any later version. See COPYING for more details. */ +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else #include "cpuminer-config.h" +#endif #include "miner.h" #include diff --git a/uint256.h b/uint256.h deleted file mode 100644 index 2a252c9..0000000 --- a/uint256.h +++ /dev/null @@ -1,784 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2012 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_UINT256_H -#define BITCOIN_UINT256_H - -#include -#include -#include -#include -#include -#include - -typedef long long int64; -typedef unsigned long long uint64; - - -inline int Testuint256AdHoc(std::vector vArg); - - - -/** Base class without constructors for uint256 and uint160. - * This makes the compiler let you use it in a union. - */ -template -class base_uint -{ -protected: - enum { WIDTH=BITS/32 }; - uint32_t pn[WIDTH]; -public: - - bool operator!() const - { - for (int i = 0; i < WIDTH; i++) - if (pn[i] != 0) - return false; - return true; - } - - const base_uint operator~() const - { - base_uint ret; - for (int i = 0; i < WIDTH; i++) - ret.pn[i] = ~pn[i]; - return ret; - } - - const base_uint operator-() const - { - base_uint ret; - for (int i = 0; i < WIDTH; i++) - ret.pn[i] = ~pn[i]; - ret++; - return ret; - } - - double getdouble() const - { - double ret = 0.0; - double fact = 1.0; - for (int i = 0; i < WIDTH; i++) { - ret += fact * pn[i]; - fact *= 4294967296.0; - } - return ret; - } - - base_uint& operator=(uint64 b) - { - pn[0] = (unsigned int)b; - pn[1] = (unsigned int)(b >> 32); - for (int i = 2; i < WIDTH; i++) - pn[i] = 0; - return *this; - } - - base_uint& operator^=(const base_uint& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] ^= b.pn[i]; - return *this; - } - - base_uint& operator&=(const base_uint& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] &= b.pn[i]; - return *this; - } - - base_uint& operator|=(const base_uint& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] |= b.pn[i]; - return *this; - } - - base_uint& operator^=(uint64 b) - { - pn[0] ^= (unsigned int)b; - pn[1] ^= (unsigned int)(b >> 32); - return *this; - } - - base_uint& operator|=(uint64 b) - { - pn[0] |= (unsigned int)b; - pn[1] |= (unsigned int)(b >> 32); - return *this; - } - - base_uint& operator<<=(unsigned int shift) - { - base_uint a(*this); - for (int i = 0; i < WIDTH; i++) - pn[i] = 0; - int k = shift / 32; - shift = shift % 32; - for (int i = 0; i < WIDTH; i++) - { - if (i+k+1 < WIDTH && shift != 0) - pn[i+k+1] |= (a.pn[i] >> (32-shift)); - if (i+k < WIDTH) - pn[i+k] |= (a.pn[i] << shift); - } - return *this; - } - - base_uint& operator>>=(unsigned int shift) - { - base_uint a(*this); - for (int i = 0; i < WIDTH; i++) - pn[i] = 0; - int k = shift / 32; - shift = shift % 32; - for (int i = 0; i < WIDTH; i++) - { - if (i-k-1 >= 0 && shift != 0) - pn[i-k-1] |= (a.pn[i] << (32-shift)); - if (i-k >= 0) - pn[i-k] |= (a.pn[i] >> shift); - } - return *this; - } - - base_uint& operator+=(const base_uint& b) - { - uint64 carry = 0; - for (int i = 0; i < WIDTH; i++) - { - uint64 n = carry + pn[i] + b.pn[i]; - pn[i] = n & 0xffffffff; - carry = n >> 32; - } - return *this; - } - - base_uint& operator-=(const base_uint& b) - { - *this += -b; - return *this; - } - - base_uint& operator+=(uint64 b64) - { - base_uint b; - b = b64; - *this += b; - return *this; - } - - base_uint& operator-=(uint64 b64) - { - base_uint b; - b = b64; - *this += -b; - return *this; - } - - - base_uint& operator++() - { - // prefix operator - int i = 0; - while (++pn[i] == 0 && i < WIDTH-1) - i++; - return *this; - } - - const base_uint operator++(int) - { - // postfix operator - const base_uint ret = *this; - ++(*this); - return ret; - } - - base_uint& operator--() - { - // prefix operator - int i = 0; - while (--pn[i] == -1 && i < WIDTH-1) - i++; - return *this; - } - - const base_uint operator--(int) - { - // postfix operator - const base_uint ret = *this; - --(*this); - return ret; - } - - - friend inline bool operator<(const base_uint& a, const base_uint& b) - { - for (int i = base_uint::WIDTH-1; i >= 0; i--) - { - if (a.pn[i] < b.pn[i]) - return true; - else if (a.pn[i] > b.pn[i]) - return false; - } - return false; - } - - friend inline bool operator<=(const base_uint& a, const base_uint& b) - { - for (int i = base_uint::WIDTH-1; i >= 0; i--) - { - if (a.pn[i] < b.pn[i]) - return true; - else if (a.pn[i] > b.pn[i]) - return false; - } - return true; - } - - friend inline bool operator>(const base_uint& a, const base_uint& b) - { - for (int i = base_uint::WIDTH-1; i >= 0; i--) - { - if (a.pn[i] > b.pn[i]) - return true; - else if (a.pn[i] < b.pn[i]) - return false; - } - return false; - } - - friend inline bool operator>=(const base_uint& a, const base_uint& b) - { - for (int i = base_uint::WIDTH-1; i >= 0; i--) - { - if (a.pn[i] > b.pn[i]) - return true; - else if (a.pn[i] < b.pn[i]) - return false; - } - return true; - } - - friend inline bool operator==(const base_uint& a, const base_uint& b) - { - for (int i = 0; i < base_uint::WIDTH; i++) - if (a.pn[i] != b.pn[i]) - return false; - return true; - } - - friend inline bool operator==(const base_uint& a, uint64 b) - { - if (a.pn[0] != (unsigned int)b) - return false; - if (a.pn[1] != (unsigned int)(b >> 32)) - return false; - for (int i = 2; i < base_uint::WIDTH; i++) - if (a.pn[i] != 0) - return false; - return true; - } - - friend inline bool operator!=(const base_uint& a, const base_uint& b) - { - return (!(a == b)); - } - - friend inline bool operator!=(const base_uint& a, uint64 b) - { - return (!(a == b)); - } - - - - std::string GetHex() const - { - char psz[sizeof(pn)*2 + 1]; - for (unsigned int i = 0; i < sizeof(pn); i++) - sprintf(psz + i*2, "%02x", ((unsigned char*)pn)[sizeof(pn) - i - 1]); - return std::string(psz, psz + sizeof(pn)*2); - } - - void SetHex(const char* psz) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = 0; - - // skip leading spaces - while (isspace(*psz)) - psz++; - - // skip 0x - if (psz[0] == '0' && tolower(psz[1]) == 'x') - psz += 2; - - // hex string to uint - static const unsigned char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 }; - const char* pbegin = psz; - while (phexdigit[(unsigned char)*psz] || *psz == '0') - psz++; - psz--; - unsigned char* p1 = (unsigned char*)pn; - unsigned char* pend = p1 + WIDTH * 4; - while (psz >= pbegin && p1 < pend) - { - *p1 = phexdigit[(unsigned char)*psz--]; - if (psz >= pbegin) - { - *p1 |= (phexdigit[(unsigned char)*psz--] << 4); - p1++; - } - } - } - - void SetHex(const std::string& str) - { - SetHex(str.c_str()); - } - - std::string ToString() const - { - return (GetHex()); - } - - unsigned char* begin() - { - return (unsigned char*)&pn[0]; - } - - unsigned char* end() - { - return (unsigned char*)&pn[WIDTH]; - } - - const unsigned char* begin() const - { - return (unsigned char*)&pn[0]; - } - - const unsigned char* end() const - { - return (unsigned char*)&pn[WIDTH]; - } - - unsigned int size() const - { - return sizeof(pn); - } - - uint64 Get64(int n=0) const - { - return pn[2*n] | (uint64)pn[2*n+1] << 32; - } - -// unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const - unsigned int GetSerializeSize(int nType, int nVersion) const - { - return sizeof(pn); - } - - template -// void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const - void Serialize(Stream& s, int nType, int nVersion) const - { - s.write((char*)pn, sizeof(pn)); - } - - template -// void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) - void Unserialize(Stream& s, int nType, int nVersion) - { - s.read((char*)pn, sizeof(pn)); - } - - - friend class uint160; - friend class uint256; - friend inline int Testuint256AdHoc(std::vector vArg); -}; - -typedef base_uint<160> base_uint160; -typedef base_uint<256> base_uint256; - - - -// -// uint160 and uint256 could be implemented as templates, but to keep -// compile errors and debugging cleaner, they're copy and pasted. -// - - - -////////////////////////////////////////////////////////////////////////////// -// -// uint160 -// - -/** 160-bit unsigned integer */ -class uint160 : public base_uint160 -{ -public: - typedef base_uint160 basetype; - - uint160() - { - for (int i = 0; i < WIDTH; i++) - pn[i] = 0; - } - - uint160(const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - } - - uint160& operator=(const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - return *this; - } - - uint160(uint64 b) - { - pn[0] = (unsigned int)b; - pn[1] = (unsigned int)(b >> 32); - for (int i = 2; i < WIDTH; i++) - pn[i] = 0; - } - - uint160& operator=(uint64 b) - { - pn[0] = (unsigned int)b; - pn[1] = (unsigned int)(b >> 32); - for (int i = 2; i < WIDTH; i++) - pn[i] = 0; - return *this; - } - - explicit uint160(const std::string& str) - { - SetHex(str); - } - - explicit uint160(const std::vector& vch) - { - if (vch.size() == sizeof(pn)) - memcpy(pn, &vch[0], sizeof(pn)); - else - *this = 0; - } -}; - -inline bool operator==(const uint160& a, uint64 b) { return (base_uint160)a == b; } -inline bool operator!=(const uint160& a, uint64 b) { return (base_uint160)a != b; } -inline const uint160 operator<<(const base_uint160& a, unsigned int shift) { return uint160(a) <<= shift; } -inline const uint160 operator>>(const base_uint160& a, unsigned int shift) { return uint160(a) >>= shift; } -inline const uint160 operator<<(const uint160& a, unsigned int shift) { return uint160(a) <<= shift; } -inline const uint160 operator>>(const uint160& a, unsigned int shift) { return uint160(a) >>= shift; } - -inline const uint160 operator^(const base_uint160& a, const base_uint160& b) { return uint160(a) ^= b; } -inline const uint160 operator&(const base_uint160& a, const base_uint160& b) { return uint160(a) &= b; } -inline const uint160 operator|(const base_uint160& a, const base_uint160& b) { return uint160(a) |= b; } -inline const uint160 operator+(const base_uint160& a, const base_uint160& b) { return uint160(a) += b; } -inline const uint160 operator-(const base_uint160& a, const base_uint160& b) { return uint160(a) -= b; } - -inline bool operator<(const base_uint160& a, const uint160& b) { return (base_uint160)a < (base_uint160)b; } -inline bool operator<=(const base_uint160& a, const uint160& b) { return (base_uint160)a <= (base_uint160)b; } -inline bool operator>(const base_uint160& a, const uint160& b) { return (base_uint160)a > (base_uint160)b; } -inline bool operator>=(const base_uint160& a, const uint160& b) { return (base_uint160)a >= (base_uint160)b; } -inline bool operator==(const base_uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const base_uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const base_uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const base_uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const base_uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline const uint160 operator+(const base_uint160& a, const uint160& b) { return (base_uint160)a + (base_uint160)b; } -inline const uint160 operator-(const base_uint160& a, const uint160& b) { return (base_uint160)a - (base_uint160)b; } - -inline bool operator<(const uint160& a, const base_uint160& b) { return (base_uint160)a < (base_uint160)b; } -inline bool operator<=(const uint160& a, const base_uint160& b) { return (base_uint160)a <= (base_uint160)b; } -inline bool operator>(const uint160& a, const base_uint160& b) { return (base_uint160)a > (base_uint160)b; } -inline bool operator>=(const uint160& a, const base_uint160& b) { return (base_uint160)a >= (base_uint160)b; } -inline bool operator==(const uint160& a, const base_uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const uint160& a, const base_uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const uint160& a, const base_uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const uint160& a, const base_uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const uint160& a, const base_uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline const uint160 operator+(const uint160& a, const base_uint160& b) { return (base_uint160)a + (base_uint160)b; } -inline const uint160 operator-(const uint160& a, const base_uint160& b) { return (base_uint160)a - (base_uint160)b; } - -inline bool operator<(const uint160& a, const uint160& b) { return (base_uint160)a < (base_uint160)b; } -inline bool operator<=(const uint160& a, const uint160& b) { return (base_uint160)a <= (base_uint160)b; } -inline bool operator>(const uint160& a, const uint160& b) { return (base_uint160)a > (base_uint160)b; } -inline bool operator>=(const uint160& a, const uint160& b) { return (base_uint160)a >= (base_uint160)b; } -inline bool operator==(const uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline const uint160 operator+(const uint160& a, const uint160& b) { return (base_uint160)a + (base_uint160)b; } -inline const uint160 operator-(const uint160& a, const uint160& b) { return (base_uint160)a - (base_uint160)b; } - - - - - - -////////////////////////////////////////////////////////////////////////////// -// -// uint256 -// - -/** 256-bit unsigned integer */ -class uint256 : public base_uint256 -{ -public: - typedef base_uint256 basetype; - - uint256() - { - for (int i = 0; i < WIDTH; i++) - pn[i] = 0; - } - - uint256(const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - } - - uint256& operator=(const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - return *this; - } - - uint256(uint64 b) - { - pn[0] = (unsigned int)b; - pn[1] = (unsigned int)(b >> 32); - for (int i = 2; i < WIDTH; i++) - pn[i] = 0; - } - - uint256& operator=(uint64 b) - { - pn[0] = (unsigned int)b; - pn[1] = (unsigned int)(b >> 32); - for (int i = 2; i < WIDTH; i++) - pn[i] = 0; - return *this; - } - - explicit uint256(const std::string& str) - { - SetHex(str); - } - - explicit uint256(const std::vector& vch) - { - if (vch.size() == sizeof(pn)) - memcpy(pn, &vch[0], sizeof(pn)); - else - *this = 0; - } -}; - -inline bool operator==(const uint256& a, uint64 b) { return (base_uint256)a == b; } -inline bool operator!=(const uint256& a, uint64 b) { return (base_uint256)a != b; } -inline const uint256 operator<<(const base_uint256& a, unsigned int shift) { return uint256(a) <<= shift; } -inline const uint256 operator>>(const base_uint256& a, unsigned int shift) { return uint256(a) >>= shift; } -inline const uint256 operator<<(const uint256& a, unsigned int shift) { return uint256(a) <<= shift; } -inline const uint256 operator>>(const uint256& a, unsigned int shift) { return uint256(a) >>= shift; } - -inline const uint256 operator^(const base_uint256& a, const base_uint256& b) { return uint256(a) ^= b; } -inline const uint256 operator&(const base_uint256& a, const base_uint256& b) { return uint256(a) &= b; } -inline const uint256 operator|(const base_uint256& a, const base_uint256& b) { return uint256(a) |= b; } -inline const uint256 operator+(const base_uint256& a, const base_uint256& b) { return uint256(a) += b; } -inline const uint256 operator-(const base_uint256& a, const base_uint256& b) { return uint256(a) -= b; } - -inline bool operator<(const base_uint256& a, const uint256& b) { return (base_uint256)a < (base_uint256)b; } -inline bool operator<=(const base_uint256& a, const uint256& b) { return (base_uint256)a <= (base_uint256)b; } -inline bool operator>(const base_uint256& a, const uint256& b) { return (base_uint256)a > (base_uint256)b; } -inline bool operator>=(const base_uint256& a, const uint256& b) { return (base_uint256)a >= (base_uint256)b; } -inline bool operator==(const base_uint256& a, const uint256& b) { return (base_uint256)a == (base_uint256)b; } -inline bool operator!=(const base_uint256& a, const uint256& b) { return (base_uint256)a != (base_uint256)b; } -inline const uint256 operator^(const base_uint256& a, const uint256& b) { return (base_uint256)a ^ (base_uint256)b; } -inline const uint256 operator&(const base_uint256& a, const uint256& b) { return (base_uint256)a & (base_uint256)b; } -inline const uint256 operator|(const base_uint256& a, const uint256& b) { return (base_uint256)a | (base_uint256)b; } -inline const uint256 operator+(const base_uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; } -inline const uint256 operator-(const base_uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; } - -inline bool operator<(const uint256& a, const base_uint256& b) { return (base_uint256)a < (base_uint256)b; } -inline bool operator<=(const uint256& a, const base_uint256& b) { return (base_uint256)a <= (base_uint256)b; } -inline bool operator>(const uint256& a, const base_uint256& b) { return (base_uint256)a > (base_uint256)b; } -inline bool operator>=(const uint256& a, const base_uint256& b) { return (base_uint256)a >= (base_uint256)b; } -inline bool operator==(const uint256& a, const base_uint256& b) { return (base_uint256)a == (base_uint256)b; } -inline bool operator!=(const uint256& a, const base_uint256& b) { return (base_uint256)a != (base_uint256)b; } -inline const uint256 operator^(const uint256& a, const base_uint256& b) { return (base_uint256)a ^ (base_uint256)b; } -inline const uint256 operator&(const uint256& a, const base_uint256& b) { return (base_uint256)a & (base_uint256)b; } -inline const uint256 operator|(const uint256& a, const base_uint256& b) { return (base_uint256)a | (base_uint256)b; } -inline const uint256 operator+(const uint256& a, const base_uint256& b) { return (base_uint256)a + (base_uint256)b; } -inline const uint256 operator-(const uint256& a, const base_uint256& b) { return (base_uint256)a - (base_uint256)b; } - -inline bool operator<(const uint256& a, const uint256& b) { return (base_uint256)a < (base_uint256)b; } -inline bool operator<=(const uint256& a, const uint256& b) { return (base_uint256)a <= (base_uint256)b; } -inline bool operator>(const uint256& a, const uint256& b) { return (base_uint256)a > (base_uint256)b; } -inline bool operator>=(const uint256& a, const uint256& b) { return (base_uint256)a >= (base_uint256)b; } -inline bool operator==(const uint256& a, const uint256& b) { return (base_uint256)a == (base_uint256)b; } -inline bool operator!=(const uint256& a, const uint256& b) { return (base_uint256)a != (base_uint256)b; } -inline const uint256 operator^(const uint256& a, const uint256& b) { return (base_uint256)a ^ (base_uint256)b; } -inline const uint256 operator&(const uint256& a, const uint256& b) { return (base_uint256)a & (base_uint256)b; } -inline const uint256 operator|(const uint256& a, const uint256& b) { return (base_uint256)a | (base_uint256)b; } -inline const uint256 operator+(const uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; } -inline const uint256 operator-(const uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; } - - - - - - - - - - -#ifdef TEST_UINT256 - -inline int Testuint256AdHoc(std::vector vArg) -{ - uint256 g(0); - - - printf("%s\n", g.ToString().c_str()); - g--; printf("g--\n"); - printf("%s\n", g.ToString().c_str()); - g--; printf("g--\n"); - printf("%s\n", g.ToString().c_str()); - g++; printf("g++\n"); - printf("%s\n", g.ToString().c_str()); - g++; printf("g++\n"); - printf("%s\n", g.ToString().c_str()); - g++; printf("g++\n"); - printf("%s\n", g.ToString().c_str()); - g++; printf("g++\n"); - printf("%s\n", g.ToString().c_str()); - - - - uint256 a(7); - printf("a=7\n"); - printf("%s\n", a.ToString().c_str()); - - uint256 b; - printf("b undefined\n"); - printf("%s\n", b.ToString().c_str()); - int c = 3; - - a = c; - a.pn[3] = 15; - printf("%s\n", a.ToString().c_str()); - uint256 k(c); - - a = 5; - a.pn[3] = 15; - printf("%s\n", a.ToString().c_str()); - b = 1; - b <<= 52; - - a |= b; - - a ^= 0x500; - - printf("a %s\n", a.ToString().c_str()); - - a = a | b | (uint256)0x1000; - - - printf("a %s\n", a.ToString().c_str()); - printf("b %s\n", b.ToString().c_str()); - - a = 0xfffffffe; - a.pn[4] = 9; - - printf("%s\n", a.ToString().c_str()); - a++; - printf("%s\n", a.ToString().c_str()); - a++; - printf("%s\n", a.ToString().c_str()); - a++; - printf("%s\n", a.ToString().c_str()); - a++; - printf("%s\n", a.ToString().c_str()); - - a--; - printf("%s\n", a.ToString().c_str()); - a--; - printf("%s\n", a.ToString().c_str()); - a--; - printf("%s\n", a.ToString().c_str()); - uint256 d = a--; - printf("%s\n", d.ToString().c_str()); - printf("%s\n", a.ToString().c_str()); - a--; - printf("%s\n", a.ToString().c_str()); - a--; - printf("%s\n", a.ToString().c_str()); - - d = a; - - printf("%s\n", d.ToString().c_str()); - for (int i = uint256::WIDTH-1; i >= 0; i--) printf("%08x", d.pn[i]); printf("\n"); - - uint256 neg = d; - neg = ~neg; - printf("%s\n", neg.ToString().c_str()); - - - uint256 e = uint256("0xABCDEF123abcdef12345678909832180000011111111"); - printf("\n"); - printf("%s\n", e.ToString().c_str()); - - - printf("\n"); - uint256 x1 = uint256("0xABCDEF123abcdef12345678909832180000011111111"); - uint256 x2; - printf("%s\n", x1.ToString().c_str()); - for (int i = 0; i < 270; i += 4) - { - x2 = x1 << i; - printf("%s\n", x2.ToString().c_str()); - } - - printf("\n"); - printf("%s\n", x1.ToString().c_str()); - for (int i = 0; i < 270; i += 4) - { - x2 = x1; - x2 >>= i; - printf("%s\n", x2.ToString().c_str()); - } - - - for (int i = 0; i < 100; i++) - { - uint256 k = (~uint256(0) >> i); - printf("%s\n", k.ToString().c_str()); - } - - for (int i = 0; i < 100; i++) - { - uint256 k = (~uint256(0) << i); - printf("%s\n", k.ToString().c_str()); - } - - return (0); -} - -#endif - -#endif diff --git a/util.c b/util.cpp old mode 100755 new mode 100644 similarity index 67% rename from util.c rename to util.cpp index 4ebcaba..faba1dd --- a/util.c +++ b/util.cpp @@ -1,22 +1,24 @@ /* - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. See COPYING for more details. - */ - -#define _GNU_SOURCE +* Copyright 2010 Jeff Garzik +* Copyright 2012-2014 pooler +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. See COPYING for more details. +*/ + +#ifdef WIN32 +#include "cpuminer-config-win.h" +#else #include "cpuminer-config.h" +#endif #include #include #include #include #include -#include #include #include #include @@ -25,6 +27,7 @@ #if defined(WIN32) #include #include +#include #else #include #include @@ -35,29 +38,42 @@ #include "miner.h" #include "elist.h" -struct data_buffer { +char* CL_N = ""; +char* CL_RED = ""; +char* CL_GRN = ""; +char* CL_YLW = ""; +char* CL_BLU = ""; +char* CL_MAG = ""; +char* CL_CYN = ""; + +struct data_buffer +{ void *buf; size_t len; }; -struct upload_buffer { +struct upload_buffer +{ const void *buf; size_t len; size_t pos; }; -struct header_info { +struct header_info +{ char *lp_path; char *reason; char *stratum_url; }; -struct tq_ent { +struct tq_ent +{ void *data; struct list_head q_node; }; -struct thread_q { +struct thread_q +{ struct list_head q; bool frozen; @@ -66,6 +82,20 @@ struct thread_q { pthread_cond_t cond; }; +void color_init() +{ + if(opt_colors) + { + CL_N = "\033[0m"; + CL_RED = "\033[31m"; + CL_GRN = "\033[32m"; + CL_YLW = "\033[33m"; + CL_BLU = "\033[34m"; + CL_MAG = "\033[35m"; + CL_CYN = "\033[36m"; + } +} + void applog(int prio, const char *fmt, ...) { va_list ap; @@ -73,24 +103,30 @@ void applog(int prio, const char *fmt, ...) va_start(ap, fmt); #ifdef HAVE_SYSLOG_H - if (use_syslog) { + if(use_syslog) + { va_list ap2; char *buf; int len; - + va_copy(ap2, ap); len = vsnprintf(NULL, 0, fmt, ap2) + 1; va_end(ap2); - buf = alloca(len); - if (vsnprintf(buf, len, fmt, ap) >= 0) + buf = (char *)alloca(len); + if(vsnprintf(buf, len, fmt, ap) >= 0) syslog(prio, "%s", buf); } #else - if (0) {} + if(0) + { + } #endif - else { + else + { + const char* color = ""; + char *reset; char *f; - int len; + size_t len; time_t now; struct tm tm, *tm_p; @@ -101,19 +137,32 @@ void applog(int prio, const char *fmt, ...) memcpy(&tm, tm_p, sizeof(tm)); pthread_mutex_unlock(&applog_lock); - len = (int)(40 + strlen(fmt) + 2); + switch(prio) + { + case LOG_ERR: color = CL_RED; break; + case LOG_WARNING: color = CL_YLW; break; + case LOG_NOTICE: color = CL_MAG; break; + case LOG_INFO: color = ""; break; + case LOG_DEBUG: color = CL_CYN; break; + } + if(strlen(color) == 0) + reset = ""; + else + reset = CL_N; + + len = strlen(fmt) + 42; f = (char*)alloca(len); - sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s\n", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - tm.tm_hour, - tm.tm_min, - tm.tm_sec, - fmt); + sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + tm.tm_hour, + tm.tm_min, + tm.tm_sec, + color, fmt, reset); pthread_mutex_lock(&applog_lock); - vfprintf(stderr, f, ap); /* atomic write to stderr */ - fflush(stderr); + vfprintf(stdout, f, ap); /* atomic write to stderr */ + fflush(stdout); pthread_mutex_unlock(&applog_lock); } va_end(ap); @@ -121,7 +170,7 @@ void applog(int prio, const char *fmt, ...) static void databuf_free(struct data_buffer *db) { - if (!db) + if(!db) return; free(db->buf); @@ -130,7 +179,7 @@ static void databuf_free(struct data_buffer *db) } static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb, - void *user_data) + void *user_data) { struct data_buffer *db = (struct data_buffer *)user_data; size_t len = size * nmemb; @@ -142,7 +191,7 @@ static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb, newlen = oldlen + len; newmem = realloc(db->buf, newlen + 1); - if (!newmem) + if(!newmem) return 0; db->buf = newmem; @@ -154,15 +203,16 @@ static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb, } static size_t upload_data_cb(void *ptr, size_t size, size_t nmemb, - void *user_data) + void *user_data) { struct upload_buffer *ub = (struct upload_buffer *)user_data; unsigned int len = (unsigned int)(size * nmemb); - if (len > ub->len - ub->pos) + if(len > ub->len - ub->pos) len = (unsigned int)(ub->len - ub->pos); - if (len) { + if(len) + { memcpy(ptr, (char*)ub->buf + ub->pos, len); ub->pos += len; } @@ -174,19 +224,20 @@ static size_t upload_data_cb(void *ptr, size_t size, size_t nmemb, static int seek_data_cb(void *user_data, curl_off_t offset, int origin) { struct upload_buffer *ub = (struct upload_buffer *)user_data; - - switch (origin) { - case SEEK_SET: - ub->pos = (size_t)offset; - break; - case SEEK_CUR: - ub->pos += (size_t)offset; - break; - case SEEK_END: - ub->pos = ub->len + (size_t)offset; - break; - default: - return 1; /* CURL_SEEKFUNC_FAIL */ + + switch(origin) + { + case SEEK_SET: + ub->pos = (size_t)offset; + break; + case SEEK_CUR: + ub->pos += (size_t)offset; + break; + case SEEK_END: + ub->pos = ub->len + (size_t)offset; + break; + default: + return 1; /* CURL_SEEKFUNC_FAIL */ } return 0; /* CURL_SEEKFUNC_OK */ @@ -197,49 +248,54 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data) { struct header_info *hi = (struct header_info *)user_data; size_t remlen, slen, ptrlen = size * nmemb; - char *rem, *val = NULL, *key = NULL; - void *tmp; + char *rem = NULL, *val = NULL, *key = NULL; + void *tmp = NULL; val = (char*)calloc(1, ptrlen); key = (char*)calloc(1, ptrlen); - if (!key || !val) + if(!key || !val) goto out; tmp = memchr(ptr, ':', ptrlen); - if (!tmp || (tmp == ptr)) /* skip empty keys / blanks */ + if(!tmp || (tmp == ptr)) /* skip empty keys / blanks */ goto out; slen = (size_t)((char*)tmp - (char*)ptr); - if ((slen + 1) == ptrlen) /* skip key w/ no value */ + if((slen + 1) == ptrlen) /* skip key w/ no value */ goto out; memcpy(key, ptr, slen); /* store & nul term key */ key[slen] = 0; rem = (char*)ptr + slen + 1; /* trim value's leading whitespace */ remlen = ptrlen - slen - 1; - while ((remlen > 0) && (isspace(*rem))) { + while((remlen > 0) && (isspace(*rem))) + { remlen--; rem++; } memcpy(val, rem, remlen); /* store value, trim trailing ws */ val[remlen] = 0; - while ((*val) && (isspace(val[strlen(val) - 1]))) { + while((*val) && (isspace(val[strlen(val) - 1]))) + { val[strlen(val) - 1] = 0; } - if (!*val) /* skip blank value */ + if(!*val) /* skip blank value */ goto out; - if (!strcasecmp("X-Long-Polling", key)) { + if(!strcasecmp("X-Long-Polling", key)) + { hi->lp_path = val; /* steal memory reference */ val = NULL; } - if (!strcasecmp("X-Reject-Reason", key)) { + if(!strcasecmp("X-Reject-Reason", key)) + { hi->reason = val; /* steal memory reference */ val = NULL; } - if (!strcasecmp("X-Stratum", key)) { + if(!strcasecmp("X-Stratum", key)) + { hi->stratum_url = val; /* steal memory reference */ val = NULL; } @@ -252,7 +308,7 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data) #if LIBCURL_VERSION_NUM >= 0x070f06 static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd, - curlsocktype purpose) + curlsocktype purpose) { int keepalive = 1; int tcp_keepcnt = 3; @@ -263,22 +319,22 @@ static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd, #endif #ifndef WIN32 - if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive, + if(unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)))) return 1; #ifdef __linux - if (unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPCNT, + if(unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &tcp_keepcnt, sizeof(tcp_keepcnt)))) return 1; - if (unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, + if(unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &tcp_keepidle, sizeof(tcp_keepidle)))) return 1; - if (unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, + if(unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &tcp_keepintvl, sizeof(tcp_keepintvl)))) return 1; #endif /* __linux */ #ifdef __APPLE_CC__ - if (unlikely(setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, + if(unlikely(setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &tcp_keepintvl, sizeof(tcp_keepintvl)))) return 1; #endif /* __APPLE_CC__ */ @@ -286,8 +342,8 @@ static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd, struct tcp_keepalive vals; vals.onoff = 1; vals.keepalivetime = tcp_keepidle * 1000; - vals.keepaliveinterval = tcp_keepintvl * 1000; - if (unlikely(WSAIoctl(fd, SIO_KEEPALIVE_VALS, &vals, sizeof(vals), + vals.keepaliveinterval = tcp_keepintvl * 1000; + if(unlikely(WSAIoctl(fd, SIO_KEEPALIVE_VALS, &vals, sizeof(vals), NULL, 0, &outputBytes, NULL, NULL))) return 1; #endif /* WIN32 */ @@ -297,10 +353,11 @@ static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd, #endif json_t *json_rpc_call(CURL *curl, const char *url, - const char *userpass, const char *rpc_req, - bool longpoll_scan, bool longpoll, int *curl_err) + const char *userpass, const char *rpc_req, + bool longpoll_scan, bool longpoll, int *curl_err) { - json_t *val, *err_val, *res_val; + json_t *val = NULL, *err_val = NULL, *res_val = NULL; + char *s = NULL; int rc; struct data_buffer all_data = {0}; struct upload_buffer upload_data; @@ -313,11 +370,11 @@ json_t *json_rpc_call(CURL *curl, const char *url, bool lp_scanning = longpoll_scan && !have_longpoll; /* it is assumed that 'curl' is freshly [re]initialized at this pt */ - - if (opt_protocol) + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); + if(opt_protocol) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_URL, url); - if (opt_cert) + if(opt_cert) curl_easy_setopt(curl, CURLOPT_CAINFO, opt_cert); curl_easy_setopt(curl, CURLOPT_ENCODING, ""); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); @@ -336,28 +393,30 @@ json_t *json_rpc_call(CURL *curl, const char *url, curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi); - if (opt_proxy) { + if(opt_proxy) + { curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy); curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type); } - if (userpass) { + if(userpass) + { curl_easy_setopt(curl, CURLOPT_USERPWD, userpass); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); } #if LIBCURL_VERSION_NUM >= 0x070f06 - if (longpoll) + if(longpoll) curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_keepalive_cb); #endif curl_easy_setopt(curl, CURLOPT_POST, 1); - if (opt_protocol) + if(opt_protocol) applog(LOG_DEBUG, "JSON protocol request:\n%s\n", rpc_req); upload_data.buf = rpc_req; upload_data.len = strlen(rpc_req); upload_data.pos = 0; sprintf(len_hdr, "Content-Length: %lu", - (unsigned long) upload_data.len); + (unsigned long)upload_data.len); headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, len_hdr); @@ -369,57 +428,62 @@ json_t *json_rpc_call(CURL *curl, const char *url, curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); rc = curl_easy_perform(curl); - if (curl_err != NULL) + if(curl_err != NULL) *curl_err = rc; - if (rc) { - if (!(longpoll && rc == CURLE_OPERATION_TIMEDOUT)) + if(rc != CURLE_OK) + { + if(!longpoll) applog(LOG_ERR, "HTTP request failed: %s", curl_err_str); goto err_out; } /* If X-Stratum was found, activate Stratum */ - if (want_stratum && hi.stratum_url && - !strncasecmp(hi.stratum_url, "stratum+tcp://", 14) && - !(opt_proxy && opt_proxy_type == CURLPROXY_HTTP)) { + if(want_stratum && hi.stratum_url && + !strncasecmp(hi.stratum_url, "stratum+tcp://", 14) && + !(opt_proxy && opt_proxy_type == CURLPROXY_HTTP)) + { have_stratum = true; tq_push(thr_info[stratum_thr_id].q, hi.stratum_url); hi.stratum_url = NULL; } /* If X-Long-Polling was found, activate long polling */ - if (lp_scanning && hi.lp_path && !have_stratum) { + if(lp_scanning && hi.lp_path && !have_stratum) + { have_longpoll = true; tq_push(thr_info[longpoll_thr_id].q, hi.lp_path); hi.lp_path = NULL; } - if (!all_data.buf) { + if(!all_data.buf) + { applog(LOG_ERR, "Empty data received in json_rpc_call."); goto err_out; } val = JSON_LOADS((const char*)all_data.buf, &err); - if (!val) { + if(!val) + { applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text); goto err_out; } - if (opt_protocol) { - char *s = json_dumps(val, JSON_INDENT(3)); + if(opt_protocol) + { + s = json_dumps(val, JSON_INDENT(3)); applog(LOG_DEBUG, "JSON protocol response:\n%s", s); free(s); } /* JSON-RPC valid response returns a non-null 'result', - * and a null 'error'. */ + * and a null 'error'. */ res_val = json_object_get(val, "result"); err_val = json_object_get(val, "error"); - if (!res_val || json_is_null(res_val) || - (err_val && !json_is_null(err_val))) { - char *s; - - if (err_val) + if(!res_val || json_is_null(res_val) || + (err_val && !json_is_null(err_val))) + { + if(err_val) s = json_dumps(err_val, JSON_INDENT(3)); else s = strdup("(unknown reason)"); @@ -431,7 +495,7 @@ json_t *json_rpc_call(CURL *curl, const char *url, goto err_out; } - if (hi.reason) + if(hi.reason) json_object_set_new(val, "reject-reason", json_string(hi.reason)); databuf_free(&all_data); @@ -453,11 +517,11 @@ char *bin2hex(const unsigned char *p, size_t len) { unsigned int i; char *s = (char*)malloc((len * 2) + 1); - if (!s) + if(!s) return NULL; - for (i = 0; i < len; i++) - sprintf(s + (i * 2), "%02x", (unsigned int) p[i]); + for(i = 0; i < len; i++) + sprintf(s + (i * 2), "%02x", (unsigned int)p[i]); return s; } @@ -469,15 +533,18 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len) hex_byte[2] = '\0'; - while (*hexstr && len) { - if (!hexstr[1]) { + while(*hexstr && len) + { + if(!hexstr[1]) + { applog(LOG_ERR, "hex2bin str truncated"); return false; } hex_byte[0] = hexstr[0]; hex_byte[1] = hexstr[1]; - *p = (unsigned char) strtol(hex_byte, &ep, 16); - if (*ep) { + *p = (unsigned char)strtol(hex_byte, &ep, 16); + if(*ep) + { applog(LOG_ERR, "hex2bin failed on '%s'", hex_byte); return false; } @@ -490,25 +557,27 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len) } /* Subtract the `struct timeval' values X and Y, - storing the result in RESULT. - Return 1 if the difference is negative, otherwise 0. */ +storing the result in RESULT. +Return 1 if the difference is negative, otherwise 0. */ int timeval_subtract(struct timeval *result, struct timeval *x, - struct timeval *y) +struct timeval *y) { /* Perform the carry for the later subtraction by updating Y. */ - if (x->tv_usec < y->tv_usec) { + if(x->tv_usec < y->tv_usec) + { int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; y->tv_usec -= 1000000 * nsec; y->tv_sec += nsec; } - if (x->tv_usec - y->tv_usec > 1000000) { + if(x->tv_usec - y->tv_usec > 1000000) + { int nsec = (x->tv_usec - y->tv_usec) / 1000000; y->tv_usec += 1000000 * nsec; y->tv_sec -= nsec; } /* Compute the time remaining to wait. - * `tv_usec' is certainly positive. */ + * `tv_usec' is certainly positive. */ result->tv_sec = x->tv_sec - y->tv_sec; result->tv_usec = x->tv_usec - y->tv_usec; @@ -520,23 +589,28 @@ bool fulltest(const uint32_t *hash, const uint32_t *target) { int i; bool rc = true; - - for (i = 7; i >= 0; i--) { - if (hash[i] > target[i]) { + + for(i = 7; i >= 0; i--) + { + if(hash[i] > target[i]) + { rc = false; break; } - if (hash[i] < target[i]) { + if(hash[i] < target[i]) + { rc = true; break; } } - if (opt_debug) { + if(opt_debug) + { uint32_t hash_be[8], target_be[8]; char *hash_str, *target_str; - - for (i = 0; i < 8; i++) { + + for(i = 0; i < 8; i++) + { be32enc(hash_be + i, hash[7 - i]); be32enc(target_be + i, target[7 - i]); } @@ -544,10 +618,10 @@ bool fulltest(const uint32_t *hash, const uint32_t *target) target_str = bin2hex((unsigned char *)target_be, 32); applog(LOG_DEBUG, "DEBUG: %s\nHash: %s\nTarget: %s", - rc ? "hash <= target" - : "hash > target (false positive)", - hash_str, - target_str); + rc ? "hash <= target" + : "hash > target (false positive)", + hash_str, + target_str); free(hash_str); free(target_str); @@ -560,13 +634,14 @@ void diff_to_target(uint32_t *target, double diff) { uint64_t m; int k; - - for (k = 6; k > 0 && diff > 1.0; k--) + + for(k = 6; k > 0 && diff > 1.0; k--) diff /= 4294967296.0; m = (uint64_t)(4294901760.0 / diff); - if (m == 0 && k == 6) + if(m == 0 && k == 6) memset(target, 0xff, 32); - else { + else + { memset(target, 0, 32); target[k] = (uint32_t)m; target[k + 1] = (uint32_t)(m >> 32); @@ -582,22 +657,24 @@ void diff_to_target(uint32_t *target, double diff) static bool send_line(curl_socket_t sock, char *s) { ssize_t len, sent = 0; - + len = (ssize_t)strlen(s); s[len++] = '\n'; - while (len > 0) { + while(len > 0) + { struct timeval timeout = {0, 0}; ssize_t n; fd_set wd; FD_ZERO(&wd); FD_SET(sock, &wd); - if (select((int)sock + 1, NULL, &wd, NULL, &timeout) < 1) + if(select((int)sock + 1, NULL, &wd, NULL, &timeout) < 1) return false; - n = send(sock, s + sent, len, 0); - if (n < 0) { - if (!socket_blocks()) + n = send(sock, s + sent, (int)len, 0); + if(n < 0) + { + if(!socket_blocks()) return false; n = 0; } @@ -612,7 +689,7 @@ bool stratum_send_line(struct stratum_ctx *sctx, char *s) { bool ret = false; - if (opt_protocol) + if(opt_protocol) applog(LOG_DEBUG, "> %s", s); pthread_mutex_lock(&sctx->sock_lock); @@ -631,7 +708,7 @@ static bool socket_full(curl_socket_t sock, int timeout) FD_SET(sock, &rd); tv.tv_sec = timeout; tv.tv_usec = 0; - if (select((int)sock + 1, &rd, NULL, NULL, &tv) > 0) + if(select((int)sock + 1, &rd, NULL, NULL, &tv) > 0) return true; return false; } @@ -650,7 +727,8 @@ static void stratum_buffer_append(struct stratum_ctx *sctx, const char *s) old = strlen(sctx->sockbuf); snew = old + strlen(s) + 1; - if (snew >= sctx->sockbuf_size) { + if(snew >= sctx->sockbuf_size) + { sctx->sockbuf_size = snew + (RBUFSIZE - (snew % RBUFSIZE)); sctx->sockbuf = (char*)realloc(sctx->sockbuf, sctx->sockbuf_size); } @@ -660,37 +738,45 @@ static void stratum_buffer_append(struct stratum_ctx *sctx, const char *s) char *stratum_recv_line(struct stratum_ctx *sctx) { ssize_t len, buflen; - char *tok, *sret = NULL; + char *tok = NULL, *sret = NULL; - if (!strstr(sctx->sockbuf, "\n")) { + if(!strstr(sctx->sockbuf, "\n")) + { bool ret = true; time_t rstart; time(&rstart); - if (!socket_full(sctx->sock, 60)) { + if(!socket_full(sctx->sock, 60)) + { applog(LOG_ERR, "stratum_recv_line timed out"); goto out; } - do { + do + { char s[RBUFSIZE]; ssize_t n; memset(s, 0, RBUFSIZE); n = recv(sctx->sock, s, RECVSIZE, 0); - if (!n) { + if(!n) + { ret = false; break; } - if (n < 0) { - if (!socket_blocks() || !socket_full(sctx->sock, 1)) { + if(n < 0) + { + if(!socket_blocks() || !socket_full(sctx->sock, 1)) + { ret = false; break; } - } else + } + else stratum_buffer_append(sctx, s); - } while (time(NULL) - rstart < 60 && !strstr(sctx->sockbuf, "\n")); + } while(time(NULL) - rstart < 60 && !strstr(sctx->sockbuf, "\n")); - if (!ret) { + if(!ret) + { applog(LOG_ERR, "stratum_recv_line failed"); goto out; } @@ -698,27 +784,28 @@ char *stratum_recv_line(struct stratum_ctx *sctx) buflen = (ssize_t)strlen(sctx->sockbuf); tok = strtok(sctx->sockbuf, "\n"); - if (!tok) { + if(!tok) + { applog(LOG_ERR, "stratum_recv_line failed to parse a newline-terminated string"); goto out; } sret = strdup(tok); len = (ssize_t)strlen(sret); - if (buflen > len + 1) + if(buflen > len + 1) memmove(sctx->sockbuf, sctx->sockbuf + len + 1, buflen - len + 1); else sctx->sockbuf[0] = '\0'; out: - if (sret && opt_protocol) + if(sret && opt_protocol) applog(LOG_DEBUG, "< %s", sret); return sret; } #if LIBCURL_VERSION_NUM >= 0x071101 static curl_socket_t opensocket_grab_cb(void *clientp, curlsocktype purpose, - struct curl_sockaddr *addr) +struct curl_sockaddr *addr) { curl_socket_t *sock = (curl_socket_t *)clientp; *sock = socket(addr->family, addr->socktype, addr->protocol); @@ -732,23 +819,26 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url) int rc; pthread_mutex_lock(&sctx->sock_lock); - if (sctx->curl) + if(sctx->curl) curl_easy_cleanup(sctx->curl); sctx->curl = curl_easy_init(); - if (!sctx->curl) { + if(!sctx->curl) + { applog(LOG_ERR, "CURL initialization failed"); pthread_mutex_unlock(&sctx->sock_lock); return false; } curl = sctx->curl; - if (!sctx->sockbuf) { + if(!sctx->sockbuf) + { sctx->sockbuf = (char*)calloc(RBUFSIZE, 1); sctx->sockbuf_size = RBUFSIZE; } sctx->sockbuf[0] = '\0'; pthread_mutex_unlock(&sctx->sock_lock); - if (url != sctx->url) { + if(url != sctx->url) + { free(sctx->url); sctx->url = strdup(url); } @@ -756,21 +846,25 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url) sctx->curl_url = (char*)malloc(strlen(url)); sprintf(sctx->curl_url, "http%s", strstr(url, "://")); - if (opt_protocol) + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); + if(opt_protocol) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_URL, sctx->curl_url); - curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1); +/* curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1); */ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sctx->curl_err_str); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1); - if (opt_proxy && opt_proxy_type != CURLPROXY_HTTP) { + if(opt_proxy && opt_proxy_type != CURLPROXY_HTTP) + { curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy); curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type); - } else if (getenv("http_proxy")) { - if (getenv("all_proxy")) + } + else if(getenv("http_proxy")) + { + if(getenv("all_proxy")) curl_easy_setopt(curl, CURLOPT_PROXY, getenv("all_proxy")); - else if (getenv("ALL_PROXY")) + else if(getenv("ALL_PROXY")) curl_easy_setopt(curl, CURLOPT_PROXY, getenv("ALL_PROXY")); else curl_easy_setopt(curl, CURLOPT_PROXY, ""); @@ -785,7 +879,8 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url) curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1); rc = curl_easy_perform(curl); - if (rc) { + if(rc != CURLE_OK) + { applog(LOG_ERR, "Stratum connection failed: %s", sctx->curl_err_str); curl_easy_cleanup(curl); sctx->curl = NULL; @@ -803,7 +898,8 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url) void stratum_disconnect(struct stratum_ctx *sctx) { pthread_mutex_lock(&sctx->sock_lock); - if (sctx->curl) { + if(sctx->curl) + { curl_easy_cleanup(sctx->curl); sctx->curl = NULL; sctx->sockbuf[0] = '\0'; @@ -817,155 +913,54 @@ static const char *get_stratum_session_id(json_t *val) int i, n; arr_val = json_array_get(val, 0); - if (!arr_val || !json_is_array(arr_val)) + if(!arr_val || !json_is_array(arr_val)) return NULL; n = json_array_size(arr_val); - for (i = 0; i < n; i++) { + for(i = 0; i < n; i++) + { const char *notify; json_t *arr = json_array_get(arr_val, i); - if (!arr || !json_is_array(arr)) + if(!arr || !json_is_array(arr)) break; notify = json_string_value(json_array_get(arr, 0)); - if (!notify) + if(!notify) continue; - if (!strcasecmp(notify, "mining.notify")) + if(!strcasecmp(notify, "mining.notify")) return json_string_value(json_array_get(arr, 1)); } return NULL; } -bool stratum_subscribe(struct stratum_ctx *sctx) -{ - if(jsonrpc_2) return true; - char *s, *sret = NULL; - const char *sid, *xnonce1; - int xn2_size; - json_t *val = NULL, *res_val, *err_val; - json_error_t err; - bool ret = false, retry = false; - -start: - s = (char*)malloc(128 + (sctx->session_id ? strlen(sctx->session_id) : 0)); - if (retry) - sprintf(s, "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}"); - else if (sctx->session_id) - sprintf(s, "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"" USER_AGENT "\", \"%s\"]}", sctx->session_id); - else - sprintf(s, "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"" USER_AGENT "\"]}"); - - if (!stratum_send_line(sctx, s)) - goto out; - - if (!socket_full(sctx->sock, 30)) { - applog(LOG_ERR, "stratum_subscribe timed out"); - goto out; - } - - sret = stratum_recv_line(sctx); - if (!sret) - goto out; - - val = JSON_LOADS(sret, &err); - free(sret); - if (!val) { - applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text); - goto out; - } - - res_val = json_object_get(val, "result"); - err_val = json_object_get(val, "error"); - - if (!res_val || json_is_null(res_val) || - (err_val && !json_is_null(err_val))) { - if (opt_debug || retry) { - free(s); - if (err_val) - s = json_dumps(err_val, JSON_INDENT(3)); - else - s = strdup("(unknown reason)"); - applog(LOG_ERR, "JSON-RPC call failed: %s", s); - } - goto out; - } - - sid = get_stratum_session_id(res_val); - if (opt_debug && !sid) - applog(LOG_DEBUG, "Failed to get Stratum session id"); - xnonce1 = json_string_value(json_array_get(res_val, 1)); - if (!xnonce1) { - applog(LOG_ERR, "Failed to get extranonce1"); - goto out; - } - xn2_size = json_integer_value(json_array_get(res_val, 2)); - if (!xn2_size) { - applog(LOG_ERR, "Failed to get extranonce2_size"); - goto out; - } - - pthread_mutex_lock(&sctx->work_lock); - free(sctx->session_id); - free(sctx->xnonce1); - sctx->session_id = sid ? strdup(sid) : NULL; - sctx->xnonce1_size = strlen(xnonce1) / 2; - sctx->xnonce1 = (unsigned char*)malloc(sctx->xnonce1_size); - hex2bin(sctx->xnonce1, xnonce1, sctx->xnonce1_size); - sctx->xnonce2_size = xn2_size; - sctx->next_diff = 1.0; - pthread_mutex_unlock(&sctx->work_lock); - - if (opt_debug && sid) - applog(LOG_DEBUG, "Stratum session id: %s", sctx->session_id); - - ret = true; - -out: - free(s); - if (val) - json_decref(val); - - if (!ret) { - if (sret && !retry) { - retry = true; - goto start; - } - } - - return ret; -} - bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass) { - json_t *val = NULL, *res_val, *err_val; - char *s, *sret; + json_t *val = NULL, *res_val = NULL, *err_val = NULL; + json_t *job_val = NULL; + char *s = NULL, *sret = NULL; json_error_t err; bool ret = false; - if(jsonrpc_2) { - s = (char*)malloc(300 + strlen(user) + strlen(pass)); - sprintf(s, "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"cpuminer-multi/0.1\"}, \"id\": 1}", - user, pass); - } else { - s = (char*)malloc(80 + strlen(user) + strlen(pass)); - sprintf(s, "{\"id\": 2, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}", - user, pass); - } + s = (char*)malloc(300 + strlen(user) + strlen(pass)); + sprintf(s, "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"%s/%s\"}, \"id\": 1}", + user, pass, PACKAGE_NAME, PACKAGE_VERSION); - if (!stratum_send_line(sctx, s)) + if(!stratum_send_line(sctx, s)) goto out; - while (1) { + while(1) + { sret = stratum_recv_line(sctx); - if (!sret) + if(!sret) goto out; - if (!stratum_handle_method(sctx, sret)) + if(!stratum_handle_method(sctx, sret)) break; free(sret); } val = JSON_LOADS(sret, &err); free(sret); - if (!val) { + if(!val) + { applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text); goto out; } @@ -973,25 +968,24 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p res_val = json_object_get(val, "result"); err_val = json_object_get(val, "error"); - if (!res_val || json_is_false(res_val) || - (err_val && !json_is_null(err_val))) { + if(!res_val || json_is_false(res_val) || + (err_val && !json_is_null(err_val))) + { applog(LOG_ERR, "Stratum authentication failed"); goto out; } - if(jsonrpc_2) { - rpc2_login_decode(val); - json_t *job_val = json_object_get(res_val, "job"); - pthread_mutex_lock(&sctx->work_lock); - if(job_val) rpc2_job_decode(job_val, &sctx->work); - pthread_mutex_unlock(&sctx->work_lock); - } + rpc2_login_decode(val); + job_val = json_object_get(res_val, "job"); + pthread_mutex_lock(&sctx->work_lock); + if(job_val) rpc2_job_decode(job_val, &sctx->work); + pthread_mutex_unlock(&sctx->work_lock); ret = true; out: free(s); - if (val) + if(val) json_decref(val); return ret; @@ -999,28 +993,30 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p static bool stratum_2_job(struct stratum_ctx *sctx, json_t *params) { - bool ret = false; - pthread_mutex_lock(&sctx->work_lock); - ret = rpc2_job_decode(params, &sctx->work); - pthread_mutex_unlock(&sctx->work_lock); - return ret; + bool ret = false; + pthread_mutex_lock(&sctx->work_lock); + ret = rpc2_job_decode(params, &sctx->work); + pthread_mutex_unlock(&sctx->work_lock); + return ret; } static bool stratum_notify(struct stratum_ctx *sctx, json_t *params) { - const char *job_id, *prevhash, *coinb1, *coinb2, *version, *nbits, *ntime, *nreward; + const char *job_id = NULL, *prevhash = NULL, *coinb1 = NULL, *coinb2 = NULL, *version = NULL, *nbits = NULL; + const char *ntime = NULL, *nreward = NULL; + const char *s = NULL; size_t coinb1_size, coinb2_size; bool clean, ret = false; int merkle_count, i; - json_t *merkle_arr; - unsigned char **merkle; + json_t *merkle_arr = NULL; + unsigned char **merkle = NULL; job_id = json_string_value(json_array_get(params, 0)); prevhash = json_string_value(json_array_get(params, 1)); coinb1 = json_string_value(json_array_get(params, 2)); coinb2 = json_string_value(json_array_get(params, 3)); merkle_arr = json_array_get(params, 4); - if (!merkle_arr || !json_is_array(merkle_arr)) + if(!merkle_arr || !json_is_array(merkle_arr)) goto out; merkle_count = json_array_size(merkle_arr); version = json_string_value(json_array_get(params, 5)); @@ -1029,17 +1025,20 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params) clean = json_is_true(json_array_get(params, 8)); nreward = json_string_value(json_array_get(params, 9)); - if (!job_id || !prevhash || !coinb1 || !coinb2 || !version || !nbits || !ntime || - strlen(prevhash) != 64 || strlen(version) != 8 || - strlen(nbits) != 8 || strlen(ntime) != 8) { + if(!job_id || !prevhash || !coinb1 || !coinb2 || !version || !nbits || !ntime || + strlen(prevhash) != 64 || strlen(version) != 8 || + strlen(nbits) != 8 || strlen(ntime) != 8) + { applog(LOG_ERR, "Stratum notify: invalid parameters"); goto out; } merkle = (unsigned char**)malloc(merkle_count * sizeof(char *)); - for (i = 0; i < merkle_count; i++) { - const char *s = json_string_value(json_array_get(merkle_arr, i)); - if (!s || strlen(s) != 64) { - while (i--) + for(i = 0; i < merkle_count; i++) + { + s = json_string_value(json_array_get(merkle_arr, i)); + if(!s || strlen(s) != 64) + { + while(i--) free(merkle[i]); free(merkle); applog(LOG_ERR, "Stratum notify: invalid Merkle branch"); @@ -1054,12 +1053,12 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params) coinb1_size = strlen(coinb1) / 2; coinb2_size = strlen(coinb2) / 2; sctx->job.coinbase_size = coinb1_size + sctx->xnonce1_size + - sctx->xnonce2_size + coinb2_size; + sctx->xnonce2_size + coinb2_size; sctx->job.coinbase = (unsigned char*)realloc(sctx->job.coinbase, sctx->job.coinbase_size); sctx->job.xnonce2 = sctx->job.coinbase + coinb1_size + sctx->xnonce1_size; hex2bin(sctx->job.coinbase, coinb1, coinb1_size); memcpy(sctx->job.coinbase + coinb1_size, sctx->xnonce1, sctx->xnonce1_size); - if (!sctx->job.job_id || strcmp(sctx->job.job_id, job_id)) + if(!sctx->job.job_id || strcmp(sctx->job.job_id, job_id)) memset(sctx->job.xnonce2, 0, sctx->xnonce2_size); hex2bin(sctx->job.xnonce2 + sctx->xnonce2_size, coinb2, coinb2_size); @@ -1067,7 +1066,7 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params) sctx->job.job_id = strdup(job_id); hex2bin(sctx->job.prevhash, prevhash, 32); - for (i = 0; i < sctx->job.merkle_count; i++) + for(i = 0; i < sctx->job.merkle_count; i++) free(sctx->job.merkle[i]); free(sctx->job.merkle); sctx->job.merkle = merkle; @@ -1098,14 +1097,14 @@ static bool stratum_set_difficulty(struct stratum_ctx *sctx, json_t *params) double diff; diff = json_number_value(json_array_get(params, 0)); - if (diff == 0) + if(diff == 0) return false; pthread_mutex_lock(&sctx->work_lock); sctx->next_diff = diff; pthread_mutex_unlock(&sctx->work_lock); - if (opt_debug) + if(opt_debug) applog(LOG_DEBUG, "Stratum difficulty set to %g", diff); return true; @@ -1119,13 +1118,13 @@ static bool stratum_reconnect(struct stratum_ctx *sctx, json_t *params) host = json_string_value(json_array_get(params, 0)); port_val = json_array_get(params, 1); - if (json_is_string(port_val)) + if(json_is_string(port_val)) port = atoi(json_string_value(port_val)); else port = json_integer_value(port_val); - if (!host || !port) + if(!host || !port) return false; - + free(sctx->url); sctx->url = (char*)malloc(32 + strlen(host)); sprintf(sctx->url, "stratum+tcp://%s:%d", host, port); @@ -1142,8 +1141,8 @@ static bool stratum_get_version(struct stratum_ctx *sctx, json_t *id) char *s; json_t *val; bool ret; - - if (!id || json_is_null(id)) + + if(!id || json_is_null(id)) return false; val = json_object(); @@ -1165,10 +1164,10 @@ static bool stratum_show_message(struct stratum_ctx *sctx, json_t *id, json_t *p bool ret; val = json_array_get(params, 0); - if (val) + if(val) applog(LOG_NOTICE, "MESSAGE FROM SERVER: %s", json_string_value(val)); - - if (!id || json_is_null(id)) + + if(!id || json_is_null(id)) return true; val = json_object(); @@ -1185,52 +1184,32 @@ static bool stratum_show_message(struct stratum_ctx *sctx, json_t *id, json_t *p bool stratum_handle_method(struct stratum_ctx *sctx, const char *s) { - json_t *val, *id, *params; + json_t *val = NULL, *id = NULL, *params = NULL; json_error_t err; - const char *method; + const char *method = NULL; bool ret = false; val = JSON_LOADS(s, &err); - if (!val) { + if(!val) + { applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text); goto out; } method = json_string_value(json_object_get(val, "method")); - if (!method) + if(!method) goto out; id = json_object_get(val, "id"); params = json_object_get(val, "params"); - if (jsonrpc_2) { - if (!strcasecmp(method, "job")) { - ret = stratum_2_job(sctx, params); - goto out; - } - } else { - if (!strcasecmp(method, "mining.notify")) { - ret = stratum_notify(sctx, params); - goto out; - } - if (!strcasecmp(method, "mining.set_difficulty")) { - ret = stratum_set_difficulty(sctx, params); - goto out; - } - if (!strcasecmp(method, "client.reconnect")) { - ret = stratum_reconnect(sctx, params); - goto out; - } - if (!strcasecmp(method, "client.get_version")) { - ret = stratum_get_version(sctx, id); - goto out; - } - if (!strcasecmp(method, "client.show_message")) { - ret = stratum_show_message(sctx, id, params); - goto out; - } - } + if(!strcasecmp(method, "job")) + { + ret = stratum_2_job(sctx, params); + goto out; + } + out: - if (val) + if(val) json_decref(val); return ret; @@ -1241,7 +1220,7 @@ struct thread_q *tq_new(void) struct thread_q *tq; tq = (struct thread_q *)calloc(1, sizeof(*tq)); - if (!tq) + if(!tq) return NULL; INIT_LIST_HEAD(&tq->q); @@ -1255,10 +1234,11 @@ void tq_free(struct thread_q *tq) { struct tq_ent *ent, *iter; - if (!tq) + if(!tq) return; - list_for_each_entry_safe(ent, iter, &tq->q, q_node, struct tq_ent, struct tq_ent) { + list_for_each_entry_safe(ent, iter, &tq->q, q_node, struct tq_ent, struct tq_ent) + { list_del(&ent->q_node); free(ent); } @@ -1296,7 +1276,7 @@ bool tq_push(struct thread_q *tq, void *data) bool rc = true; ent = (struct tq_ent *)calloc(1, sizeof(*ent)); - if (!ent) + if(!ent) return false; ent->data = data; @@ -1304,9 +1284,12 @@ bool tq_push(struct thread_q *tq, void *data) pthread_mutex_lock(&tq->mutex); - if (!tq->frozen) { + if(!tq->frozen) + { list_add_tail(&ent->q_node, &tq->q); - } else { + } + else + { free(ent); rc = false; } @@ -1319,22 +1302,22 @@ bool tq_push(struct thread_q *tq, void *data) void *tq_pop(struct thread_q *tq, const struct timespec *abstime) { - struct tq_ent *ent; + struct tq_ent *ent = NULL; void *rval = NULL; int rc; pthread_mutex_lock(&tq->mutex); - if (!list_empty(&tq->q)) + if(!list_empty(&tq->q)) goto pop; - if (abstime) + if(abstime) rc = pthread_cond_timedwait(&tq->cond, &tq->mutex, abstime); else rc = pthread_cond_wait(&tq->cond, &tq->mutex); - if (rc) + if(rc) goto out; - if (list_empty(&tq->q)) + if(list_empty(&tq->q)) goto out; pop: @@ -1349,29 +1332,51 @@ void *tq_pop(struct thread_q *tq, const struct timespec *abstime) return rval; } -void hexdump( const char *what, void *data, const size_t datalen ) +void hexdump(const char *what, void *data, const size_t datalen) { - char *padding; - int i, len; - - len = strlen(what) + 3; - padding = (char *)malloc(len+1); + char *padding; + size_t i, len; + + len = strlen(what) + 3; + padding = (char *)malloc(len + 1); + + if(padding == NULL) return; + + memset(padding, 0x20, len); + padding[len] = 0; + + printf("%s : ", what); + + for(i = 0; i < datalen; i++) + { + + if(i > 0 && i % 16 == 0) printf("\n%s", padding); + printf("0x%02x ", ((uint8_t*)data)[i]); + } - if( padding == NULL ) return; + printf("\n"); - memset(padding, 0x20, len); - padding[len] = 0; + free(padding); +} - printf("%s : ", what); - - for( i = 0; i < datalen; i++ ) { +bool stratum_keepalived(struct stratum_ctx *sctx, const char *rpc2_id) +{ + json_t *val = NULL; + char *s = NULL; + bool ret = false; - if( i > 0 && i % 16 == 0 ) printf("\n%s", padding); - printf("0x%02x ", ((uint8_t*)data)[i]); - } - - printf("\n"); + s = (char *)malloc(300 + strlen(rpc2_id)); + if(s == NULL) + return ret; + snprintf(s, 128, "{\"method\": \"keepalived\", \"params\": {\"id\": \"%s\"}, \"id\":1}\r\n", rpc2_id); - free(padding); + if(!stratum_send_line(sctx, s)) + { + goto out; + } + ret = true; +out: + free(s); + return ret; }