Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dmlc/mshadow into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
hjk41 committed Feb 2, 2016
2 parents 08427e3 + ec3e314 commit 12299cb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmake/Cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function(detect_cuDNN)
DOC "Path to cuDNN include directory." )

get_filename_component(__libpath_hist ${CUDA_CUDART_LIBRARY} PATH)
find_library(CUDNN_LIBRARY NAMES libcudnn.so # libcudnn_static.a
find_library(CUDNN_LIBRARY NAMES libcudnn.so cudnn.lib # libcudnn_static.a
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDNN_INCLUDE} ${__libpath_hist}
DOC "Path to cuDNN library.")

Expand Down
12 changes: 11 additions & 1 deletion guide/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(void) {
float data[20];
// create a 2 x 5 x 2 tensor, from existing space
Tensor<cpu, 3> ts(data, Shape3(2,5,2));
// take first subscript of the tensor
// take first subscript of the tensor
Tensor<cpu, 2> mat = ts[0];
// Tensor object is only a handle, assignment means they have same data content
// we can specify content type of a Tensor, if not specified, it is float bydefault
Expand Down Expand Up @@ -69,6 +69,16 @@ int main(void) {
}
printf("\n");

TensorContainer<cpu, 2> recover_lhs(Shape2(2, 3)), small_mat(Shape2(2, 3));
small_mat = -100.0f;
recover_lhs = mat_fill_row_element(small_mat, choosed, index);
for (index_t i = 0; i < recover_lhs.size(0); ++i) {
for (index_t j = 0; j < recover_lhs.size(1); ++j) {
printf("%.2f ", recover_lhs[i][j] - lhs[i][j]);
}
}
printf("\n");

rhs = one_hot_encode(index, 3);

for (index_t i = 0; i < lhs.size(0); ++i) {
Expand Down
20 changes: 15 additions & 5 deletions mshadow/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,30 @@ class Random<gpu, DType> {
inline void GenGaussian(float *dptr, size_t size, float mu, float sigma) {
curandStatus_t status;
status = curandGenerateNormal(gen_, dptr, size, mu, sigma);
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Uniform failed";
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Normal float failed."
<< " size = " << size
<< ",mu = " << mu
<< ",sigma = " << sigma;
}
inline void GenGaussian(double *dptr, size_t size, double mu, double sigma) {
curandStatus_t status;
status = curandGenerateNormalDouble(gen_, dptr, size, mu, sigma);
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Uniform failed";
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Normal double failed."
<< " size = " << size
<< ",mu = " << mu
<< ",sigma = " << sigma;
}
inline void GenUniform(float *dptr, size_t size) {
curandStatus_t status;
status = curandGenerateUniform(gen_, dptr, size);
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Uniform failed";
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Uniform float failed."
<< " size = " << size;
}
inline void GenUniform(double *dptr, size_t size) {
curandStatus_t status;
status = curandGenerateUniformDouble(gen_, dptr, size);
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Uniform failed";
CHECK_EQ(status, CURAND_STATUS_SUCCESS) << "CURAND Gen Uniform double failed."
<< " size = " << size;
}
/*! \brief random numbeer generator */
curandGenerator_t gen_;
Expand Down Expand Up @@ -361,7 +369,9 @@ template<typename DType>
template<int dim>
inline void Random<gpu, DType>::SampleGaussian(
Tensor<gpu, dim, DType> *dst, DType mu, DType sigma) {
if (dst->CheckContiguous()) {
// We need to check whether the shape size is even since CuRand supports only normal distribution
// generation of even number of elements.
if (dst->CheckContiguous() && (dst->shape_.Size() % 2 == 0)) {
this->GenGaussian(dst->dptr_, dst->shape_.Size(), mu, sigma);
} else {
*dst = this->gaussian(dst->shape_, mu, sigma);
Expand Down
2 changes: 1 addition & 1 deletion mshadow/tensor_blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ struct TShape {
inline std::ostream &operator<<(std::ostream &os, const TShape &shape) {
os << '(';
for (index_t i = 0; i < shape.ndim(); ++i) {
if (i != 0) os << ", ";
if (i != 0) os << ',';
os << shape[i];
}
// python style tuple
Expand Down
8 changes: 5 additions & 3 deletions mshadow/tensor_cpu-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ inline void DeleteStream<cpu>(Stream<cpu> *stream) {

template<int ndim>
inline std::ostream &operator<<(std::ostream &os, const Shape<ndim> &shape) { // NOLINT(*)
os << "(";
os << '(';
for (int i = 0; i < ndim; ++i) {
if (i != 0) os << ",";
if (i != 0) os << ',';
os << shape[i];
}
os << ")";
// python style tuple
if (ndim == 1) os << ',';
os << ')';
return os;
}

Expand Down

0 comments on commit 12299cb

Please sign in to comment.