kokkos / kokkos-kernels

Kokkos C++ Performance Portability Programming Ecosystem: Math Kernels - Provides BLAS, Sparse BLAS and Graph Kernels
Other
305 stars 96 forks source link

Can I get some detail information about how to run the example code ? #1104

Open yuanAIhan opened 3 years ago

yuanAIhan commented 3 years ago

I only want to know how to run the example code. and I may can solve the cmake error...

srajama1 commented 3 years ago

@yuanAIhan Which example code are you trying to run?

yuanAIhan commented 3 years ago

@yuanAIhan Which example code are you trying to run?

https://github.com/kokkos/kokkos-kernels/blob/master/example/wiki/sparse/KokkosSparse_wiki_spgemm.cpp

yuanAIhan commented 3 years ago

such as https://github.com/kokkos/kokkos-kernels/blob/master/example/wiki/sparse/KokkosSparse_wiki_spgemm.cpp,I don't know which compilation instructions should I use to complete it.

lucbv commented 3 years ago

Hi @yuanAIhan the instructions to build Kokkos Kernels can be found on our here wiki. In general here are the steps to follow:

  1. git clone git@github.com:kokkos/kokkos.git
  2. build and install Kokkos (needs to be done outside Kokkos source directory), see the procedure below (${KOKKOS_PATH} is the path to the Kokkos source directory while ${KOKKOS_INSTALL} is the path to the Kokkos installation directory which you need later to build Kokkos Kernels)
    
    cmake -D CMAKE_CXX_COMPILER:STRING="g++" \
    -D CMAKE_CXX_STANDARD:STRING="14" \
    -D CMAKE_INSTALL_PREFIX:PATH=${KOKKOS_INSTALL} \
    -D Kokkos_ENABLE_SERIAL:BOOL=ON \
    -D Kokkos_ENABLE_TESTS:BOOL=OFF \
    -D Kokkos_ENABLE_EXAMPLES:BOOL=OFF \
    ${KOKKOS_PATH}

make install -j

3. git clone git@github.com:kokkos/kokkos-kernels.git
4. build and install Kokkos Kernels with tests and examples enabled, here ${KOKKOS_INSTALL} is the same as in step 2. and ${KOKKOSKERNELS_PATH} is the path to the source code of Kokkos Kernels.

cmake -D CMAKE_CXX_COMPILER:STRING="g++" \ -D CMAKE_CXX_STANDARD:STRING="14" \ -D Kokkos_DIR:PATH="${KOKKOS_INSTALL}/lib/cmake/Kokkos" \ -D KokkosKernels_ENABLE_TESTS:BOOL=ON \ -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON \ ${KOKKOSKERNELS_PATH}



If this does not work, please post the output of the `cmake` configuration steps so we can see what went wrong.
yuanAIhan commented 3 years ago

Yes! I solved the problem of how to make it run today . But I ran into another problem. Is there any document about how to use kokkos-kernel? For example, Kokkos' guide book is a good tutorial on Kokkos. Like the following code, when I want to modify the dimensions of this matrix, it is very difficult for me. image

lucbv commented 3 years ago

We have the wiki and the examples which serve as main user resources to learn more about Kokkos Kernels. In your case, the structured matrix generation is a small utility that we only use in one or two tests and not for any production so it is not considered as a priority for documentation. In the following code, I would think that the comment states which values need to be modified, i.e. mat_structure(0, 0) and mat_structure(1, 0)

Kokkos::View<Ordinal*[3], Kokkos::HostSpace> mat_structure("Matrix Structure", 2);
mat_structure(0, 0) = 10; // Request 10 grid points in `x` direction
mat_structure(0, 0) = 1;  // Add BC to the left
mat_structure(0, 0) = 1;  // Add BC to the right
mat_structure(1, 0) = 10; // Request 10 grid points in `y` direction
mat_structure(1, 0) = 1;  // Add BC to the bottom
mat_structure(1, 0) = 1;  // Add BC to the top

How would you suggest to add more comment that make the use of mat_structure more clear?

ArindamK92 commented 3 years ago

Hi @yuanAIhan the instructions to build Kokkos Kernels can be found on our here wiki. In general here are the steps to follow:

  1. git clone git@github.com:kokkos/kokkos.git
  2. build and install Kokkos (needs to be done outside Kokkos source directory), see the procedure below (${KOKKOS_PATH} is the path to the Kokkos source directory while ${KOKKOS_INSTALL} is the path to the Kokkos installation directory which you need later to build Kokkos Kernels)
cmake -D CMAKE_CXX_COMPILER:STRING="g++" \
    -D CMAKE_CXX_STANDARD:STRING="14" \
    -D CMAKE_INSTALL_PREFIX:PATH=${KOKKOS_INSTALL} \
    -D Kokkos_ENABLE_SERIAL:BOOL=ON \
    -D Kokkos_ENABLE_TESTS:BOOL=OFF \
    -D Kokkos_ENABLE_EXAMPLES:BOOL=OFF \
    ${KOKKOS_PATH}

make install -j
  1. git clone git@github.com:kokkos/kokkos-kernels.git
  2. build and install Kokkos Kernels with tests and examples enabled, here ${KOKKOS_INSTALL} is the same as in step 2. and ${KOKKOSKERNELS_PATH} is the path to the source code of Kokkos Kernels.
cmake -D CMAKE_CXX_COMPILER:STRING="g++" \
    -D CMAKE_CXX_STANDARD:STRING="14" \
    -D Kokkos_DIR:PATH="${KOKKOS_INSTALL}/lib/cmake/Kokkos" \
    -D KokkosKernels_ENABLE_TESTS:BOOL=ON \
    -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON \
    ${KOKKOSKERNELS_PATH}

If this does not work, please post the output of the cmake configuration steps so we can see what went wrong.

Hi, I followed all the steps. I want to run KokkosKernels_Example_Distance2GraphColor.cpp. Can you please tell me how I can get the executable KokkosKernels_Example_Distance2GraphColor.exe ? I didn't find scripts/generate_makefile.bash.

lucbv commented 3 years ago

@ArindamK92 can you post the configure line that you used and the corresponding output? If you have compiled Kokkos Kernels with -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON \ the distance 2 graph color executable should be built for you.

ArindamK92 commented 3 years ago

@ArindamK92 can you post the configure line that you used and the corresponding output? If you have compiled Kokkos Kernels with -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON \ the distance 2 graph color executable should be built for you.

Yes I did. Here is the exact configure line cmake -D CMAKE_CXX_COMPILER:STRING="g++" \ -D Kokkos_DIR:PATH="/home/akkcm/kokkos/kokkos/install/lib/cmake/Kokkos" \ -D KokkosKernels_ENABLE_TESTS:BOOL=ON \ -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON \ /home/akkcm/kokkos-kernels/kokkos-kernels

lucbv commented 3 years ago

OK, I see that the example is not included in the build process, this is probably due to the example not being maintained anymore. What would you like to test? We have another executable currently maintained here: perf_test/graph/KokkosGraph_color_d2.cpp that should allow you to perform a distance coloring of a graph.

ArindamK92 commented 3 years ago

I want to use Kokkos to find vertex colors for a large graph. I found KokkosGraph_color_d2.cpp. Can you please tell me how I can compile it and make the executable? Are the inputs of KokkosGraph_color_d2.cpp same as KokkosKernels_Example_Distance2GraphColor.cpp?

lucbv commented 3 years ago

So KokkosGraph_color_d2.cpp should be built because you have the examples enabled, just look in the build directory: perf_test/graph/graph_color_d2. You should be able to run the executable with --help and you get the input/output options, but mostly you pass a matrix market file as input with --amtx then you can play with the parameters. For distance one coloring which might actually be what you want, just use graph_color instead of graph_color_d2

ArindamK92 commented 3 years ago

Thanks for the help. But unfortunately I don't see the executable in the folder.

~/kokkos-kernels/kokkos-kernels/perf_test/graph$ ls CMakeLists.txt KokkosGraph_color.cpp KokkosGraph_color_d2.cpp KokkosGraph_mis_d2.cpp KokkosGraph_multimem_triangle.hpp KokkosGraph_run_triangle.hpp KokkosGraph_triangle.cpp

lucbv commented 3 years ago

Did you build in the source directory? I am not sure that's allowed actually?

ArindamK92 commented 3 years ago

can you tell me the direct command to compile it? E.g. direct g++ -o .... ... -I .... kind of command or some cmake

ArindamK92 commented 3 years ago

Did you build in the source directory? I am not sure that's allowed actually?

You mean I need to give the install folder path outside the kokkos folder? Here is the exact thing I did:

/home/akkcm/cmake-3.21.3-linux-x86_64/bin/cmake -D CMAKE_CXX_COMPILER:STRING="g++" -D CMAKE_INSTALL_PREFIX:PATH="/home/akkcm/kokkos/kokkos/install" -D Kokkos_ENABLE_SERIAL:BOOL=ON -D Kokkos_ENABLE_TESTS:BOOL=OFF -D Kokkos_ENABLE_EXAMPLES:BOOL=ON /home/akkcm/kokkos/kokkos

make install -j

/home/akkcm/cmake-3.21.3-linux-x86_64/bin/cmake -D CMAKE_CXX_COMPILER:STRING="g++" \ -D Kokkos_DIR:PATH="/home/akkcm/kokkos/kokkos/install/lib/cmake/Kokkos" \ -D KokkosKernels_ENABLE_TESTS:BOOL=ON \ -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON \ /home/akkcm/kokkos-kernels/kokkos-kernels

lucbv commented 3 years ago

Just to have things setup cleanly based on your above cmake command I would do something like:

mkdir /home/akkcm/kokkos-kernels/build
cd /home/akkcm/kokkos-kernels/build

cmake -D CMAKE_CXX_COMPILER:STRING="g++"
-D Kokkos_DIR:PATH="/home/akkcm/kokkos/kokkos/install/lib/cmake/Kokkos"
-D KokkosKernels_ENABLE_TESTS:BOOL=ON
-D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON
/home/akkcm/kokkos-kernels/kokkos-kernels

make -j
ArindamK92 commented 3 years ago

Just to have things setup cleanly based on your above cmake command I would do something like:

mkdir /home/akkcm/kokkos-kernels/build
cd /home/akkcm/kokkos-kernels/build

cmake -D CMAKE_CXX_COMPILER:STRING="g++"
-D Kokkos_DIR:PATH="/home/akkcm/kokkos/kokkos/install/lib/cmake/Kokkos"
-D KokkosKernels_ENABLE_TESTS:BOOL=ON
-D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON
/home/akkcm/kokkos-kernels/kokkos-kernels

make -j

Ok, I can do that quickly and let you know

lucbv commented 3 years ago

Sure, if you need to install the library and to later link an application against it, add -D CMAKE_INSTALL_PREFIX:PATH=/home/akkcm/kokkos-kernels/install and the following after the build is performed:

mkdir /home/akkcm/kokkos-kernels/install
cd /home/akkcm/kokkos-kernels/install

make install -j

Note that it's not necessary to build the tests and examples.

ArindamK92 commented 3 years ago

Thank you so much. Now I got the desired executable in /kokkos-kernels/build/perf_test/graph.

ArindamK92 commented 3 years ago

I am trying to run graph_color. But I could not generate any color output. I am getting like below and the output file is blank.

/kokkos-kernels/build/perf_test/graph$ ./graph_color --openmp 8 --algorithm COLORING_VB --amtx test_GraphAK.mtx --outputfile output Sizeof(idx):4 sizeof(size_type):4 Kokkos Version: 3.4.1 Compiler: KOKKOS_COMPILER_GNU: 750 Architecture: Default Device: N6Kokkos6SerialE KOKKOS_ENABLE_ISA_KNC: no KOKKOS_ENABLE_ISA_POWERPCLE: no KOKKOS_ENABLE_ISA_X86_64: no Atomics: KOKKOS_ENABLE_GNU_ATOMICS: no KOKKOS_ENABLE_INTEL_ATOMICS: no KOKKOS_ENABLE_WINDOWS_ATOMICS: no Vectorization: KOKKOS_ENABLE_PRAGMA_IVDEP: no KOKKOS_ENABLE_PRAGMA_LOOPCOUNT: no KOKKOS_ENABLE_PRAGMA_SIMD: no KOKKOS_ENABLE_PRAGMA_UNROLL: no KOKKOS_ENABLE_PRAGMA_VECTOR: no Memory: KOKKOS_ENABLE_HBWSPACE: no KOKKOS_ENABLE_INTEL_MM_ALLOC: no KOKKOS_ENABLE_POSIX_MEMALIGN: no Options: KOKKOS_ENABLE_ASM: yes KOKKOS_ENABLE_CXX14: yes KOKKOS_ENABLE_CXX17: no KOKKOS_ENABLE_CXX20: no KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK: no KOKKOS_ENABLE_HWLOC: no KOKKOS_ENABLE_LIBRT: no KOKKOS_ENABLE_MPI: no Host Serial Execution Space: KOKKOS_ENABLE_SERIAL: yes Serial Atomics: KOKKOS_ENABLE_SERIAL_ATOMICS: yes

Serial Runtime Configuration:

lucbv commented 3 years ago

@brian-kelley should be able to help you with that : )

brian-kelley commented 3 years ago

@ArindamK92 I ran a command exactly like yours but with a graph from SuiteSparse (bodyy5) and it wrote out the colors as expected. Is test_GraphAK.mtx structurally symmetric (that's required for Kokkos Kernels coloring)? That's the simplest reason I could see for it not working.

ArindamK92 commented 3 years ago

@ArindamK92 I ran a command exactly like yours but with a graph from SuiteSparse (bodyy5) and it wrote out the colors as expected. Is test_GraphAK.mtx structurally symmetric (that's required for Kokkos Kernels coloring)? That's the simplest reason I could see for it not working.

I used a very small test graph as shown below. 3 3 2 1 2 1 3

lucbv commented 3 years ago

Hum, that leads to a non-symmetric graph:

[0 1 1]
[0 0 0]
[0 0 0]

you could switch to the following graph:

[0 1 1]
[1 0 0]
[1 0 0]

using the following matrix-market:

3 3 4
1 2
1 3
2 1
3 1
ArindamK92 commented 3 years ago

Sorry to say, it didn't work either. ~/kokkos-kernels/build/perf_test/graph$ ls CMakeFiles cmake_install.cmake CTestTestfile.cmake graph_color graph_color_d2 graph_mis_d2 Makefile test_GraphAK.mtx

~/kokkos-kernels/build/perf_test/graph$ ./graph_color --openmp 1 --algorithm COLORING_EB --amtx test_GraphAK.mtx --outputfile result Sizeof(idx):4 sizeof(size_type):4 Kokkos Version: 3.4.1 Compiler: KOKKOS_COMPILER_GNU: 750 Architecture: Default Device: N6Kokkos6SerialE KOKKOS_ENABLE_ISA_KNC: no KOKKOS_ENABLE_ISA_POWERPCLE: no KOKKOS_ENABLE_ISA_X86_64: no Atomics: KOKKOS_ENABLE_GNU_ATOMICS: no KOKKOS_ENABLE_INTEL_ATOMICS: no KOKKOS_ENABLE_WINDOWS_ATOMICS: no Vectorization: KOKKOS_ENABLE_PRAGMA_IVDEP: no KOKKOS_ENABLE_PRAGMA_LOOPCOUNT: no KOKKOS_ENABLE_PRAGMA_SIMD: no KOKKOS_ENABLE_PRAGMA_UNROLL: no KOKKOS_ENABLE_PRAGMA_VECTOR: no Memory: KOKKOS_ENABLE_HBWSPACE: no KOKKOS_ENABLE_INTEL_MM_ALLOC: no KOKKOS_ENABLE_POSIX_MEMALIGN: no Options: KOKKOS_ENABLE_ASM: yes KOKKOS_ENABLE_CXX14: yes KOKKOS_ENABLE_CXX17: no KOKKOS_ENABLE_CXX20: no KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK: no KOKKOS_ENABLE_HWLOC: no KOKKOS_ENABLE_LIBRT: no KOKKOS_ENABLE_MPI: no Host Serial Execution Space: KOKKOS_ENABLE_SERIAL: yes Serial Atomics: KOKKOS_ENABLE_SERIAL_ATOMICS: yes

Serial Runtime Configuration:

~/kokkos-kernels/build/perf_test/graph$ cat test_GraphAK.mtx 3 3 4 1 2 1 3 2 1 3 1

brian-kelley commented 3 years ago

@ArindamK92 You need the MatrixMarket header line. With this file, it works for me:

%%MatrixMarket matrix coordinate real general
3 3 4
1 2
1 3
2 1
3 1
ArindamK92 commented 3 years ago

@brian-kelley It is still not working for me. :(

brian-kelley commented 3 years ago

@ArindamK92 Oh, I don't think your build actually has OpenMP enabled. My build has Serial and OpenMP both enabled, and it prints

Host Parallel Execution Space:
  KOKKOS_ENABLE_OPENMP: yes
OpenMP Atomics:
  KOKKOS_ENABLE_OPENMP_ATOMICS: no

OpenMP Runtime Configuration:
Kokkos::OpenMP thread_pool_topology[ 1 x 1 x 1 ]
Host Serial Execution Space:
  KOKKOS_ENABLE_SERIAL: yes
Serial Atomics:
  KOKKOS_ENABLE_SERIAL_ATOMICS: no

but yours just prints

 Host Serial Execution Space:
KOKKOS_ENABLE_SERIAL: yes
Serial Atomics:
KOKKOS_ENABLE_SERIAL_ATOMICS: yes

So if you want to get running with your current build, pass --serial 1 instead of --openmp 1 (the "1" in serial doesn't mean anything, it just needs to be nonzero). If you really do want OpenMP, rebuild Kokkos with -DKokkos_ENABLE_OPENMP=ON, and then re-configure and rebuild KokkosKernels. Then the command you've been trying will work.

ArindamK92 commented 2 years ago

@ArindamK92 Oh, I don't think your build actually has OpenMP enabled. My build has Serial and OpenMP both enabled, and it prints

Host Parallel Execution Space:
  KOKKOS_ENABLE_OPENMP: yes
OpenMP Atomics:
  KOKKOS_ENABLE_OPENMP_ATOMICS: no

OpenMP Runtime Configuration:
Kokkos::OpenMP thread_pool_topology[ 1 x 1 x 1 ]
Host Serial Execution Space:
  KOKKOS_ENABLE_SERIAL: yes
Serial Atomics:
  KOKKOS_ENABLE_SERIAL_ATOMICS: no

but yours just prints

 Host Serial Execution Space:
KOKKOS_ENABLE_SERIAL: yes
Serial Atomics:
KOKKOS_ENABLE_SERIAL_ATOMICS: yes

So if you want to get running with your current build, pass --serial 1 instead of --openmp 1 (the "1" in serial doesn't mean anything, it just needs to be nonzero). If you really do want OpenMP, rebuild Kokkos with -DKokkos_ENABLE_OPENMP=ON, and then re-configure and rebuild KokkosKernels. Then the command you've been trying will work.

Sorry for the late reply and thanks for the help. It is running properly now after building kokkos with 'DKokkos_ENABLE_OPENMP=ON`.