Skip to content

Commit

Permalink
Fixed warnings on MSVC.
Browse files Browse the repository at this point in the history
  • Loading branch information
moellenh committed Feb 16, 2016
1 parent 7a10546 commit 872ae5b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O3")
endif()

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267")
endif()

find_package(MatlabMex REQUIRED)
find_package(CUDA REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion include/prost/backend/backend_pdhg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BackendPDHG : public Backend<T>
enum StepsizeVariant
{
/// \brief Constant steps.
kPDHGStepsAlg1,
kPDHGStepsAlg1 = 1,

/// \brief Variable steps for strongly convex problems.
kPDHGStepsAlg2,
Expand Down
4 changes: 4 additions & 0 deletions include/prost/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
namespace prost {

static const size_t kBlockSizeCUDA = 256;

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // disable type-conversion loss of data warnings on windows
#endif

} // namespace prost

Expand Down
20 changes: 10 additions & 10 deletions matlab/+prost/private/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ CreateProxElemOperation1D(size_t idx, size_t size, bool diagsteps, const mxArray
{
size_t count = (size_t) mxGetScalar(mxGetCell(data, 0));
size_t dim = (size_t) mxGetScalar(mxGetCell(data, 1));
bool interleaved = (bool) mxGetScalar(mxGetCell(data, 2));
bool interleaved = mxGetScalar(mxGetCell(data, 2)) > 0;

std::array<std::vector<real>, 7> coeffs;
GetCoefficients<7>(coeffs, mxGetCell(data, 3), size);
Expand All @@ -135,7 +135,7 @@ CreateProxElemOperationNorm2(size_t idx, size_t size, bool diagsteps, const mxAr
{
size_t count = (size_t) mxGetScalar(mxGetCell(data, 0));
size_t dim = (size_t) mxGetScalar(mxGetCell(data, 1));
bool interleaved = (bool) mxGetScalar(mxGetCell(data, 2));
bool interleaved = mxGetScalar(mxGetCell(data, 2)) > 0;

std::array<std::vector<real>, 7> coeffs;
GetCoefficients<7>(coeffs, mxGetCell(data, 3), count);
Expand All @@ -149,7 +149,7 @@ CreateProxElemOperationIndSimplex(size_t idx, size_t size, bool diagsteps, const
{
size_t count = (size_t) mxGetScalar(mxGetCell(data, 0));
size_t dim = (size_t) mxGetScalar(mxGetCell(data, 1));
bool interleaved = (bool) mxGetScalar(mxGetCell(data, 2));
bool interleaved = (mxGetScalar(mxGetCell(data, 2)) > 0);

return new ProxElemOperation<real, ElemOperationIndSimplex<real> >(idx, count, dim, interleaved, diagsteps);
}
Expand All @@ -159,7 +159,7 @@ CreateProxIndEpiQuad(size_t idx, size_t size, bool diagsteps, const mxArray *dat
{
size_t count = (size_t) mxGetScalar(mxGetCell(data, 0));
size_t dim = (size_t) mxGetScalar(mxGetCell(data, 1));
bool interleaved = (bool) mxGetScalar(mxGetCell(data, 2));
bool interleaved = (mxGetScalar(mxGetCell(data, 2)) > 0);

const mxArray *coeffs = mxGetCell(data, 3);

Expand Down Expand Up @@ -217,7 +217,7 @@ CreateBlockGradient2D(size_t row, size_t col, const mxArray *pm)
size_t nx = (size_t) mxGetScalar(mxGetCell(pm, 0));
size_t ny = (size_t) mxGetScalar(mxGetCell(pm, 1));
size_t L = (size_t) mxGetScalar(mxGetCell(pm, 2));
bool label_first = (bool) mxGetScalar(mxGetCell(pm, 3));
bool label_first = mxGetScalar(mxGetCell(pm, 3)) > 0;

return new BlockGradient2D<real>(row, col, nx, ny, L, label_first);
}
Expand All @@ -228,7 +228,7 @@ CreateBlockGradient3D(size_t row, size_t col, const mxArray *pm)
size_t nx = (size_t) mxGetScalar(mxGetCell(pm, 0));
size_t ny = (size_t) mxGetScalar(mxGetCell(pm, 1));
size_t L = (size_t) mxGetScalar(mxGetCell(pm, 2));
bool label_first = (bool) mxGetScalar(mxGetCell(pm, 3));
bool label_first = mxGetScalar(mxGetCell(pm, 3)) > 0;

return new BlockGradient3D<real>(row, col, nx, ny, L, label_first);
}
Expand Down Expand Up @@ -280,9 +280,9 @@ CreateBackendPDHG(const mxArray *data)
// read options from data
opts.tau0 = (real) mxGetScalar(mxGetField(data, 0, "tau0"));
opts.sigma0 = (real) mxGetScalar(mxGetField(data, 0, "sigma0"));
opts.solve_dual_problem = (real) mxGetScalar(mxGetField(data, 0, "solve_dual"));
opts.solve_dual_problem = mxGetScalar(mxGetField(data, 0, "solve_dual")) > 0;
opts.residual_iter = (int) mxGetScalar(mxGetField(data, 0, "residual_iter"));
opts.scale_steps_operator = (bool) mxGetScalar(mxGetField(data, 0, "scale_steps_operator"));;
opts.scale_steps_operator = mxGetScalar(mxGetField(data, 0, "scale_steps_operator")) > 0;
opts.alg2_gamma = (real) mxGetScalar(mxGetField(data, 0, "alg2_gamma"));
opts.arg_alpha0 = (real) mxGetScalar(mxGetField(data, 0, "arg_alpha0"));
opts.arg_nu = (real) mxGetScalar(mxGetField(data, 0, "arg_nu"));
Expand Down Expand Up @@ -317,7 +317,7 @@ CreateProx(const mxArray *pm)

size_t idx = (size_t) mxGetScalar(mxGetCell(pm, 1));
size_t size = (size_t) mxGetScalar(mxGetCell(pm, 2));
bool diagsteps = (bool) mxGetScalar(mxGetCell(pm, 3));
bool diagsteps = mxGetScalar(mxGetCell(pm, 3)) > 0;
mxArray *data = mxGetCell(pm, 4);

Prox<real> *prox = nullptr;
Expand Down Expand Up @@ -465,7 +465,7 @@ CreateSolverOptions(const mxArray *pm)
opts.tol_abs_dual = (real) mxGetScalar(mxGetField(pm, 0, "tol_abs_dual"));
opts.max_iters = (int) mxGetScalar(mxGetField(pm, 0, "max_iters"));
opts.num_cback_calls = (int) mxGetScalar(mxGetField(pm, 0, "num_cback_calls"));
opts.verbose = (bool) mxGetScalar(mxGetField(pm, 0, "verbose"));
opts.verbose = mxGetScalar(mxGetField(pm, 0, "verbose")) > 0;

Solver_interm_cb_handle = mxGetField(pm, 0, "interm_cb");

Expand Down
2 changes: 1 addition & 1 deletion matlab/+prost/private/prost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static void EvalLinOp(MEX_ARGS) {
linop->AddBlock( std::shared_ptr<Block<real> >(CreateBlock(mxGetCell(cell_linop, i))) );

std::vector<real> rhs;
bool transpose = static_cast<bool>(mxGetScalar(prhs[2]));
bool transpose = (mxGetScalar(prhs[2]) > 0);
const mwSize *dims = mxGetDimensions(prhs[1]);

if(dims[1] != 1)
Expand Down
7 changes: 6 additions & 1 deletion matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ endif()

add_definitions(-DMATLAB_MEX_FILE)

set(CMAKE_CXX_FLAGS "-largeArrayDims")
if(MSVC)
# is largeArrayDims needed? since cuSparse cannot handle 64-bit indices anyways.
else()
set(CMAKE_CXX_FLAGS "-largeArrayDims")
endif()

if(UNIX)
set(CMAKE_SHARED_LIBRARY_SUFFIX .mexa64)
Expand Down Expand Up @@ -56,6 +60,7 @@ add_library( prost_ SHARED ${SOURCES} ${MATLAB_CUSTOM_SOURCES})
if(MSVC)
target_link_libraries( prost_ prost libmex libmx libut ${CUDA_cusparse_LIBRARY} )
set_property(TARGET prost_ PROPERTY LINK_FLAGS "/export:mexFunction")
set_property(TARGET prost_ PROPERTY _CRT_SECURE_NO_WARNINGS )
else()
target_link_libraries( prost_ prost ut cusparse )
add_dependencies( prost_ prost ) #required.
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
string(TIMESTAMP VERSION "%Y-%m-%d")

set(PROST_VERSION "0.0.1-build-${VERSION}")
set(PROST_VERSION "0.1-build-${VERSION}")
add_definitions(-DPROST_VERSION=${PROST_VERSION})

if(UNIX OR APPLE)
Expand Down
4 changes: 3 additions & 1 deletion src/backend/backend_pdhg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ BackendPDHG<T>::Initialize()
}
catch(std::bad_alloc& e)
{
throw Exception("BackendPDHG: out of memory.");
std::stringstream ss;
ss << "Out of memory: " << e.what();
throw Exception(ss.str());
}

iteration_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/linop/block_diags.cu
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ T BlockDiags<T>::row_sum(size_t row, T alpha) const
if(col < 0)
continue;

if(col >= this->ncols())
if(static_cast<size_t>(col) >= this->ncols()) // cast allowed, since col >= 0
break;

sum += std::pow(std::abs(factors_[i]), alpha);
Expand Down
7 changes: 5 additions & 2 deletions src/prox/prox_moreau.cu
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ void ProxMoreau<T>::Initialize()
{
scaled_arg_.resize(this->size_);
}
catch(std::bad_alloc &e)
catch(const std::bad_alloc &e)
{
throw Exception("Out of memory. ");
std::stringstream ss;
ss << "Out of memory: " << e.what();

throw Exception(ss.str());
}

conjugate_->Initialize();
Expand Down
6 changes: 4 additions & 2 deletions src/prox/prox_transform.cu
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ void ProxTransform<T>::Initialize()
scaled_arg_.resize(this->size_);
scaled_tau_.resize(this->size_);
}
catch(std::bad_alloc &e)
catch(const std::bad_alloc &e)
{
throw Exception("Out of memory. ");
std::stringstream ss;
ss << "Out of memory: " << e.what();
throw Exception(ss.str());
}

inner_fn_->Initialize();
Expand Down
22 changes: 13 additions & 9 deletions src/solver.cu
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ void Solver<T>::Initialize() {
backend_->SetOptions(opts_);
backend_->Initialize();

if (opts_.verbose) {
size_t mem = problem_->gpu_mem_amount() + backend_->gpu_mem_amount();
size_t mem_avail, mem_total;
cudaMemGetInfo(&mem_avail, &mem_total);
mem_avail /= 1024 * 1024;
mem_total /= 1024 * 1024;

std::cout << "Initialized solver successfully. Problem dimension:" << std::endl;
std::cout << "# primal variables: " << problem_->ncols() << std::endl;
std::cout << "# dual variables: " << problem_->nrows() << std::endl;
std::cout << "Memory requirements: " << mem / (1024 * 1024) << "MB (" << mem_avail << "/" << mem_total << "MB available)." << std::endl;
}

cur_primal_sol_.resize( problem_->ncols() );
cur_dual_sol_.resize( problem_->nrows() );

if(opts_.verbose) {
size_t mem = problem_->gpu_mem_amount() + backend_->gpu_mem_amount();

std::cout << "Initialized solver successfully. Problem dimension:" << std::endl;
std::cout << "# primal variables: " << problem_->ncols() << std::endl;
std::cout << "# dual variables: " << problem_->nrows() << std::endl;
std::cout << "Memory requirements: " << mem / (1024 * 1024) << "MB." << std::endl;
}
}

template<typename T>
Expand Down

0 comments on commit 872ae5b

Please sign in to comment.