Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 22e23f1

Browse files
cjolivier01tqchen
authored andcommittedApr 4, 2017
Fix link error for newer gcc versions, Minor CMake adjustments (#226)
* Fix warnings, build adjustments in CMake * fix cuda variable-declaration order problems * Remove gpu flavors below 30, no longer compatible * fix cuda variable-declaration order problems * Add nvcc --run cuda library path flag for when detecting gpu flavor * Allow CUDA_LIBRARY_PATH to not be defined * Minor visibility adjustments * Remove more warnings * use static_cast instead of () * Fix warnings * Fix link error, undefined kSize * Size() for kPlain packet * fix: Ignored test directory * Fix lint, re-apply kSize fix
1 parent 23210f3 commit 22e23f1

14 files changed

+49
-36
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*~
1515
doc/html
1616
doc/latex
17-
test*
1817
rabit
1918
dmlc-core
2019
*.db

‎cmake/Cuda.cmake

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,23 @@ set(CUDA_gpu_detect_output "")
3131
"}\n")
3232
if(MSVC)
3333
#find vcvarsall.bat and run it building msvc environment
34-
get_filename_component(MY_COMPILER_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
35-
find_file(MY_VCVARSALL_BAT vcvarsall.bat "${MY_COMPILER_DIR}/.." "${MY_COMPILER_DIR}/../..")
34+
get_filename_component(MY_COMPILER_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
35+
find_file(MY_VCVARSALL_BAT vcvarsall.bat "${MY_COMPILER_DIR}/.." "${MY_COMPILER_DIR}/../..")
3636
execute_process(COMMAND ${MY_VCVARSALL_BAT} && ${CUDA_NVCC_EXECUTABLE} -arch sm_30 --run ${__cufile}
3737
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/"
3838
RESULT_VARIABLE __nvcc_res OUTPUT_VARIABLE __nvcc_out
3939
ERROR_QUIET
4040
OUTPUT_STRIP_TRAILING_WHITESPACE)
4141
else()
42-
execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} -arch sm_30 --run ${__cufile}
42+
if(CUDA_LIBRARY_PATH)
43+
set(CUDA_LINK_LIBRARY_PATH "-L${CUDA_LIBRARY_PATH}")
44+
endif()
45+
execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} -arch sm_30 --run ${__cufile} ${CUDA_LINK_LIBRARY_PATH}
4346
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/"
4447
RESULT_VARIABLE __nvcc_res OUTPUT_VARIABLE __nvcc_out
4548
ERROR_QUIET
4649
OUTPUT_STRIP_TRAILING_WHITESPACE)
4750
endif()
48-
4951
if(__nvcc_res EQUAL 0)
5052
# nvcc outputs text containing line breaks when building with MSVC.
5153
# The line below prevents CMake from inserting a variable with line

‎cmake/mshadow.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ set(mshadow_LINKER_LIBS "")
33
set(BLAS "Open" CACHE STRING "Selected BLAS library")
44
set_property(CACHE BLAS PROPERTY STRINGS "Atlas;Open;MKL")
55

6+
if(USE_MKL_IF_AVAILABLE)
7+
if(NOT MKL_FOUND)
8+
find_package(MKL)
9+
endif()
10+
if(MKL_FOUND)
11+
set(BLAS "MKL")
12+
endif()
13+
endif()
14+
615
if(BLAS STREQUAL "Atlas" OR BLAS STREQUAL "atlas")
716
find_package(Atlas REQUIRED)
817
include_directories(SYSTEM ${Atlas_INCLUDE_DIR})

‎mshadow/expression.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ namespace expr {
2020
namespace type {
2121
// type expression type are defined as bitmask
2222
// subtype relationshop kRValue < kMapper < kPull < kComplex
23-
/*!
23+
/*!
2424
* \brief this expression directly correspnds to a data class,
25-
* can be used to assign data
25+
* can be used to assign data
2626
*/
2727
const int kRValue = 0;
28-
/*!
28+
/*!
2929
* \brief expression contains element-wise tensor operations,
30-
* map a expression to same shape
30+
* map a expression to same shape
3131
*/
3232
const int kMapper = 1;
3333
/*!
@@ -70,7 +70,7 @@ struct Exp {
7070
}
7171
};
7272
/*!
73-
* \brief scalar expression
73+
* \brief scalar expression
7474
* \tparam DType the data type of the scalar
7575
*/
7676
template<typename DType>
@@ -280,12 +280,12 @@ MakeExp(const Exp<TA, DType, ta> &item1, const Exp<TB, DType, tb> &item2,
280280
(ta|tb|tc|type::kMapper)>(item1.self(), item2.self(), item3.self());
281281
}
282282
/*!
283-
* \brief short hand for MakeExp, usage F<op>(item1,item2,item3). create a ternary operation expression
283+
* \brief short hand for MakeExp, usage F<op>(item1,item2,item3). create a ternary operation expression
284284
* \param item1 first operand
285285
* \param item2 second operand
286286
* \param item3 third operand
287287
* \return the result expression
288-
* \tparam ternary operator
288+
* \tparam ternary operator
289289
* \tparam TA item1 expression
290290
* \tparam ta item1 expression type
291291
* \tparam TB item2 expression
@@ -332,11 +332,11 @@ MakeExp(const Exp<TA, DType, ta> &lhs, const Exp<TB, DType, tb> &rhs) {
332332
(ta|tb|type::kMapper)>(lhs.self(), rhs.self());
333333
}
334334
/*!
335-
* \brief short hand for MakeExp, usage F<op>(lhs, rhs). create a binary operation expression
335+
* \brief short hand for MakeExp, usage F<op>(lhs, rhs). create a binary operation expression
336336
* \param lhs left operand
337337
* \param rhs right operand
338338
* \return the result expression
339-
* \tparam binary operator
339+
* \tparam binary operator
340340
* \tparam TA lhs expression
341341
* \tparam ta lhs expression type
342342
* \tparam TB rhs expression
@@ -397,11 +397,11 @@ inline UnaryMapExp<OP, TA, DType, (ta|type::kMapper)>
397397
MakeExp(const Exp<TA, DType, ta> &src) {
398398
return UnaryMapExp<OP, TA, DType, (ta|type::kMapper)>(src.self());
399399
}
400-
/*!
401-
* \brief short hand for MakeExp, usage F<op>(src), create a unary operation expression
400+
/*!
401+
* \brief short hand for MakeExp, usage F<op>(src), create a unary operation expression
402402
* \param src source expression
403403
* \return the result expression
404-
* \tparam operator
404+
* \tparam operator
405405
* \tparam TA source expression
406406
* \tparam ta source expression type
407407
* \sa mshadow::op

‎mshadow/extension/broadcast_with_axis.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct BroadcastWithAxisExp:
5555
} else {
5656
CHECK(dimdst > axis && axis >= 0) << "broadcast axis (keepdim) out of bound, " <<
5757
"axis must be between 0 and" << dimdst - 1 << ", given=" << axis << ".";
58-
CHECK_EQ(src_shape[axis], 1) << "Size of the dimension of the broadcasting axis must be 1" <<
58+
CHECK_EQ(src_shape[axis], 1U) << "Size of the dimension of the broadcasting axis must be 1" <<
5959
" when keepdim is on, src_shape[" << axis << "]=" << src_shape[axis] << ".";
6060
for (int i = 0; i <= axis - 1; ++i) {
6161
this->shape_[i] = src_shape[i];
@@ -137,7 +137,7 @@ struct BroadcastWithMultiAxesExp :
137137
CHECK(dimsrc > axes[i]) << "broadcast axis (keepdim) out of bound, " <<
138138
"all axes must be between 0 and" << dimsrc - 1 << ", given axes[" << i << "] = " << axes[i]
139139
<< ".";
140-
CHECK_EQ(src_shape[axes[i]], 1) << "Size of the dimension of the broadcasting axis must be 1"
140+
CHECK_EQ(src_shape[axes[i]], 1U) << "Size of the dimension of the broadcasting axis must be 1"
141141
<< ", src_shape[" << axes[i] << "]=" << src_shape[axes[i]] << ".";
142142
if (i < this->axesnum_ - 1) {
143143
CHECK(axes[i] < axes[i + 1]) << "The given axes must be in increasing order.";

‎mshadow/extension/channel_pool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ inline ChannelPoolingExp<Reducer, SrcExp, DType, ExpInfo<SrcExp>::kDim>
5757
chpool(const Exp<SrcExp, DType, etype> &src, index_t nsize) {
5858
TypeCheckPass<ExpInfo<SrcExp>::kDim >= 3>
5959
::Error_Expression_Does_Not_Meet_Dimension_Req();
60-
CHECK_EQ(nsize % 2, 1) << "chpool: if no pad is specified, local size must be odd";
60+
CHECK_EQ(nsize % 2, 1U) << "chpool: if no pad is specified, local size must be odd";
6161
return ChannelPoolingExp<Reducer, SrcExp,
6262
DType, ExpInfo<SrcExp>::kDim>(src.self(), nsize, 1, nsize / 2);
6363
}

‎mshadow/extension/implicit_gemm.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ struct Plan<ImplicitGEMMExp<LhsExp, RhsExp, DType>, DType> {
6767
typedef packet::Packet<DType> Packet;
6868
Packet sum = Packet::Fill(0);
6969

70-
DType lhs_temp[Packet::kSize], rhs_temp[Packet::kSize];
70+
const size_t packetSize = Packet::Size();
71+
DType lhs_temp[packetSize], rhs_temp[packetSize];
7172

72-
for (index_t i = 0; i < prod_size_lower_align_; i += packet::Packet<DType>::kSize) {
73+
for (index_t i = 0; i < prod_size_lower_align_; i += packetSize) {
7374
// unroll
74-
for (index_t j = 0; j < Packet::kSize; ++j) {
75+
for (index_t j = 0; j < packetSize; ++j) {
7576
lhs_temp[j] = lhs_.Eval(y, i + j);
7677
}
77-
for (index_t j = 0; j < Packet::kSize; ++j) {
78+
for (index_t j = 0; j < packetSize; ++j) {
7879
rhs_temp[j] = rhs_.Eval(i + j, x);
7980
}
8081
sum = sum + Packet::LoadUnAligned(lhs_temp) * Packet::LoadUnAligned(rhs_temp);

‎mshadow/extension/transpose.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ namespace expr {
1616
* output: Tensor<Device,dimdst> oshape[a1],oshape[a2] = ishape[a2],oshape[a1]
1717
*
1818
* \tparam SrcExp type of source expression
19-
* \tparam DType the type of elements
19+
* \tparam DType the type of elements
2020
* \tparam dimsrc source dimension, assert a1 > a2
21-
* \tparam m_a1 one dimension to be swapped, encoded by dimsrc - a1
21+
* \tparam m_a1 one dimension to be swapped, encoded by dimsrc - a1
2222
* \tparam a2 second dimension to be swapped, encoded by a2
2323
*/
2424
template<typename SrcExp, typename DType, int dimsrc>
@@ -50,7 +50,7 @@ struct TransposeExExp:
5050
* \tparam a1 higher dimension to be swapped, assert a1 > a2
5151
* \tparam a2 lower dimension to be swapped
5252
* \tparam SrcExp source expression
53-
* \tparam DType the type of elements
53+
* \tparam DType the type of elements
5454
* \tparam etype source expression type
5555
*/
5656
template<typename SrcExp, typename DType, int etype>
@@ -110,7 +110,7 @@ struct TransposeIndicesExp:
110110
Shape<dimsrc> dst_stride_;
111111
bool axes_checking_flag[dimsrc] = { 0 };
112112
for (int i = 0; i < dimsrc; ++i) {
113-
CHECK_LT(axes[i], dimsrc)
113+
CHECK_LT(static_cast<int>(axes[i]), dimsrc)
114114
<< "Invalid axes input! All elements of axes must be between 0 and " << dimsrc
115115
<< ", find axes=" << axes;
116116
dst_shape_[i] = src_shape[axes[i]];

‎mshadow/packet-inl.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class PacketPlan {
214214
public:
215215
/*!
216216
* \brief evaluate the expression at index [y][x],
217-
* x will be aligned to Packet<DType, Arch>::kSize
217+
* x will be aligned to Packet<DType, Arch>::Size()
218218
*/
219219
MSHADOW_CINLINE packet::Packet<DType, Arch> EvalPacket(index_t y, index_t x) const;
220220
MSHADOW_CINLINE DType Eval(index_t y, index_t x) const;
@@ -395,11 +395,12 @@ inline void MapPacketPlan(Tensor<cpu, dim, DType> _dst,
395395
const expr::PacketPlan<E, DType, Arch>& plan) {
396396
Tensor<cpu, 2, DType> dst = _dst.FlatTo2D();
397397
const index_t xlen = packet::LowerAlign<DType, Arch>(dst.size(1));
398+
const size_t packetSize = packet::Packet<DType, Arch>::Size();
398399
#if (MSHADOW_USE_CUDA == 0)
399400
#pragma omp parallel for
400401
#endif
401402
for (openmp_index_t y = 0; y < dst.size(0); ++y) {
402-
for (index_t x = 0; x < xlen; x += packet::Packet<DType, Arch>::kSize) {
403+
for (index_t x = 0; x < xlen; x += packetSize) {
403404
packet::Saver<SV, DType, Arch>::Save(&dst[y][x], plan.EvalPacket(y, x));
404405
}
405406
for (index_t x = xlen; x < dst.size(1); ++x) {

‎mshadow/packet/plain-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ template<typename DType>
1515
struct Packet<DType, kPlain> {
1616
public:
1717
/*! \brief number of float in vector */
18-
static const index_t kSize = 1;
18+
static inline index_t Size() { return 1; }
1919
/*! \brief The internal data */
2020
DType data_;
2121
// enable default copy constructor

‎mshadow/packet/sse-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ template<>
1717
struct Packet<float, kSSE2> {
1818
public:
1919
/*! \brief number of float in vector */
20-
static const index_t kSize = 4;
20+
static inline index_t Size() { return 4; }
2121
/*! \brief The internal data */
2222
__m128 data_;
2323
// enable default copy constructor
@@ -63,7 +63,7 @@ struct Packet<float, kSSE2> {
6363
template<>
6464
struct Packet<double, kSSE2> {
6565
/*! \brief number of float in vector */
66-
static const index_t kSize = 2;
66+
static inline index_t Size() { return 2; }
6767
// internal data
6868
__m128d data_;
6969
// constructor

‎mshadow/tensor_blob.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ struct TShape {
259259
*/
260260
template<int dim>
261261
inline Shape<dim> get(void) const {
262-
CHECK_EQ(dim, ndim_) << "dimension do not match target dimension " << dim << " vs " << ndim_;
262+
CHECK_EQ(dim, static_cast<int>(ndim_)) << "dimension do not match target dimension "
263+
<< dim << " vs " << ndim_;
263264
const index_t *d = this->data();
264265
Shape<dim> s;
265266
for (int i = 0; i < dim; ++i) {

‎mshadow/tensor_cpu-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ inline void MapReduceKeepLowest(TRValue<R, cpu, 1, DType> *dst,
210210
::Check(exp.self()).FlatTo2D();
211211
Shape<1> dshape = expr::ShapeCheck<1, R>::Check(dst->self());
212212
CHECK_EQ(eshape[1], dshape[0]) << "MapReduceKeepLowest::reduction dimension do not match";
213-
CHECK_NE(eshape[0], 0) << "can not reduce over empty tensor";
213+
CHECK_NE(eshape[0], 0U) << "can not reduce over empty tensor";
214214
// execution
215215
expr::Plan<R, DType> dplan = MakePlan(dst->self());
216216
expr::Plan<E, DType> splan = MakePlan(exp.self());

‎mshadow/tensor_gpu-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ inline void MapReduceKeepLowest(TRValue<R, gpu, 1, DType> *dst,
126126
::Check(exp.self()).FlatTo2D();
127127
Shape<1> dshape = expr::ShapeCheck<1, R>::Check(dst->self());
128128
CHECK_EQ(eshape[1], dshape[0]) << "MapReduceKeepLowest::reduction dimension do not match";
129-
CHECK_NE(eshape[0], 0) << "can not reduce over empty tensor";
129+
CHECK_NE(eshape[0], 0U) << "can not reduce over empty tensor";
130130
cuda::MapReduceKeepLowest<Saver, Reducer>
131131
(MakePlan(dst->self()), MakePlan(exp.self()), scale, eshape,
132132
Stream<gpu>::GetStream(expr::StreamInfo<gpu, R>::Get(dst->self())));

0 commit comments

Comments
 (0)
This repository has been archived.