Skip to content

Commit c9fef6c

Browse files
committed
merge to develop
2 parents 90be53e + e126bcc commit c9fef6c

File tree

258 files changed

+4359
-82318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+4359
-82318
lines changed

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def runTests(String testPath) {
1111
def runTestsWin(String testPath) {
1212
withEnv(['PATH+TBB=./lib/tbb']) {
1313
bat "echo $PATH"
14-
bat "runTests.py -j${env.PARALLEL} ${testPath} --make-only"
15-
try { bat "runTests.py -j${env.PARALLEL} ${testPath}" }
14+
bat "runTests.py -j12 ${testPath} --make-only"
15+
try { bat "runTests.py -j12 ${testPath}" }
1616
finally { junit 'test/**/*.xml' }
1717
}
1818
}
@@ -160,7 +160,7 @@ pipeline {
160160
deleteDir()
161161
unstash 'MathSetup'
162162
sh "echo CXX=${MPICXX} >> make/local"
163-
sh "echo CXX_TYPE=gcc >> make/local"
163+
sh "echo CXX_TYPE=gcc >> make/local"
164164
sh "echo STAN_MPI=true >> make/local"
165165
runTests("test/unit")
166166
}

stan/math/fwd/mat/fun/dot_product.hpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,60 @@ inline fvar<T> dot_product(const std::vector<fvar<T> >& v1,
157157
return ret;
158158
}
159159

160+
/**
161+
* Return dot product of specified pointers up to specified length.
162+
*
163+
* @tparam T type of scalar within fvar
164+
* @param v1 pointer to first sequence
165+
* @param v2 pointer second sequence
166+
* @param length number of elements to multiply from each sequence
167+
* @return dot product of sequences up to length
168+
*/
169+
template <typename T>
170+
inline fvar<T> dot_product(const fvar<T>* v1, const fvar<T>* v2,
171+
size_type length) {
172+
fvar<T> y = 0;
173+
for (size_t i = 0; i < length; ++i)
174+
y += v1[i] * v2[i];
175+
return y;
176+
}
177+
178+
/**
179+
* Return dot product of specified pointers up to specified length.
180+
*
181+
* @tparam T type of scalar within fvar
182+
* @param v1 pointer to first sequence
183+
* @param v2 pointer second sequence
184+
* @param length number of elements to multiply from each sequence
185+
* @return dot product of sequences up to length
186+
*/
187+
template <typename T>
188+
inline fvar<T> dot_product(const double* v1, const fvar<T>* v2,
189+
size_type length) {
190+
fvar<T> y = 0;
191+
for (size_t i = 0; i < length; ++i)
192+
y += v1[i] * v2[i];
193+
return y;
194+
}
195+
196+
/**
197+
* Return dot product of specified pointers up to specified length.
198+
*
199+
* @tparam T type of scalar within fvar
200+
* @param v1 pointer to first sequence
201+
* @param v2 pointer second sequence
202+
* @param length number of elements to multiply from each sequence
203+
* @return dot product of sequences up to length
204+
*/
205+
template <typename T>
206+
inline fvar<T> dot_product(const fvar<T>* v1, const double* v2,
207+
size_type length) {
208+
fvar<T> y = 0;
209+
for (size_t i = 0; i < length; ++i)
210+
y += v1[i] * v2[i];
211+
return y;
212+
}
213+
160214
} // namespace math
161215
} // namespace stan
162216
#endif

stan/math/opencl/copy.hpp

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,24 @@ namespace math {
3636
template <typename Mat, typename Mat_scalar = scalar_type_t<Mat>,
3737
require_eigen_t<Mat>...>
3838
inline matrix_cl<Mat_scalar> to_matrix_cl(Mat&& src) {
39-
return matrix_cl<Mat_scalar>(src);
39+
matrix_cl<Mat_scalar> dst(src.rows(), src.cols());
40+
if (src.size() == 0) {
41+
return dst;
42+
}
43+
try {
44+
cl::Event transfer_event;
45+
cl::CommandQueue& queue = opencl_context.queue();
46+
queue.enqueueWriteBuffer(
47+
dst.buffer(),
48+
opencl_context.in_order()
49+
|| std::is_rvalue_reference<Mat_scalar&&>::value,
50+
0, sizeof(Mat_scalar) * src.size(), src.eval().data(), nullptr,
51+
&transfer_event);
52+
dst.add_write_event(transfer_event);
53+
} catch (const cl::Error& e) {
54+
check_opencl_error("copy Eigen->(OpenCL)", e);
55+
}
56+
return dst;
4057
}
4158

4259
/**
@@ -50,7 +67,24 @@ inline matrix_cl<Mat_scalar> to_matrix_cl(Mat&& src) {
5067
template <typename Vec, typename Vec_scalar = scalar_type_t<Vec>,
5168
require_std_vector_t<Vec>...>
5269
inline matrix_cl<Vec_scalar> to_matrix_cl(Vec&& src) {
53-
return matrix_cl<Vec_scalar>(src);
70+
matrix_cl<Vec_scalar> dst(src.size(), 1);
71+
if (src.size() == 0) {
72+
return dst;
73+
}
74+
try {
75+
cl::Event transfer_event;
76+
cl::CommandQueue& queue = opencl_context.queue();
77+
queue.enqueueWriteBuffer(
78+
dst.buffer(),
79+
opencl_context.in_order()
80+
|| std::is_rvalue_reference<Vec_scalar&&>::value,
81+
0, sizeof(Vec_scalar) * src.size(), src.data(), nullptr,
82+
&transfer_event);
83+
dst.add_write_event(transfer_event);
84+
} catch (const cl::Error& e) {
85+
check_opencl_error("copy Eigen->(OpenCL)", e);
86+
}
87+
return dst;
5488
}
5589

5690
/**
@@ -181,7 +215,28 @@ inline matrix_cl<Vec_scalar> packed_copy(Vec&& src, int rows) {
181215
*/
182216
template <typename T, typename = require_arithmetic_t<T>>
183217
inline matrix_cl<T> copy_cl(const matrix_cl<T>& src) {
184-
return matrix_cl<T>(src);
218+
matrix_cl<T> dst(src.rows(), src.cols(), src.view());
219+
if (src.size() == 0) {
220+
return dst;
221+
}
222+
try {
223+
/**
224+
* Copies the contents of the src buffer to the dst buffer
225+
* see the matrix_cl(matrix_cl&) constructor
226+
* for explanation
227+
*/
228+
cl::CommandQueue queue = opencl_context.queue();
229+
const std::vector<cl::Event> mat_events
230+
= vec_concat(dst.read_write_events(), src.write_events());
231+
cl::Event copy_event;
232+
queue.enqueueCopyBuffer(src.buffer(), dst.buffer(), 0, 0,
233+
sizeof(T) * src.size(), &mat_events, &copy_event);
234+
dst.add_write_event(copy_event);
235+
src.add_read_event(copy_event);
236+
} catch (const cl::Error& e) {
237+
check_opencl_error("copy_cl (OpenCL)->(OpenCL)", e);
238+
}
239+
return dst;
185240
}
186241

187242
/**
@@ -218,7 +273,23 @@ inline T from_matrix_cl_error_code(const matrix_cl<T>& src) {
218273
*/
219274
template <typename T, typename = require_arithmetic_t<std::decay_t<T>>>
220275
inline matrix_cl<std::decay_t<T>> to_matrix_cl(T&& src) {
221-
return matrix_cl<std::decay_t<T>>(src);
276+
matrix_cl<std::decay_t<T>> dst(1, 1);
277+
check_size_match("to_matrix_cl ((OpenCL) -> (OpenCL))", "src.rows()",
278+
dst.rows(), "dst.rows()", 1);
279+
check_size_match("to_matrix_cl ((OpenCL) -> (OpenCL))", "src.cols()",
280+
dst.cols(), "dst.cols()", 1);
281+
try {
282+
cl::Event copy_event;
283+
const cl::CommandQueue queue = opencl_context.queue();
284+
queue.enqueueWriteBuffer(
285+
dst.buffer(),
286+
opencl_context.in_order() || std::is_rvalue_reference<T&&>::value, 0,
287+
sizeof(std::decay_t<T>), &src, &dst.write_events(), &copy_event);
288+
dst.add_write_event(copy_event);
289+
} catch (const cl::Error& e) {
290+
check_opencl_error("to_matrix_cl (OpenCL)->(OpenCL)", e);
291+
}
292+
return dst;
222293
}
223294

224295
} // namespace math

0 commit comments

Comments
 (0)