New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinalgRefactor - SGVector - inplace add #3391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,32 @@ TEST(LinalgBackendViennaCL, SGVector_add) | |
EXPECT_NEAR(alpha*A[i]+beta*B[i], result[i], 1e-15); | ||
} | ||
|
||
TEST(LinalgBackendViennaCL, add_in_place) | ||
{ | ||
sg_linalg->set_gpu_backend(new LinalgBackendViennaCL()); | ||
|
||
const float32_t alpha = 0.3; | ||
const float32_t beta = -1.5; | ||
|
||
SGVector<float32_t> A(9), B(9), C(9); | ||
SGVector<float32_t> A_gpu, B_gpu; | ||
|
||
for (index_t i = 0; i < 9; ++i) | ||
{ | ||
A[i] = i; | ||
B[i] = 0.5*i; | ||
C[i] = i; | ||
} | ||
A_gpu = to_gpu(A); | ||
B_gpu = to_gpu(B); | ||
|
||
add(A_gpu, B_gpu, A_gpu, alpha, beta); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this is an awkward interface, suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean inplace should be avoided where possible (for speed reasons), and only applied in particular cases where the memory cannot be afforded. So in that sense I dont care if the interface is awkward. But still would be nicer to do this somehow nicer (i.e. with a flag or so) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer do it like
compared to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OXPHOS the 'necessity' of allocating the memory advance is because some people want to actually have full control of the mallocs happening within the code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah imagine you already have a big matrix where you want to put things for some reason (I sometimes do in my code) |
||
A = from_gpu(A_gpu); | ||
|
||
for (index_t i = 0; i < 9; ++i) | ||
EXPECT_NEAR(alpha*C[i]+beta*B[i], A[i], 1e-15); | ||
} | ||
|
||
TEST(LinalgBackendViennaCL, SGVector_dot) | ||
{ | ||
sg_linalg->set_gpu_backend(new LinalgBackendViennaCL()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XOR for victory! :)