Skip to content

Commit

Permalink
proposed change which contains:
Browse files Browse the repository at this point in the history
(1) warning|erros handling more accurate via logging it.
(2) logging infrastructure to log
(3) logging configuration (4) compiler specific macroses to handle compiler-relative information
(4) append unittests to test logging
(5) append doxygen documentation
(6) append (in #if 0) examples of usage into pcaFit

(7) minor changes in README.md
(8) some changes in CMakeLists.txt relative to way how enumerate source and link libraries
  • Loading branch information
burlachenkok committed Nov 9, 2018
1 parent 18f715f commit 5dc14b9
Show file tree
Hide file tree
Showing 15 changed files with 1,120 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
*.swp

cuML-build/
cuml/build/

ml-prims-build/
ml-prims/build/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ $ make -j
$ ./ml_test
```

To list available test:
```bash
$./ml_test --gtest_list_tests
```

To launch test which fullname correspond to specific wildcard string:
```bash
$ ./ml_test --gtest_filter=*Pca*
```

### Python Notebooks

Demo notebooks can be found in python/notebooks folder.
Expand Down
17 changes: 8 additions & 9 deletions cuML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,16 @@ include_directories(src

add_subdirectory(${GTEST_DIR}/googletest ${PROJECT_BINARY_DIR}/googletest)

add_executable(ml_test
test/pca_test.cu
test/tsvd_test.cu
test/dbscan_test.cu
test/kmeans_test.cu
)
# Append source file in recursive manner, append header files to target for work with them in IDE
file(GLOB_RECURSE ml_prims_header "${MLPRIMS_DIR}/src/*.h" "${MLPRIMS_DIR}/src/*.hpp")
file(GLOB_RECURSE cuml_test_cuda_sources "test/*.cu")

add_executable(ml_test ${cuml_test_cuda_sources} ${ml_prims_header})
target_link_libraries(ml_test
${GTEST_LIBNAME}
cublas
curand
cusolver
${CUDA_cublas_LIBRARY}
${CUDA_curand_LIBRARY}
${CUDA_cusolver_LIBRARY}
${CUDA_CUDART_LIBRARY}
pthread
z)
28 changes: 25 additions & 3 deletions cuML/src/pca/pca.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "ml_utils.h"
#include "tsvd/tsvd.h"

#include "../../external/ml-prims/src/utils/logger/LoggerMacroses.h" ///< TODO: Ask how proper include this

namespace ML {

using namespace MLCommon;
Expand Down Expand Up @@ -85,6 +87,21 @@ void pcaFit(math_t *input, math_t *components, math_t *explained_var,
math_t *noise_vars, paramsPCA prms, cublasHandle_t cublas_handle,
cusolverDnHandle_t cusolver_handle) {

#if 0
//===========================================EXAMPLE OF USAGE ML_LOG_ERROR START==========================
::ML::Utils::Logger mylog = ::ML::Utils::Logger::initializeWithEnvironment();
bool forceLogForTest = true;
ML_LOG_TOOLCHAIN_INFO(mylog);
if (! (prms.n_cols > 1) || forceLogForTest )
ML_LOG_ERROR(mylog) << "Parameter n_cols: number of columns cannot be less than two." << " And you provide: '" << prms.n_cols << "\n";
if (! (prms.n_rows > 1) || forceLogForTest )
ML_LOG_ERROR(mylog) << "Parameter n_rows: number of rows cannot be less than two." << " And you provide: '" << prms.n_rows << "\n";
if (! (prms.n_components > 0) || forceLogForTest )
ML_LOG_ERROR(mylog) << "Parameter n_components: number of components cannot be less than one." << " And you provide: '" << prms.n_components << "\n";
//===========================================EXAMPLE OF USAGE END=========================================
#endif


ASSERT(prms.n_cols > 1,
"Parameter n_cols: number of columns cannot be less than two");
ASSERT(prms.n_rows > 1,
Expand All @@ -109,9 +126,14 @@ void pcaFit(math_t *input, math_t *components, math_t *explained_var,
math_t scalar = (prms.n_rows - 1);
Matrix::seqRoot(explained_var, singular_vals, scalar, prms.n_components);

CUDA_CHECK(cudaFree(cov));

Stats::meanAdd(input, mu, prms.n_cols, prms.n_rows, false);
#if 0
//===========================================EXAMPLE OF USAGE ML_EVAL_EXPRESSION_AND_CHECK START=========
ML_EVAL_EXPRESSION_AND_CHECK(mylog, cudaFree(cov));
//===========================================EXAMPLE OF USAGE END=========================================
#else
CUDA_CHECK(cudaFree(cov));
#endif
Stats::meanAdd(input, mu, prms.n_cols, prms.n_rows, false);
}

/**
Expand Down
72 changes: 42 additions & 30 deletions ml-prims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,41 +60,53 @@ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_${ptx},code=comp
include_directories(src
${GTEST_DIR}/googletest/include
${CUTLASS_DIR}
${CUB_DIR})
${CUB_DIR}
${CUDA_TOOLKIT_INCLUDE} # This include directory inplicitly available for course compiled with nvcc, but not for pure host compiler
)

add_subdirectory(${GTEST_DIR}/googletest ${PROJECT_BINARY_DIR}/googletest)

add_executable(mlcommon_test
test/add.cu
test/binary_op.cu
test/cuda_utils.cu
test/cov.cu
test/eig.cu
test/eltwise.cu
test/eltwise2d.cu
test/gemm.cu
test/kselection.cu
test/math.cu
test/matrix.cu
test/matrix_vector_op.cu
test/mean.cu
test/mean_center.cu
test/mnist.cu
test/mvg.cu
test/norm.cu
test/rng.cu
test/rsvd.cu
test/stddev.cu
test/subtract.cu
test/svd.cu
test/transpose.cu
test/unary_op.cu
test/vector_broadcast.cu)
# Alternative for find sources and headers
file(GLOB_RECURSE cpp_sources "test/*.cpp" "test/*.c")
#file(GLOB_RECURSE cu_sources "test/*.cu")

add_executable(mlcommon_test ${cu_sources} ${cpp_sources})

#add_executable(mlcommon_test
# test/add.cu
# test/binary_op.cu
# test/cuda_utils.cu
# test/cov.cu
# test/eig.cu
# test/eltwise.cu
# test/eltwise2d.cu
# test/gemm.cu
# test/kselection.cu
# test/math.cu
# test/matrix.cu
# test/matrix_vector_op.cu
# test/mean.cu
# test/mean_center.cu
# test/mnist.cu
# test/mvg.cu
# test/norm.cu
# test/rng.cu
# test/rsvd.cu
# test/stddev.cu
# test/subtract.cu
# test/svd.cu
# test/transpose.cu
# test/unary_op.cu
# test/vector_broadcast.cu
# test/base_logger_test.cpp
# test/logger_test.cpp
#)

target_link_libraries(mlcommon_test
${GTEST_LIBNAME}
cublas
curand
cusolver
${CUDA_cublas_LIBRARY}
${CUDA_curand_LIBRARY}
${CUDA_cusolver_LIBRARY}
${CUDA_CUDART_LIBRARY}
pthread
z)
53 changes: 53 additions & 0 deletions ml-prims/src/utils/info/ArchMacroses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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
* Architecture specific macroses
* Information to make I took from http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
*/

#pragma once

#if defined(__ia64) || defined(__itanium__) || defined(_M_IA64)
#define RAPIDS_ARCH_NAME "Itanium"
#define RAPIDS_ARCH_ITANIUM 1
#define RAPIDS_ARCH_LITTLE_ENDIAN 1
#define RAPIDS_ARCH_BIG_ENDIAN 0

#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
#if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(__64BIT__) || defined(_LP64) || defined(__LP64__)
#define RAPIDS_ARCH_NAME "Power pc 64"
#define RAPIDS_ARCH_POWER_PC_64 1
#else
#define RAPIDS_ARCH_NAME "Power pc 32"
#define RAPIDS_ARCH_POWER_PC_32 1
#endif
#elif defined(__sparc)
#define RAPIDS_ARCH_NAME "Sparc"
#define RAPIDS_ARCH_SPARC 1
#define RAPIDS_ARCH_LITTLE_ENDIAN 0
#define RAPIDS_ARCH_BIG_ENDIAN 1
#elif defined(__x86_64__) || defined(_M_X64)
#define RAPIDS_ARCH_NAME "AMD, Intel x86 64 bit"
#define RAPIDS_ARCH_X86_64BIT 1
#define RAPIDS_ARCH_LITTLE_ENDIAN 1
#define RAPIDS_ARCH_BIG_ENDIAN 0
#elif defined(__i386) || defined(_M_IX86)
#define RAPIDS_ARCH_NAME "AMD, Intel x86 32 bit"
#define RAPIDS_ARCH_X86_32BIT 1
#define RAPIDS_ARCH_LITTLE_ENDIAN 1
#define RAPIDS_ARCH_BIG_ENDIAN 0
#endif
68 changes: 68 additions & 0 deletions ml-prims/src/utils/info/CheckStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2018, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS 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_runtime_api.h>
#include <cublas_v2.h>

#include <string>

namespace ML
{
namespace Utils
{
template<class T>
inline bool isSuccessStatus(const T& arg);
template<class T>
inline std::string unSuccessReason(const T& arg);

//===============CUBLAS RELATIVE STATUSES START===================================================
template<>
inline bool isSuccessStatus(const cublasStatus_t& arg) {
return arg != CUBLAS_STATUS_SUCCESS;
}
template<>
inline std::string unSuccessReason(const cublasStatus_t& arg) {
switch (arg)
{
case CUBLAS_STATUS_SUCCESS : return "CUBLAS_STATUS_SUCCESS";
case CUBLAS_STATUS_NOT_INITIALIZED : return "CUBLAS_STATUS_NOT_INITIALIZED";
case CUBLAS_STATUS_ALLOC_FAILED : return "CUBLAS_STATUS_ALLOC_FAILED";
case CUBLAS_STATUS_INVALID_VALUE : return "CUBLAS_STATUS_INVALID_VALUE";
case CUBLAS_STATUS_ARCH_MISMATCH : return "CUBLAS_STATUS_ARCH_MISMATCH";
case CUBLAS_STATUS_MAPPING_ERROR : return "CUBLAS_STATUS_MAPPING_ERROR";
case CUBLAS_STATUS_EXECUTION_FAILED : return "CUBLAS_STATUS_EXECUTION_FAILED";
case CUBLAS_STATUS_INTERNAL_ERROR : return "CUBLAS_STATUS_INTERNAL_ERROR";
case CUBLAS_STATUS_NOT_SUPPORTED : return "CUBLAS_STATUS_NOT_SUPPORTED";
case CUBLAS_STATUS_LICENSE_ERROR : return "CUBLAS_STATUS_LICENSE_ERROR";
}
return "Uknown";
}
//===============CUBLAS RELATIVE STATUSES END===================================================

//===============CUDA RELATIVE STATUSES START===================================================
template<>
inline bool isSuccessStatus(const cudaError_t& arg) {
return arg != cudaSuccess;
}
template<>
inline std::string unSuccessReason(const cudaError_t& arg) {
return std::string(cudaGetErrorString(arg));
}
//===============CUDA RELATIVE STATUSES END=====================================================
}
}
63 changes: 63 additions & 0 deletions ml-prims/src/utils/info/CompilerInfoMacroses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2018, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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-specific macroses
* The most part of thiswas taken from http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
*/

#pragma once

#include "utils/info/HelpMacroses.h"

#if defined(__clang__)
#define RAPIDS_COMPILER_NAME "Clang/LLVM"
#define RAPIDS_COMPILER_VERSION_STRING_LONG __VERSION__
#define RAPIDS_COMPILER_IS_CLANG
#define RAPIDS_FUNCTION_NAME __FUNCTION__
#elif defined(__ICC) || defined(__INTEL_COMPILER)
#define RAPIDS_COMPILER_NAME "Intel ICC/ICPC"
#define RAPIDS_COMPILER_VERSION_STRING_LONG __VERSION__
#define RAPIDS_COMPILER_IS_INTEL
#define RAPIDS_FUNCTION_NAME __FUNCTION__
#elif defined(__GNUC__) || defined(__GNUG__)
#define RAPIDS_COMPILER_NAME "GNU GCC/G++"
#define RAPIDS_COMPILER_VERSION_STRING_LONG __VERSION__
#define RAPIDS_COMPILER_IS_GCC
#define RAPIDS_FUNCTION_NAME __PRETTY_FUNCTION__
#elif defined(__HP_cc) || defined(__HP_aCC)
#define RAPIDS_COMPILER_NAME "Hewlett-Packard C/aC++"
#define RAPIDS_COMPILER_VERSION_STRING_LONG RAPIDS_STRINGIZING(__HP_aCC)
#define RAPIDS_COMPILER_IS_HP
#define RAPIDS_FUNCTION_NAME __FUNCTION__
#elif defined(__IBMC__) || defined(__IBMCPP__)
#define RAPIDS_COMPILER_NAME "IBM XL C/C++"
#define RAPIDS_COMPILER_VERSION_STRING_LONG __xlc__
#define RAPIDS_COMPILER_IS_IBM
#define RAPIDS_FUNCTION_NAME __FUNCTION__
#elif defined(_MSC_VER)
#error "RAPIDS is not supported for building under Windows and any Windows platform compilers"
#elif defined(__PGI)
#define RAPIDS_COMPILER_NAME "Portland Group PGCC/PGCPP"
#define RAPIDS_COMPILER_VERSION_STRING_LONG RAPIDS_STRINGIZING(__PGIC__) "." RAPIDS_STRINGIZING(__PGIC_MINOR) "." RAPIDS_STRINGIZING(__PGIC_PATCHLEVEL__)
#define RAPIDS_COMPILER_IS_PGI
#define RAPIDS_FUNCTION_NAME __FUNCTION__
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#define RAPIDS_COMPILER_NAME "Oracle Solaris Studio"
#define RAPIDS_COMPILER_VERSION_STRING_LONG RAPIDS_STRINGIZING(__SUNPRO_CC)
#define RAPIDS_COMPILER_IS_ORACLE
#define RAPIDS_FUNCTION_NAME __FUNCTION__
#endif
27 changes: 27 additions & 0 deletions ml-prims/src/utils/info/HelpMacroses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2018, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

/** Stringizing of exprtession without evaluate it in compiler time
* @param expr expression which you would not be evaluated in compile-time and then stringinized
*/
#define RAPIDS_STRINGIZING_NO_EVAL_EXPRESSION(expr) #expr

/** Stringizing. Text which will be checked for macro expansion and arithmeitc operations during compile-time, and then stringinized
* @param expr expression which you want to evaluate in compile-time and then stringinized
*/
#define RAPIDS_STRINGIZING(expr) RAPIDS_STRINGIZING_NO_EVAL_EXPRESSION(expr)

0 comments on commit 5dc14b9

Please sign in to comment.