Skip to content

Commit

Permalink
CUDA exceptions now go with filename and line number
Browse files Browse the repository at this point in the history
  • Loading branch information
milakov committed Aug 16, 2013
1 parent 6c2dc53 commit 6b48bd8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
7 changes: 5 additions & 2 deletions nnforge/cuda/neural_network_cublas_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ namespace nnforge
{
namespace cuda
{
neural_network_cublas_exception::neural_network_cublas_exception(cublasStatus_t error_code)
: neural_network_exception((boost::format("CUBLAS error %1%") % error_code).str())
neural_network_cublas_exception::neural_network_cublas_exception(
cublasStatus_t error_code,
const char * filename,
int line_number)
: neural_network_exception((boost::format("CUBLAS error: %1%") % error_code).str(), filename, line_number)
{
}
}
Expand Down
7 changes: 5 additions & 2 deletions nnforge/cuda/neural_network_cublas_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ namespace nnforge
class neural_network_cublas_exception : public neural_network_exception
{
public:
neural_network_cublas_exception(cublasStatus_t error_code);
neural_network_cublas_exception(
cublasStatus_t error_code,
const char * filename,
int line_number);
};
}
}

#define cublas_safe_call(callstr) {cublasStatus_t error_code = callstr; if (error_code != CUBLAS_STATUS_SUCCESS) throw nnforge::cuda::neural_network_cublas_exception(error_code);}
#define cublas_safe_call(callstr) {cublasStatus_t error_code = callstr; if (error_code != CUBLAS_STATUS_SUCCESS) throw nnforge::cuda::neural_network_cublas_exception(error_code, __FILE__, __LINE__);}
7 changes: 5 additions & 2 deletions nnforge/cuda/neural_network_cuda_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ namespace nnforge
{
namespace cuda
{
neural_network_cuda_exception::neural_network_cuda_exception(cudaError_t error_code)
: neural_network_exception((boost::format("CUDA error: %1%") % cudaGetErrorString(error_code)).str())
neural_network_cuda_exception::neural_network_cuda_exception(
cudaError_t error_code,
const char * filename,
int line_number)
: neural_network_exception((boost::format("CUDA error: %1%") % cudaGetErrorString(error_code)).str(), filename, line_number)
{
}
}
Expand Down
7 changes: 5 additions & 2 deletions nnforge/cuda/neural_network_cuda_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ namespace nnforge
class neural_network_cuda_exception : public neural_network_exception
{
public:
neural_network_cuda_exception(cudaError_t error_code);
neural_network_cuda_exception(
cudaError_t error_code,
const char * filename,
int line_number);
};
}
}

#define cuda_safe_call(callstr) {cudaError_t error_code = callstr; if ((error_code != cudaSuccess) && (error_code != cudaErrorNotReady)) throw nnforge::cuda::neural_network_cuda_exception(error_code);}
#define cuda_safe_call(callstr) {cudaError_t error_code = callstr; if ((error_code != cudaSuccess) && (error_code != cudaErrorNotReady)) throw nnforge::cuda::neural_network_cuda_exception(error_code, __FILE__, __LINE__);}
10 changes: 10 additions & 0 deletions nnforge/neural_network_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "neural_network_exception.h"

#include <boost/format.hpp>

namespace nnforge
{
neural_network_exception::neural_network_exception(const char * message)
Expand All @@ -27,4 +29,12 @@ namespace nnforge
: std::runtime_error(message)
{
}

neural_network_exception::neural_network_exception(
const std::string& message,
const char * filename,
int line_number)
: std::runtime_error((boost::format("%1% in %2%:%3%") % message % filename % line_number).str())
{
}
}
6 changes: 6 additions & 0 deletions nnforge/neural_network_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ namespace nnforge
{
public:
neural_network_exception(const char * message);

neural_network_exception(const std::string& message);

neural_network_exception(
const std::string& message,
const char * filename,
int line_number);
};
}

0 comments on commit 6b48bd8

Please sign in to comment.