Skip to content

Commit

Permalink
merge to develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveBronder committed Nov 5, 2019
2 parents 90be53e + e126bcc commit c9fef6c
Show file tree
Hide file tree
Showing 258 changed files with 4,359 additions and 82,318 deletions.
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def runTests(String testPath) {
def runTestsWin(String testPath) {
withEnv(['PATH+TBB=./lib/tbb']) {
bat "echo $PATH"
bat "runTests.py -j${env.PARALLEL} ${testPath} --make-only"
try { bat "runTests.py -j${env.PARALLEL} ${testPath}" }
bat "runTests.py -j12 ${testPath} --make-only"
try { bat "runTests.py -j12 ${testPath}" }
finally { junit 'test/**/*.xml' }
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ pipeline {
deleteDir()
unstash 'MathSetup'
sh "echo CXX=${MPICXX} >> make/local"
sh "echo CXX_TYPE=gcc >> make/local"
sh "echo CXX_TYPE=gcc >> make/local"
sh "echo STAN_MPI=true >> make/local"
runTests("test/unit")
}
Expand Down
54 changes: 54 additions & 0 deletions stan/math/fwd/mat/fun/dot_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,60 @@ inline fvar<T> dot_product(const std::vector<fvar<T> >& v1,
return ret;
}

/**
* Return dot product of specified pointers up to specified length.
*
* @tparam T type of scalar within fvar
* @param v1 pointer to first sequence
* @param v2 pointer second sequence
* @param length number of elements to multiply from each sequence
* @return dot product of sequences up to length
*/
template <typename T>
inline fvar<T> dot_product(const fvar<T>* v1, const fvar<T>* v2,
size_type length) {
fvar<T> y = 0;
for (size_t i = 0; i < length; ++i)
y += v1[i] * v2[i];
return y;
}

/**
* Return dot product of specified pointers up to specified length.
*
* @tparam T type of scalar within fvar
* @param v1 pointer to first sequence
* @param v2 pointer second sequence
* @param length number of elements to multiply from each sequence
* @return dot product of sequences up to length
*/
template <typename T>
inline fvar<T> dot_product(const double* v1, const fvar<T>* v2,
size_type length) {
fvar<T> y = 0;
for (size_t i = 0; i < length; ++i)
y += v1[i] * v2[i];
return y;
}

/**
* Return dot product of specified pointers up to specified length.
*
* @tparam T type of scalar within fvar
* @param v1 pointer to first sequence
* @param v2 pointer second sequence
* @param length number of elements to multiply from each sequence
* @return dot product of sequences up to length
*/
template <typename T>
inline fvar<T> dot_product(const fvar<T>* v1, const double* v2,
size_type length) {
fvar<T> y = 0;
for (size_t i = 0; i < length; ++i)
y += v1[i] * v2[i];
return y;
}

} // namespace math
} // namespace stan
#endif
79 changes: 75 additions & 4 deletions stan/math/opencl/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ namespace math {
template <typename Mat, typename Mat_scalar = scalar_type_t<Mat>,
require_eigen_t<Mat>...>
inline matrix_cl<Mat_scalar> to_matrix_cl(Mat&& src) {
return matrix_cl<Mat_scalar>(src);
matrix_cl<Mat_scalar> dst(src.rows(), src.cols());
if (src.size() == 0) {
return dst;
}
try {
cl::Event transfer_event;
cl::CommandQueue& queue = opencl_context.queue();
queue.enqueueWriteBuffer(
dst.buffer(),
opencl_context.in_order()
|| std::is_rvalue_reference<Mat_scalar&&>::value,
0, sizeof(Mat_scalar) * src.size(), src.eval().data(), nullptr,
&transfer_event);
dst.add_write_event(transfer_event);
} catch (const cl::Error& e) {
check_opencl_error("copy Eigen->(OpenCL)", e);
}
return dst;
}

/**
Expand All @@ -50,7 +67,24 @@ inline matrix_cl<Mat_scalar> to_matrix_cl(Mat&& src) {
template <typename Vec, typename Vec_scalar = scalar_type_t<Vec>,
require_std_vector_t<Vec>...>
inline matrix_cl<Vec_scalar> to_matrix_cl(Vec&& src) {
return matrix_cl<Vec_scalar>(src);
matrix_cl<Vec_scalar> dst(src.size(), 1);
if (src.size() == 0) {
return dst;
}
try {
cl::Event transfer_event;
cl::CommandQueue& queue = opencl_context.queue();
queue.enqueueWriteBuffer(
dst.buffer(),
opencl_context.in_order()
|| std::is_rvalue_reference<Vec_scalar&&>::value,
0, sizeof(Vec_scalar) * src.size(), src.data(), nullptr,
&transfer_event);
dst.add_write_event(transfer_event);
} catch (const cl::Error& e) {
check_opencl_error("copy Eigen->(OpenCL)", e);
}
return dst;
}

/**
Expand Down Expand Up @@ -181,7 +215,28 @@ inline matrix_cl<Vec_scalar> packed_copy(Vec&& src, int rows) {
*/
template <typename T, typename = require_arithmetic_t<T>>
inline matrix_cl<T> copy_cl(const matrix_cl<T>& src) {
return matrix_cl<T>(src);
matrix_cl<T> dst(src.rows(), src.cols(), src.view());
if (src.size() == 0) {
return dst;
}
try {
/**
* Copies the contents of the src buffer to the dst buffer
* see the matrix_cl(matrix_cl&) constructor
* for explanation
*/
cl::CommandQueue queue = opencl_context.queue();
const std::vector<cl::Event> mat_events
= vec_concat(dst.read_write_events(), src.write_events());
cl::Event copy_event;
queue.enqueueCopyBuffer(src.buffer(), dst.buffer(), 0, 0,
sizeof(T) * src.size(), &mat_events, &copy_event);
dst.add_write_event(copy_event);
src.add_read_event(copy_event);
} catch (const cl::Error& e) {
check_opencl_error("copy_cl (OpenCL)->(OpenCL)", e);
}
return dst;
}

/**
Expand Down Expand Up @@ -218,7 +273,23 @@ inline T from_matrix_cl_error_code(const matrix_cl<T>& src) {
*/
template <typename T, typename = require_arithmetic_t<std::decay_t<T>>>
inline matrix_cl<std::decay_t<T>> to_matrix_cl(T&& src) {
return matrix_cl<std::decay_t<T>>(src);
matrix_cl<std::decay_t<T>> dst(1, 1);
check_size_match("to_matrix_cl ((OpenCL) -> (OpenCL))", "src.rows()",
dst.rows(), "dst.rows()", 1);
check_size_match("to_matrix_cl ((OpenCL) -> (OpenCL))", "src.cols()",
dst.cols(), "dst.cols()", 1);
try {
cl::Event copy_event;
const cl::CommandQueue queue = opencl_context.queue();
queue.enqueueWriteBuffer(
dst.buffer(),
opencl_context.in_order() || std::is_rvalue_reference<T&&>::value, 0,
sizeof(std::decay_t<T>), &src, &dst.write_events(), &copy_event);
dst.add_write_event(copy_event);
} catch (const cl::Error& e) {
check_opencl_error("to_matrix_cl (OpenCL)->(OpenCL)", e);
}
return dst;
}

} // namespace math
Expand Down
Loading

0 comments on commit c9fef6c

Please sign in to comment.