Commit e6adb5c2 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@16019 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 9b012758
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
KOKKOS_PATH = ${HOME}/kokkos
SRC = $(wildcard *.cpp)
KOKKOS_DEVICES=Cuda
KOKKOS_CUDA_OPTIONS=enable_lambda

default: build
	echo "Start Build"

ifneq (,$(findstring Cuda,$(KOKKOS_DEVICES)))
CXX = ${KOKKOS_PATH}/config/nvcc_wrapper
EXE = bytes_and_flops.cuda
KOKKOS_DEVICES = "Cuda,OpenMP"
KOKKOS_ARCH = "SNB,Kepler35"
else
CXX = g++
EXE = bytes_and_flops.host
KOKKOS_DEVICES = "OpenMP"
KOKKOS_ARCH = "SNB"
endif

CXXFLAGS = -O3 -g

DEPFLAGS = -M
LINK = ${CXX}
LINKFLAGS =  

OBJ = $(SRC:.cpp=.o)
LIB =

include $(KOKKOS_PATH)/Makefile.kokkos

build: $(EXE)

$(EXE): $(OBJ) $(KOKKOS_LINK_DEPENDS)
	$(LINK) $(KOKKOS_LDFLAGS) $(LINKFLAGS) $(EXTRA_PATH) $(OBJ) $(KOKKOS_LIBS) $(LIB) -o $(EXE)

clean: kokkos-clean 
	rm -f *.o *.cuda *.host

# Compilation rules

%.o:%.cpp $(KOKKOS_CPP_DEPENDS) bench.hpp bench_unroll_stride.hpp bench_stride.hpp
	$(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) $(EXTRA_INC) -c $<
+99 −0
Original line number Diff line number Diff line
/*
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 2.0
//              Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact  H. Carter Edwards (hcedwar@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#include<Kokkos_Core.hpp>
#include<impl/Kokkos_Timer.hpp>

template<class Scalar, int Unroll,int Stride>
struct Run {
static void run(int N, int K, int R, int F, int T, int S);
};

template<class Scalar, int Stride>
struct RunStride {
static void run_1(int N, int K, int R, int F, int T, int S);
static void run_2(int N, int K, int R, int F, int T, int S);
static void run_3(int N, int K, int R, int F, int T, int S);
static void run_4(int N, int K, int R, int F, int T, int S);
static void run_5(int N, int K, int R, int F, int T, int S);
static void run_6(int N, int K, int R, int F, int T, int S);
static void run_7(int N, int K, int R, int F, int T, int S);
static void run_8(int N, int K, int R, int F, int T, int S);
static void run(int N, int K, int R, int U, int F, int T, int S);
};

#define STRIDE 1
#include<bench_stride.hpp>
#undef STRIDE
#define STRIDE 2
#include<bench_stride.hpp>
#undef STRIDE
#define STRIDE 4
#include<bench_stride.hpp>
#undef STRIDE
#define STRIDE 8
#include<bench_stride.hpp>
#undef STRIDE
#define STRIDE 16
#include<bench_stride.hpp>
#undef STRIDE
#define STRIDE 32
#include<bench_stride.hpp>
#undef STRIDE

template<class Scalar>
void run_stride_unroll(int N, int K, int R, int D, int U, int F, int T, int S) {
 if(D == 1)
   RunStride<Scalar,1>::run(N,K,R,U,F,T,S);
 if(D == 2)
   RunStride<Scalar,2>::run(N,K,R,U,F,T,S);
 if(D == 4)
   RunStride<Scalar,4>::run(N,K,R,U,F,T,S);
 if(D == 8)
   RunStride<Scalar,8>::run(N,K,R,U,F,T,S);
 if(D == 16)
   RunStride<Scalar,16>::run(N,K,R,U,F,T,S);
 if(D == 32)
   RunStride<Scalar,32>::run(N,K,R,U,F,T,S);
}
+124 −0
Original line number Diff line number Diff line
/*
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 2.0
//              Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact  H. Carter Edwards (hcedwar@sandia.gov)
//
// ************************************************************************
//@HEADER
*/


#define UNROLL 1
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 2
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 3
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 4
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 5
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 6
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 7
#include<bench_unroll_stride.hpp>
#undef UNROLL
#define UNROLL 8
#include<bench_unroll_stride.hpp>
#undef UNROLL

template<class Scalar>
struct RunStride<Scalar,STRIDE> {
static void run_1(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,1,STRIDE>::run(N,K,R,F,T,S);
}
static void run_2(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,2,STRIDE>::run(N,K,R,F,T,S);
}
static void run_3(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,3,STRIDE>::run(N,K,R,F,T,S);
}
static void run_4(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,4,STRIDE>::run(N,K,R,F,T,S);
}
static void run_5(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,5,STRIDE>::run(N,K,R,F,T,S);
}
static void run_6(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,6,STRIDE>::run(N,K,R,F,T,S);
}
static void run_7(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,7,STRIDE>::run(N,K,R,F,T,S);
}
static void run_8(int N, int K, int R, int F, int T, int S) {
  Run<Scalar,8,STRIDE>::run(N,K,R,F,T,S);
}

static void run(int N, int K, int R, int U, int F, int T, int S) {
  if(U==1) {
    run_1(N,K,R,F,T,S);
  }
  if(U==2) {
    run_2(N,K,R,F,T,S);
  }
  if(U==3) {
    run_3(N,K,R,F,T,S);
  }
  if(U==4) {
    run_4(N,K,R,F,T,S);
  }
  if(U==5) {
    run_5(N,K,R,F,T,S);
  }
  if(U==6) {
    run_6(N,K,R,F,T,S);
  }
  if(U==7) {
    run_7(N,K,R,F,T,S);
  }
  if(U==8) {
    run_8(N,K,R,F,T,S);
  } 
}
};
+148 −0
Original line number Diff line number Diff line
/*
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 2.0
//              Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact  H. Carter Edwards (hcedwar@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

template<class Scalar>
struct Run<Scalar,UNROLL,STRIDE> {
static void run(int N, int K, int R, int F, int T, int S) {
  Kokkos::View<Scalar**[STRIDE],Kokkos::LayoutRight> A("A",N,K);
  Kokkos::View<Scalar**[STRIDE],Kokkos::LayoutRight> B("B",N,K);
  Kokkos::View<Scalar**[STRIDE],Kokkos::LayoutRight> C("C",N,K);

  Kokkos::deep_copy(A,Scalar(1.5));
  Kokkos::deep_copy(B,Scalar(2.5));
  Kokkos::deep_copy(C,Scalar(3.5));

  Kokkos::Timer timer;
  Kokkos::parallel_for("BenchmarkKernel",Kokkos::TeamPolicy<>(N,T).set_scratch_size(0,Kokkos::PerTeam(S)),
    KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type& team) {
    const int n = team.league_rank();
    for(int r=0; r<R; r++) {
      Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,K), [&] (const int& i) {
        Scalar a1 = A(n,i,0); 
        const Scalar b = B(n,i,0);
#if(UNROLL>1)
        Scalar a2 = a1*1.3;
#endif
#if(UNROLL>2)
        Scalar a3 = a2*1.1;
#endif
#if(UNROLL>3)
        Scalar a4 = a3*1.1;
#endif
#if(UNROLL>4)
        Scalar a5 = a4*1.3;
#endif
#if(UNROLL>5)
        Scalar a6 = a5*1.1;
#endif
#if(UNROLL>6)
        Scalar a7 = a6*1.1;
#endif
#if(UNROLL>7)
        Scalar a8 = a7*1.1;
#endif


        for(int f = 0; f<F; f++) {
          a1 += b*a1;
#if(UNROLL>1)
          a2 += b*a2;
#endif
#if(UNROLL>2)
          a3 += b*a3;
#endif
#if(UNROLL>3)
          a4 += b*a4;
#endif
#if(UNROLL>4)
          a5 += b*a5;
#endif
#if(UNROLL>5)
          a6 += b*a6;
#endif
#if(UNROLL>6)
          a7 += b*a7;
#endif
#if(UNROLL>7)
          a8 += b*a8;
#endif


        }
#if(UNROLL==1)
        C(n,i,0) = a1; 
#endif
#if(UNROLL==2)
        C(n,i,0) = a1+a2; 
#endif
#if(UNROLL==3)
        C(n,i,0) = a1+a2+a3; 
#endif
#if(UNROLL==4)
        C(n,i,0) = a1+a2+a3+a4; 
#endif
#if(UNROLL==5)
        C(n,i,0) = a1+a2+a3+a4+a5;
#endif
#if(UNROLL==6)
        C(n,i,0) = a1+a2+a3+a4+a5+a6;
#endif
#if(UNROLL==7)
        C(n,i,0) = a1+a2+a3+a4+a5+a6+a7;
#endif
#if(UNROLL==8)
        C(n,i,0) = a1+a2+a3+a4+a5+a6+a7+a8;
#endif

      });
    }
  });
  Kokkos::fence(); 
  double seconds = timer.seconds();

  double bytes = 1.0*N*K*R*3*sizeof(Scalar);
  double flops = 1.0*N*K*R*(F*2*UNROLL + 2*(UNROLL-1));
  printf("NKRUFTS: %i %i %i %i %i %i %i Time: %lfs Bandwidth: %lfGiB/s GFlop/s: %lf\n",N,K,R,UNROLL,F,T,S,seconds,1.0*bytes/seconds/1024/1024/1024,1.e-9*flops/seconds);
}
};
+96 −0
Original line number Diff line number Diff line
/*
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 2.0
//              Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact  H. Carter Edwards (hcedwar@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#include<Kokkos_Core.hpp>
#include<impl/Kokkos_Timer.hpp>
#include<bench.hpp>

int main(int argc, char* argv[]) {
  Kokkos::initialize();
  

  if(argc<10) { 
    printf("Arguments: N K R D U F T S\n");
    printf("  P:   Precision (1==float, 2==double)\n");
    printf("  N,K: dimensions of the 2D array to allocate\n");
    printf("  R:   how often to loop through the K dimension with each team\n");
    printf("  D:   distance between loaded elements (stride)\n");
    printf("  U:   how many independent flops to do per load\n");
    printf("  F:   how many times to repeat the U unrolled operations before reading next element\n");
    printf("  T:   team size\n");
    printf("  S:   shared memory per team (used to control occupancy on GPUs)\n");
    printf("Example Input GPU:\n");
    printf("  Bandwidth Bound : 2 100000 1024 1 1 1 1 256 6000\n");
    printf("  Cache Bound     : 2 100000 1024 64 1 1 1 512 20000\n");
    printf("  Compute Bound   : 2 100000 1024 1 1 8 64 256 6000\n");
    printf("  Load Slots Used : 2 20000 256 32 16 1 1 256 6000\n");
    printf("  Inefficient Load: 2 20000 256 32 2 1 1 256 20000\n");
    Kokkos::finalize();
    return 0;
  }
  

  int P = atoi(argv[1]);
  int N = atoi(argv[2]);
  int K = atoi(argv[3]);
  int R = atoi(argv[4]);
  int D = atoi(argv[5]);
  int U = atoi(argv[6]);
  int F = atoi(argv[7]);
  int T = atoi(argv[8]);
  int S = atoi(argv[9]);

  if(U>8) {printf("U must be 1-8\n"); return 0;} 
  if( (D!=1) && (D!=2) && (D!=4) && (D!=8) && (D!=16) && (D!=32)) {printf("D must be one of 1,2,4,8,16,32\n"); return 0;}
  if( (P!=1) && (P!=2) ) {printf("P must be one of 1,2\n"); return 0;}

  if(P==1) {
    run_stride_unroll<float>(N,K,R,D,U,F,T,S);
  }
  if(P==2) {
    run_stride_unroll<double>(N,K,R,D,U,F,T,S);
  }

  Kokkos::finalize();
}
Loading