From b34c611802eedaed8bdf86dff0bdab7f544e7de3 Mon Sep 17 00:00:00 2001 From: "U-AMR\\ptillet" Date: Thu, 13 Aug 2015 15:44:58 -0700 Subject: [PATCH] Code quality: Added consistency between int_t and size_t. Fixed warnings for Win64 --- include/isaac/driver/buffer.h | 2 +- include/isaac/kernels/mapped_object.h | 8 ++--- .../isaac/profiles/predictors/random_forest.h | 6 ++-- lib/array.cpp | 2 +- lib/driver/buffer.cpp | 2 +- lib/driver/helpers/ocl/infos.hpp | 2 +- lib/driver/kernel.cpp | 4 +-- lib/driver/program.cpp | 6 ++-- lib/external/rapidjson/to_array.hpp | 4 +-- lib/kernels/mapped_object.cpp | 4 +-- lib/kernels/templates/tools/arguments.hpp | 2 +- lib/kernels/templates/tools/map.hpp | 6 ++-- lib/profiles/predictors/random_forest.cpp | 6 ++-- lib/wrap/clBLAS.cpp | 30 +++++++++---------- tests/linalg/common.hpp | 2 +- tests/linalg/dot.cpp | 4 +-- tests/linalg/gemv.cpp | 8 ++--- 17 files changed, 49 insertions(+), 49 deletions(-) diff --git a/include/isaac/driver/buffer.h b/include/isaac/driver/buffer.h index 4820890c9..26c5915f4 100644 --- a/include/isaac/driver/buffer.h +++ b/include/isaac/driver/buffer.h @@ -20,7 +20,7 @@ class ISAACAPI Buffer friend class Kernel; public: Buffer(cl_mem Buffer, bool take_ownership = true); - Buffer(Context const & context, int_t size); + Buffer(Context const & context, size_t size); Context const & context() const; bool operator<(Buffer const &) const; bool operator==(Buffer const &) const; diff --git a/include/isaac/kernels/mapped_object.h b/include/isaac/kernels/mapped_object.h index 79cf0de48..db05af182 100644 --- a/include/isaac/kernels/mapped_object.h +++ b/include/isaac/kernels/mapped_object.h @@ -19,7 +19,7 @@ enum leaf_t class mapped_object; -typedef std::pair mapping_key; +typedef std::pair mapping_key; typedef std::map > mapping_type; /** @brief Mapped Object @@ -46,10 +46,10 @@ protected: public: struct node_info { - node_info(mapping_type const * _mapping, array_expression const * _array_expression, int_t _root_idx); + node_info(mapping_type const * _mapping, array_expression const * _array_expression, size_t _root_idx); mapping_type const * mapping; isaac::array_expression const * array_expression; - int_t root_idx; + size_t root_idx; }; public: @@ -99,7 +99,7 @@ class mapped_dot : public mapped_object, public binary_leaf public: mapped_dot(std::string const & scalartype, unsigned int id, node_info info, std::string const & type_key); - int_t root_idx() const; + size_t root_idx() const; isaac::array_expression const & array_expression() const; array_expression::node root_node() const; bool is_index_dot() const; diff --git a/include/isaac/profiles/predictors/random_forest.h b/include/isaac/profiles/predictors/random_forest.h index 2002d1208..728cd6bca 100644 --- a/include/isaac/profiles/predictors/random_forest.h +++ b/include/isaac/profiles/predictors/random_forest.h @@ -23,14 +23,14 @@ public: public: tree(rapidjson::Value const & treerep); std::vector const & predict(std::vector const & x) const; - int_t D() const; + size_t D() const; private: std::vector children_left_; std::vector children_right_; std::vector threshold_; std::vector feature_; std::vector > value_; - int_t D_; + size_t D_; }; random_forest(rapidjson::Value const & estimators); @@ -38,7 +38,7 @@ public: std::vector const & estimators() const; private: std::vector estimators_; - int_t D_; + size_t D_; }; } diff --git a/lib/array.cpp b/lib/array.cpp index 79b135b15..6ae432eb1 100644 --- a/lib/array.cpp +++ b/lib/array.cpp @@ -31,7 +31,7 @@ array::array(int_t shape0, numeric_type dtype, driver::Buffer data, int_t start, template array::array(std::vector
const & x, driver::Context const & context): - dtype_(to_numeric_type
::value), shape_(x.size(), 1), start_(0, 0, 0, 0), stride_(1, 1, 1, 1), ld_(shape_[0]), + dtype_(to_numeric_type
::value), shape_((int_t)x.size(), 1), start_(0, 0, 0, 0), stride_(1, 1, 1, 1), ld_(shape_[0]), context_(context), data_(context, size_of(dtype_)*dsize()) { *this = x; } diff --git a/lib/driver/buffer.cpp b/lib/driver/buffer.cpp index 29150437b..f04c58829 100644 --- a/lib/driver/buffer.cpp +++ b/lib/driver/buffer.cpp @@ -14,7 +14,7 @@ Buffer::Buffer(cl_mem buffer, bool take_ownership) : backend_(OPENCL), context_( h_.cl() = buffer; } -Buffer::Buffer(Context const & context, int_t size) : backend_(context.backend_), context_(context), h_(backend_, true) +Buffer::Buffer(Context const & context, size_t size) : backend_(context.backend_), context_(context), h_(backend_, true) { switch(backend_) { diff --git a/lib/driver/helpers/ocl/infos.hpp b/lib/driver/helpers/ocl/infos.hpp index b4d97948e..e2aa8d08c 100644 --- a/lib/driver/helpers/ocl/infos.hpp +++ b/lib/driver/helpers/ocl/infos.hpp @@ -341,7 +341,7 @@ inline typename detail::return_type::Result inf { std::vector res; std::vector sizes = info(handle); - for(unsigned int s: sizes) + for(size_t s: sizes) res.push_back(new unsigned char[s]); clGetProgramInfo(handle, CL_PROGRAM_BINARIES, sizeof(unsigned char**), (void*)res.data(), NULL); return res; diff --git a/lib/driver/kernel.cpp b/lib/driver/kernel.cpp index 869d16457..5ae75a1be 100644 --- a/lib/driver/kernel.cpp +++ b/lib/driver/kernel.cpp @@ -77,14 +77,14 @@ void Kernel::setSizeArg(unsigned int index, size_t N) #ifdef ISAAC_WITH_CUDA case CUDA: { - int NN = N; + int NN = static_cast(N); setArg(index, sizeof(int), &NN); break; } #endif case OPENCL: { - cl_int NN = N; + cl_int NN = static_cast(N); setArg(index, 4, &NN); break; } diff --git a/lib/driver/program.cpp b/lib/driver/program.cpp index ff0908a58..abbb6664e 100644 --- a/lib/driver/program.cpp +++ b/lib/driver/program.cpp @@ -118,9 +118,9 @@ Program::Program(Context const & context, std::string const & source) : backend_ buffer.resize(len); cached.read((char*)buffer.data(), std::streamsize(len)); char* cbuffer = buffer.data(); - h_.cl() = clCreateProgramWithBinary(context_.h_.cl(), devices.size(), devices.data(), &len, (const unsigned char **)&cbuffer, NULL, &err); + h_.cl() = clCreateProgramWithBinary(context_.h_.cl(), static_cast(devices.size()), devices.data(), &len, (const unsigned char **)&cbuffer, NULL, &err); ocl::check(err); - ocl::check(clBuildProgram(h_.cl(), devices.size(), devices.data(), build_opt.c_str(), NULL, NULL)); + ocl::check(clBuildProgram(h_.cl(), static_cast(devices.size()), devices.data(), build_opt.c_str(), NULL, NULL)); return; } } @@ -129,7 +129,7 @@ Program::Program(Context const & context, std::string const & source) : backend_ const char * csrc = source.c_str(); h_.cl() = clCreateProgramWithSource(context_.h_.cl(), 1, &csrc, &srclen, &err); try{ - ocl::check(clBuildProgram(h_.cl(), devices.size(), devices.data(), build_opt.c_str(), NULL, NULL)); + ocl::check(clBuildProgram(h_.cl(), static_cast(devices.size()), devices.data(), build_opt.c_str(), NULL, NULL)); }catch(ocl::exception::build_program_failure const &){ for(std::vector::const_iterator it = devices.begin(); it != devices.end(); ++it) { diff --git a/lib/external/rapidjson/to_array.hpp b/lib/external/rapidjson/to_array.hpp index 0130ef222..00ebd00b0 100644 --- a/lib/external/rapidjson/to_array.hpp +++ b/lib/external/rapidjson/to_array.hpp @@ -12,7 +12,7 @@ std::vector to_int_array(rapidjson::Value const & a) { size_t N = a.Size(); std::vector res(N); - for(size_t i = 0 ; i < N ; ++i) res[i] = a[i].GetInt(); + for(rapidjson::SizeType i = 0 ; i < N ; ++i) res[i] = a[i].GetInt(); return res; } @@ -21,7 +21,7 @@ std::vector to_float_array(rapidjson::Value const & a) { size_t N = a.Size(); std::vector res(N); - for(size_t i = 0 ; i < N ; ++i) res[i] = a[i].GetDouble(); + for(rapidjson::SizeType i = 0 ; i < N ; ++i) res[i] = a[i].GetDouble(); return res; } diff --git a/lib/kernels/mapped_object.cpp b/lib/kernels/mapped_object.cpp index a76322a02..4d08f3b20 100644 --- a/lib/kernels/mapped_object.cpp +++ b/lib/kernels/mapped_object.cpp @@ -51,7 +51,7 @@ void mapped_object::register_attribute(std::string & attribute, std::string cons keywords_[key] = attribute; } -mapped_object::node_info::node_info(mapping_type const * _mapping, isaac::array_expression const * _array_expression, int_t _root_idx) : +mapped_object::node_info::node_info(mapping_type const * _mapping, isaac::array_expression const * _array_expression, size_t _root_idx) : mapping(_mapping), array_expression(_array_expression), root_idx(_root_idx) { } mapped_object::mapped_object(std::string const & scalartype, unsigned int id, std::string const & type_key) : type_key_(type_key) @@ -111,7 +111,7 @@ mapped_dot::mapped_dot(std::string const & scalartype, unsigned int id, node_inf mapped_object(scalartype, id, type_key), binary_leaf(info) { } -int_t mapped_dot::root_idx() const +size_t mapped_dot::root_idx() const { return info_.root_idx; } isaac::array_expression const & mapped_dot::array_expression() const diff --git a/lib/kernels/templates/tools/arguments.hpp b/lib/kernels/templates/tools/arguments.hpp index cac1a588d..a06a506db 100644 --- a/lib/kernels/templates/tools/arguments.hpp +++ b/lib/kernels/templates/tools/arguments.hpp @@ -108,7 +108,7 @@ public: } } - void operator()(isaac::array_expression const & array_expression, int_t root_idx, leaf_t leaf_t) const + void operator()(isaac::array_expression const & array_expression, size_t root_idx, leaf_t leaf_t) const { array_expression::node const & root_node = array_expression.tree()[root_idx]; if (leaf_t==LHS_NODE_TYPE && root_node.lhs.type_family != COMPOSITE_OPERATOR_FAMILY) diff --git a/lib/kernels/templates/tools/map.hpp b/lib/kernels/templates/tools/map.hpp index 4fa3a7717..130ac99b0 100644 --- a/lib/kernels/templates/tools/map.hpp +++ b/lib/kernels/templates/tools/map.hpp @@ -12,7 +12,7 @@ namespace templates class map_functor : public traversal_functor { - numeric_type get_numeric_type(isaac::array_expression const * array_expression, int_t root_idx) const + numeric_type get_numeric_type(isaac::array_expression const * array_expression, size_t root_idx) const { array_expression::node const * root_node = &array_expression->tree()[root_idx]; while (root_node->lhs.dtype==INVALID_NUMERIC_TYPE) @@ -21,7 +21,7 @@ class map_functor : public traversal_functor } template - std::shared_ptr binary_leaf(isaac::array_expression const * array_expression, int_t root_idx, mapping_type const * mapping) const + std::shared_ptr binary_leaf(isaac::array_expression const * array_expression, size_t root_idx, mapping_type const * mapping) const { return std::shared_ptr(new T(to_string(array_expression->dtype()), binder_.get(), mapped_object::node_info(mapping, array_expression, root_idx))); } @@ -74,7 +74,7 @@ public: { } - void operator()(isaac::array_expression const & array_expression, int_t root_idx, leaf_t leaf_t) const + void operator()(isaac::array_expression const & array_expression, size_t root_idx, leaf_t leaf_t) const { { mapping_type::key_type key(root_idx, leaf_t); diff --git a/lib/profiles/predictors/random_forest.cpp b/lib/profiles/predictors/random_forest.cpp index 56d669b92..b7ea52539 100644 --- a/lib/profiles/predictors/random_forest.cpp +++ b/lib/profiles/predictors/random_forest.cpp @@ -27,7 +27,7 @@ std::vector const & random_forest::tree::predict(std::vector const return value_[idx]; } -int_t random_forest::tree::D() const { return D_; } +size_t random_forest::tree::D() const { return D_; } random_forest::random_forest(rapidjson::Value const & estimators) { @@ -42,10 +42,10 @@ std::vector random_forest::predict(std::vector const & x) const for(const auto & elem : estimators_) { std::vector const & subres = elem.predict(x); - for(int_t i = 0 ; i < D_ ; ++i) + for(size_t i = 0 ; i < D_ ; ++i) res[i] += subres[i]; } - for(int_t i = 0 ; i < D_ ; ++i) + for(size_t i = 0 ; i < D_ ; ++i) res[i] /= estimators_.size(); return res; } diff --git a/lib/wrap/clBLAS.cpp b/lib/wrap/clBLAS.cpp index 40f551b58..e669893e1 100644 --- a/lib/wrap/clBLAS.cpp +++ b/lib/wrap/clBLAS.cpp @@ -53,8 +53,8 @@ extern "C" cl_uint numEventsInWaitList, const cl_event *eventWaitList, \ cl_event *events) \ { \ - is::array x(N, TYPE_ISAAC, is::driver::Buffer(mx,false), (is::int_t)offx, incx); \ - is::array y(N, TYPE_ISAAC, is::driver::Buffer(my,false), (is::int_t)offy, incy); \ + is::array x((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mx,false), (is::int_t)offx, incx); \ + is::array y((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(my,false), (is::int_t)offy, incy); \ execute(is::assign(y, alpha*x + y), y.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events); \ return clblasSuccess; \ } @@ -69,7 +69,7 @@ extern "C" cl_uint numCommandQueues, cl_command_queue *commandQueues,\ cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\ {\ - is::array x(N, TYPE_ISAAC, is::driver::Buffer(mx,false), (is::int_t)offx, incx);\ + is::array x((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mx,false), (is::int_t)offx, incx);\ execute(is::assign(x, alpha*x), x.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\ return clblasSuccess;\ } @@ -85,8 +85,8 @@ extern "C" cl_uint numCommandQueues, cl_command_queue *commandQueues,\ cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\ {\ - const is::array x(N, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx);\ - is::array y(N, TYPE_ISAAC, is::driver::Buffer(my, false), (is::int_t)offy, incy);\ + const is::array x((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx);\ + is::array y((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(my, false), (is::int_t)offy, incy);\ execute(is::assign(y, x), y.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\ return clblasSuccess;\ } @@ -103,8 +103,8 @@ extern "C" cl_command_queue *commandQueues, cl_uint numEventsInWaitList, \ const cl_event *eventWaitList, cl_event *events) \ { \ - is::array x(N, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx); \ - is::array y(N, TYPE_ISAAC, is::driver::Buffer(my, false), (is::int_t)offy, incy); \ + is::array x((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx); \ + is::array y((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(my, false), (is::int_t)offy, incy); \ is::scalar s(TYPE_ISAAC, is::driver::Buffer(dotProduct, false), (is::int_t)offDP); \ execute(is::assign(s, dot(x,y)), s.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events); \ return clblasSuccess; \ @@ -120,7 +120,7 @@ extern "C" cl_mem /*scratchBuff*/, cl_uint numCommandQueues, cl_command_queue *commandQueues,\ cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\ {\ - is::array x(N, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx);\ + is::array x((is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx);\ is::scalar s(TYPE_ISAAC, is::driver::Buffer(asum, false), (is::int_t)offAsum);\ execute(is::assign(s, sum(abs(x))), s.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\ return clblasSuccess;\ @@ -145,9 +145,9 @@ extern "C" std::swap(M, N);\ transA = (transA==clblasTrans)?clblasNoTrans:clblasTrans;\ }\ - is::array A(M, N, TYPE_ISAAC, is::driver::Buffer(mA, false), (is::int_t)offA, lda);\ + is::array A((is::int_t)M, (is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mA, false), (is::int_t)offA, (is::int_t)lda);\ \ - is::int_t sx = N, sy = M;\ + is::int_t sx = (is::int_t)N, sy = (is::int_t)M;\ if(transA) std::swap(sx, sy);\ is::array x(sx, TYPE_ISAAC, is::driver::Buffer(mx, false), (is::int_t)offx, incx);\ is::array y(sy, TYPE_ISAAC, is::driver::Buffer(my, false), (is::int_t)offy, incy);\ @@ -186,14 +186,14 @@ extern "C" std::swap(M, N);\ std::swap(transA, transB);\ }\ - is::int_t As1 = M, As2 = K;\ - is::int_t Bs1 = K, Bs2 = N;\ + is::int_t As1 = (is::int_t)M, As2 = (is::int_t)K;\ + is::int_t Bs1 = (is::int_t)K, Bs2 = (is::int_t)N;\ if(transA==clblasTrans) std::swap(As1, As2);\ if(transB==clblasTrans) std::swap(Bs1, Bs2);\ /*Struct*/\ - is::array A(As1, As2, TYPE_ISAAC, is::driver::Buffer(mA, false), (is::int_t)offA, lda);\ - is::array B(Bs1, Bs2, TYPE_ISAAC, is::driver::Buffer(mB, false), (is::int_t)offB, ldb);\ - is::array C(M, N, TYPE_ISAAC, is::driver::Buffer(mC, false), (is::int_t)offC, ldc);\ + is::array A(As1, As2, TYPE_ISAAC, is::driver::Buffer(mA, false), (is::int_t)offA, (is::int_t)lda);\ + is::array B(Bs1, Bs2, TYPE_ISAAC, is::driver::Buffer(mB, false), (is::int_t)offB, (is::int_t)ldb);\ + is::array C((is::int_t)M, (is::int_t)N, TYPE_ISAAC, is::driver::Buffer(mC, false), (is::int_t)offC, (is::int_t)ldc);\ is::driver::Context const & context = C.context();\ /*Operation*/\ if((transA==clblasTrans) && (transB==clblasTrans))\ diff --git a/tests/linalg/common.hpp b/tests/linalg/common.hpp index f3142c118..25495ef10 100644 --- a/tests/linalg/common.hpp +++ b/tests/linalg/common.hpp @@ -51,7 +51,7 @@ template class simple_vector : public simple_vector_base { public: - simple_vector(size_t N) : simple_vector_base(0, N, 1, data_), data_(N){} + simple_vector(int_t N) : simple_vector_base(0, N, 1, data_), data_(N){} private: std::vector data_; }; diff --git a/tests/linalg/dot.cpp b/tests/linalg/dot.cpp index 14aac12fc..94236564f 100644 --- a/tests/linalg/dot.cpp +++ b/tests/linalg/dot.cpp @@ -57,8 +57,8 @@ void test_reduction(T epsilon, simple_vector_base & cx, simple_vector_base::min(), cs, ds = max(x)); + RUN_TEST("s = min(x)", cs = std::min(cs, cx[i]), std::numeric_limits::max(), cs, ds = min(x)); #undef RUN_TEST diff --git a/tests/linalg/gemv.cpp b/tests/linalg/gemv.cpp index b2db96351..ce081f03c 100644 --- a/tests/linalg/gemv.cpp +++ b/tests/linalg/gemv.cpp @@ -76,13 +76,13 @@ void test_row_wise_reduction(T epsilon, simple_vector_base & cy, simple_matri { TEST_OPERATION("x = dot(A.T, y)", N, M, 0, xi+=cA(j,i)*cy[j], cx[i] = xi, x = dot(trans(A),y), x, bufx, cx); TEST_OPERATION("x = sum(A, 0)", N, M, 0, xi+=cA(j,i), cx[i] = xi, x = sum(A,0), x, bufx, cx); - TEST_OPERATION("x = max(A, 0)", N, M, -INFINITY, xi=std::max(xi,cA(j,i)), cx[i] = xi, x = max(A,0), x, bufx, cx); - TEST_OPERATION("x = min(A, 0)", N, M, INFINITY, xi=std::min(xi,cA(j,i)), cx[i] = xi, x = min(A,0), x, bufx, cx); + TEST_OPERATION("x = max(A, 0)", N, M, std::numeric_limits::min(), xi=std::max(xi,cA(j,i)), cx[i] = xi, x = max(A,0), x, bufx, cx); + TEST_OPERATION("x = min(A, 0)", N, M, std::numeric_limits::max(), xi=std::min(xi,cA(j,i)), cx[i] = xi, x = min(A,0), x, bufx, cx); TEST_OPERATION("y = dot(A, x)", M, N, 0, yi+=cA(i,j)*cx[j], cy[i] = yi, y = dot(A,x), y, bufy, cy); TEST_OPERATION("y = sum(A, 1)", M, N, 0, yi+=cA(i,j), cy[i] = yi, y = sum(A,1), y, bufy, cy); - TEST_OPERATION("y = max(A, 1)", M, N, -INFINITY, yi=std::max(yi,cA(i,j)), cy[i] = yi, y = max(A,1), y, bufy, cy); - TEST_OPERATION("y = min(A, 1)", M, N, INFINITY, yi=std::min(yi,cA(i,j)), cy[i] = yi, y = min(A,1), y, bufy, cy); + TEST_OPERATION("y = max(A, 1)", M, N, std::numeric_limits::min(), yi=std::max(yi,cA(i,j)), cy[i] = yi, y = max(A,1), y, bufy, cy); + TEST_OPERATION("y = min(A, 1)", M, N, std::numeric_limits::max(), yi=std::min(yi,cA(i,j)), cy[i] = yi, y = min(A,1), y, bufy, cy); } if(failure_count>0)