8 changed files with 337 additions and 129 deletions
			
			
		- 
					55resources/cmake/FindCusp.cmake
- 
					69resources/cmake/FindThrust.cmake
- 
					64resources/cudaForStorm/CMakeAlignmentCheck.cpp
- 
					93resources/cudaForStorm/CMakeLists.txt
- 
					87resources/cudaForStorm/srcCuda/basicValueIteration.cu
- 
					2resources/cudaForStorm/srcCuda/basicValueIteration.h
- 
					83resources/cudaForStorm/srcCuda/cuspExtension.h
- 
					13resources/cudaForStorm/storm-cudaplugin-config.h.in
| @ -0,0 +1,55 @@ | |||||
|  | # | ||||
|  | # FindCusp | ||||
|  | # | ||||
|  | # This module finds the CUSP header files and extracts their version.  It | ||||
|  | # sets the following variables. | ||||
|  | # | ||||
|  | # CUSP_INCLUDE_DIR -  Include directory for cusp header files.  (All header | ||||
|  | #                       files will actually be in the cusp subdirectory.) | ||||
|  | # CUSP_VERSION -      Version of cusp in the form "major.minor.patch". | ||||
|  | # | ||||
|  | # CUSP_FOUND - Indicates whether Cusp has been found | ||||
|  | # | ||||
|  | 
 | ||||
|  | find_path(CUSP_INCLUDE_DIR | ||||
|  | 	HINTS | ||||
|  | 		/usr/include/cusp | ||||
|  | 		/usr/local/include | ||||
|  | 		/usr/local/cusp/include | ||||
|  | 		${CUSP_INCLUDE_DIRS} | ||||
|  | 		${CUSP_HINT} | ||||
|  | 	NAMES cusp/version.h | ||||
|  | 	DOC "Cusp headers" | ||||
|  | ) | ||||
|  | if(CUSP_INCLUDE_DIR) | ||||
|  | 	list(REMOVE_DUPLICATES CUSP_INCLUDE_DIR) | ||||
|  | endif(CUSP_INCLUDE_DIR) | ||||
|  | 
 | ||||
|  | # Find cusp version | ||||
|  | file(STRINGS ${CUSP_INCLUDE_DIR}/cusp/version.h | ||||
|  | 	version | ||||
|  | 	REGEX "#define CUSP_VERSION[ \t]+([0-9x]+)" | ||||
|  | ) | ||||
|  | string(REGEX REPLACE | ||||
|  | 	"#define CUSP_VERSION[ \t]+" | ||||
|  | 	"" | ||||
|  | 	version | ||||
|  | 	"${version}" | ||||
|  | ) | ||||
|  | 
 | ||||
|  | #define CUSP_MAJOR_VERSION     (CUSP_VERSION / 100000) | ||||
|  | #define CUSP_MINOR_VERSION     (CUSP_VERSION / 100 % 1000) | ||||
|  | #define CUSP_SUBMINOR_VERSION  (CUSP_VERSION % 100) | ||||
|  | 
 | ||||
|  | math(EXPR CUSP_MAJOR_VERSION "${version} / 100000") | ||||
|  | math(EXPR CUSP_MINOR_VERSION "${version} / 100 % 1000") | ||||
|  | math(EXPR CUSP_PATCH_VERSION "${version} % 100") | ||||
|  | 
 | ||||
|  | set(CUSP_VERSION "${CUSP_MAJOR_VERSION}.${CUSP_MINOR_VERSION}.${CUSP_PATCH_VERSION}") | ||||
|  | 
 | ||||
|  | # Check for required components | ||||
|  | include(FindPackageHandleStandardArgs) | ||||
|  | find_package_handle_standard_args(Cusp REQUIRED_VARS CUSP_INCLUDE_DIR VERSION_VAR CUSP_VERSION) | ||||
|  | 
 | ||||
|  | set(CUSP_INCLUDE_DIRS ${CUSP_INCLUDE_DIR}) | ||||
|  | mark_as_advanced(CUSP_INCLUDE_DIR) | ||||
| @ -1,53 +1,52 @@ | |||||
| # | # | ||||
| # FindThrust | # FindThrust | ||||
| # | # | ||||
| # This module finds the Thrust header files and extrats their version.  It |  | ||||
|  | # This module finds the Thrust header files and extracts their version.  It | ||||
| # sets the following variables. | # sets the following variables. | ||||
| # | # | ||||
| # THRUST_INCLUDE_DIR -  Include directory for thrust header files.  (All header | # THRUST_INCLUDE_DIR -  Include directory for thrust header files.  (All header | ||||
| #                       files will actually be in the thrust subdirectory.) | #                       files will actually be in the thrust subdirectory.) | ||||
| # THRUST_VERSION -      Version of thrust in the form "major.minor.patch". | # THRUST_VERSION -      Version of thrust in the form "major.minor.patch". | ||||
| # | # | ||||
|  | # Thrust_FOUND - Indicates whether Thrust has been found | ||||
|  | # | ||||
| 
 | 
 | ||||
| find_path( THRUST_INCLUDE_DIR |  | ||||
|   HINTS |  | ||||
|     /usr/include/cuda |  | ||||
|     /usr/local/include |  | ||||
|     /usr/local/cuda/include |  | ||||
|     ${CUDA_INCLUDE_DIRS} |  | ||||
|   NAMES thrust/version.h |  | ||||
|   DOC "Thrust headers" |  | ||||
|   ) |  | ||||
| if( THRUST_INCLUDE_DIR ) |  | ||||
|   list( REMOVE_DUPLICATES THRUST_INCLUDE_DIR ) |  | ||||
| endif( THRUST_INCLUDE_DIR ) |  | ||||
|  | find_path(THRUST_INCLUDE_DIR | ||||
|  | 	HINTS | ||||
|  | 		/usr/include/cuda | ||||
|  | 		/usr/local/include | ||||
|  | 		/usr/local/cuda/include | ||||
|  | 		${CUDA_INCLUDE_DIRS} | ||||
|  | 	NAMES thrust/version.h | ||||
|  | 	DOC "Thrust headers" | ||||
|  | ) | ||||
|  | if(THRUST_INCLUDE_DIR) | ||||
|  | 	list(REMOVE_DUPLICATES THRUST_INCLUDE_DIR) | ||||
|  | endif(THRUST_INCLUDE_DIR) | ||||
| 
 | 
 | ||||
| # Find thrust version | # Find thrust version | ||||
| file( STRINGS ${THRUST_INCLUDE_DIR}/thrust/version.h |  | ||||
|   version |  | ||||
|   REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)" |  | ||||
|   ) |  | ||||
| string( REGEX REPLACE |  | ||||
|   "#define THRUST_VERSION[ \t]+" |  | ||||
|   "" |  | ||||
|   version |  | ||||
|   "${version}" |  | ||||
|   ) |  | ||||
|  | file(STRINGS ${THRUST_INCLUDE_DIR}/thrust/version.h | ||||
|  | 	version | ||||
|  | 	REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)" | ||||
|  | ) | ||||
|  | string(REGEX REPLACE | ||||
|  | 	"#define THRUST_VERSION[ \t]+" | ||||
|  | 	"" | ||||
|  | 	version | ||||
|  | 	"${version}" | ||||
|  | ) | ||||
| 
 | 
 | ||||
| string( REGEX MATCH "^[0-9]" major ${version} ) |  | ||||
| string( REGEX REPLACE "^${major}00" "" version "${version}" ) |  | ||||
| string( REGEX MATCH "^[0-9]" minor ${version} ) |  | ||||
| string( REGEX REPLACE "^${minor}0" "" version "${version}" ) |  | ||||
| set( THRUST_VERSION "${major}.${minor}.${version}") |  | ||||
| set( THRUST_MAJOR_VERSION "${major}") |  | ||||
| set( THRUST_MINOR_VERSION "${minor}") |  | ||||
|  | string(REGEX MATCH "^[0-9]" major ${version}) | ||||
|  | string(REGEX REPLACE "^${major}00" "" version "${version}") | ||||
|  | string(REGEX MATCH "^[0-9]" minor ${version}) | ||||
|  | string(REGEX REPLACE "^${minor}0" "" version "${version}") | ||||
|  | set(THRUST_VERSION "${major}.${minor}.${version}") | ||||
|  | set(THRUST_MAJOR_VERSION "${major}") | ||||
|  | set(THRUST_MINOR_VERSION "${minor}") | ||||
| 
 | 
 | ||||
| # Check for required components | # Check for required components | ||||
| include( FindPackageHandleStandardArgs ) |  | ||||
| find_package_handle_standard_args( Thrust |  | ||||
|   REQUIRED_VARS THRUST_INCLUDE_DIR |  | ||||
|   VERSION_VAR THRUST_VERSION |  | ||||
|   ) |  | ||||
|  | include(FindPackageHandleStandardArgs) | ||||
|  | find_package_handle_standard_args(Thrust REQUIRED_VARS THRUST_INCLUDE_DIR VERSION_VAR THRUST_VERSION) | ||||
| 
 | 
 | ||||
| set(THRUST_INCLUDE_DIRS ${THRUST_INCLUDE_DIR}) | set(THRUST_INCLUDE_DIRS ${THRUST_INCLUDE_DIR}) | ||||
| mark_as_advanced(THRUST_INCLUDE_DIR) | mark_as_advanced(THRUST_INCLUDE_DIR) | ||||
| @ -0,0 +1,64 @@ | |||||
|  | /*
 | ||||
|  |  * This is component of StoRM - Cuda Plugin to check whether type alignment matches the assumptions done while optimizing the code. | ||||
|  |  */ | ||||
|  |  #include <cstdint>
 | ||||
|  |  #include <utility>
 | ||||
|  |  #include <vector>
 | ||||
|  |   | ||||
|  |  #define CONTAINER_SIZE 100ul
 | ||||
|  |   | ||||
|  |  template <typename IndexType, typename ValueType> | ||||
|  |  int checkForAlignmentOfPairTypes(size_t containerSize, IndexType const firstValue, ValueType const secondValue) { | ||||
|  | 	std::vector<std::pair<IndexType, ValueType>>* myVector = new std::vector<std::pair<IndexType, ValueType>>(); | ||||
|  | 	for (size_t i = 0; i < containerSize; ++i) { | ||||
|  | 		myVector->push_back(std::make_pair(firstValue, secondValue)); | ||||
|  | 	} | ||||
|  | 	size_t myVectorSize = myVector->size(); | ||||
|  | 	IndexType* firstStart = &(myVector->at(0).first); | ||||
|  | 	IndexType* firstEnd = &(myVector->at(myVectorSize - 1).first); | ||||
|  | 	ValueType* secondStart = &(myVector->at(0).second); | ||||
|  | 	ValueType* secondEnd = &(myVector->at(myVectorSize - 1).second); | ||||
|  | 	size_t startOffset = reinterpret_cast<size_t>(secondStart) - reinterpret_cast<size_t>(firstStart); | ||||
|  | 	size_t endOffset = reinterpret_cast<size_t>(secondEnd) - reinterpret_cast<size_t>(firstEnd); | ||||
|  | 	size_t firstOffset = reinterpret_cast<size_t>(firstEnd) - reinterpret_cast<size_t>(firstStart); | ||||
|  | 	size_t secondOffset = reinterpret_cast<size_t>(secondEnd) - reinterpret_cast<size_t>(secondStart); | ||||
|  | 	 | ||||
|  | 	delete myVector; | ||||
|  | 	myVector = nullptr; | ||||
|  | 	 | ||||
|  | 	if (myVectorSize != containerSize) { | ||||
|  | 		return -2; | ||||
|  | 	} | ||||
|  | 	 | ||||
|  | 	// Check for alignment:
 | ||||
|  | 	// Requirement is that the pairs are aligned like: first, second, first, second, first, second, ...
 | ||||
|  | 	if (sizeof(IndexType) != sizeof(ValueType)) { | ||||
|  | 		return -3; | ||||
|  | 	} | ||||
|  | 	if (startOffset != sizeof(IndexType)) { | ||||
|  | 		return -4; | ||||
|  | 	} | ||||
|  | 	if (endOffset != sizeof(IndexType)) { | ||||
|  | 		return -5; | ||||
|  | 	} | ||||
|  | 	if (firstOffset != ((sizeof(IndexType) + sizeof(ValueType)) * (myVectorSize - 1))) { | ||||
|  | 		return -6; | ||||
|  | 	} | ||||
|  | 	if (secondOffset != ((sizeof(IndexType) + sizeof(ValueType)) * (myVectorSize - 1))) { | ||||
|  | 		return -7; | ||||
|  | 	} | ||||
|  | 	 | ||||
|  | 	return 0; | ||||
|  |  } | ||||
|  |   | ||||
|  |   | ||||
|  |  int main(int argc, char* argv[]) { | ||||
|  | 	int result = 0; | ||||
|  | 	 | ||||
|  | 	result = checkForAlignmentOfPairTypes<uint_fast64_t, double>(CONTAINER_SIZE, 42, 3.14); | ||||
|  | 	if (result != 0) { | ||||
|  | 		return result; | ||||
|  | 	} | ||||
|  | 	 | ||||
|  | 	return 0; | ||||
|  |  } | ||||
| @ -0,0 +1,83 @@ | |||||
|  | /* | ||||
|  |  * This is an extension of the original CUSP csr_vector.h SPMV implementation. | ||||
|  |  * It is based on the Code and incorporates changes as to cope with the details | ||||
|  |  * of the StoRM code. | ||||
|  |  * As this is mostly copy & past, the original license still applies. | ||||
|  |  */ | ||||
|  | 
 | ||||
|  | /* | ||||
|  |  *  Copyright 2008-2009 NVIDIA Corporation | ||||
|  |  * | ||||
|  |  *  Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  |  *  you may not use this file except in compliance with the License. | ||||
|  |  *  You may obtain a copy of the License at | ||||
|  |  * | ||||
|  |  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  |  * | ||||
|  |  *  Unless required by applicable law or agreed to in writing, software | ||||
|  |  *  distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  |  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  |  *  See the License for the specific language governing permissions and | ||||
|  |  *  limitations under the License. | ||||
|  |  */ | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | #pragma once | ||||
|  | 
 | ||||
|  | #include <cusp/detail/device/spmv/csr_vector.h> | ||||
|  | 
 | ||||
|  | namespace cusp | ||||
|  | { | ||||
|  | namespace detail | ||||
|  | { | ||||
|  | namespace device | ||||
|  | { | ||||
|  | 
 | ||||
|  | template <bool UseCache, unsigned int THREADS_PER_VECTOR, typename IndexType, typename ValueType> | ||||
|  | void __storm_cuda_spmv_csr_vector(const IndexType num_rows, const IndexType * matrixRowIndices, const IndexType * matrixColumnIndices, const ValueType * matrixValues, const ValueType* x, ValueType* y) | ||||
|  | { | ||||
|  |     const size_t THREADS_PER_BLOCK  = 128; | ||||
|  |     const size_t VECTORS_PER_BLOCK  = THREADS_PER_BLOCK / THREADS_PER_VECTOR; | ||||
|  | 
 | ||||
|  |     const size_t MAX_BLOCKS = cusp::detail::device::arch::max_active_blocks(spmv_csr_vector_kernel<IndexType, ValueType, VECTORS_PER_BLOCK, THREADS_PER_VECTOR, UseCache>, THREADS_PER_BLOCK, (size_t) 0); | ||||
|  |     const size_t NUM_BLOCKS = std::min<size_t>(MAX_BLOCKS, DIVIDE_INTO(num_rows, VECTORS_PER_BLOCK)); | ||||
|  |      | ||||
|  |     if (UseCache) | ||||
|  |         bind_x(x); | ||||
|  | 
 | ||||
|  |     spmv_csr_vector_kernel<IndexType, ValueType, VECTORS_PER_BLOCK, THREADS_PER_VECTOR, UseCache> <<<NUM_BLOCKS, THREADS_PER_BLOCK>>>  | ||||
|  |         (num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); | ||||
|  | 
 | ||||
|  |     if (UseCache) | ||||
|  |         unbind_x(x); | ||||
|  | } | ||||
|  | 
 | ||||
|  | template <typename IndexType, typename ValueType> | ||||
|  | void storm_cuda_spmv_csr_vector(const IndexType num_rows, const IndexType num_entries, const IndexType * matrixRowIndices, const IndexType * matrixColumnIndices, const ValueType * matrixValues, const ValueType* x, ValueType* y) | ||||
|  | { | ||||
|  |     const IndexType nnz_per_row = num_entries / num_rows; | ||||
|  | 
 | ||||
|  |     if (nnz_per_row <=  2) { __storm_cuda_spmv_csr_vector<false, 2>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |     if (nnz_per_row <=  4) { __storm_cuda_spmv_csr_vector<false, 4>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |     if (nnz_per_row <=  8) { __storm_cuda_spmv_csr_vector<false, 8>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |     if (nnz_per_row <= 16) { __storm_cuda_spmv_csr_vector<false,16>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |      | ||||
|  |     __storm_cuda_spmv_csr_vector<false,32>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); | ||||
|  | } | ||||
|  | 
 | ||||
|  | template <typename IndexType, typename ValueType> | ||||
|  | void storm_cuda_spmv_csr_vector_tex(const IndexType num_rows, const IndexType num_entries, const IndexType * matrixRowIndices, const IndexType * matrixColumnIndices, const ValueType * matrixValues, const ValueType* x, ValueType* y) | ||||
|  | { | ||||
|  |     const IndexType nnz_per_row = num_entries / num_rows; | ||||
|  | 
 | ||||
|  |     if (nnz_per_row <=  2) { __storm_cuda_spmv_csr_vector<true, 2>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |     if (nnz_per_row <=  4) { __storm_cuda_spmv_csr_vector<true, 4>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |     if (nnz_per_row <=  8) { __storm_cuda_spmv_csr_vector<true, 8>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  |     if (nnz_per_row <= 16) { __storm_cuda_spmv_csr_vector<true,16>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); return; } | ||||
|  | 
 | ||||
|  |     __storm_cuda_spmv_csr_vector<true,32>(num_rows, matrixRowIndices, matrixColumnIndices, matrixValues, x, y); | ||||
|  | } | ||||
|  | 
 | ||||
|  | } // end namespace device | ||||
|  | } // end namespace detail | ||||
|  | } // end namespace cusp | ||||
| @ -0,0 +1,13 @@ | |||||
|  | /* | ||||
|  |  * StoRM - Build-in Options | ||||
|  |  * | ||||
|  |  * This file is parsed by CMake during makefile generation | ||||
|  |  * It contains information such as the base path to the test/example data | ||||
|  |  */ | ||||
|  | 
 | ||||
|  | #ifndef STORM_CUDAPLUGIN_GENERATED_STORMCONFIG_H_ | ||||
|  | #define STORM_CUDAPLUGIN_GENERATED_STORMCONFIG_H_ | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | #endif // STORM_CUDAPLUGIN_GENERATED_STORMCONFIG_H_ | ||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue