Skip to content
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

Initial support for expression templates in array and array_ref class #628

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

vaithak
Copy link
Collaborator

@vaithak vaithak commented Sep 18, 2023

This is to speed up the operations for vector mode by ensuring that temporary array objects are not created when performing arithmetic operations of vectors.
Reference used: https://indico.cern.ch/event/450743/contributions/1116430/attachments/1224060/1790963/out-iCSC2016-L1.pdf

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

include/clad/Differentiator/ArrayExpression.h Outdated Show resolved Hide resolved
include/clad/Differentiator/ArrayExpression.h Outdated Show resolved Hide resolved
include/clad/Differentiator/ArrayExpression.h Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Merging #628 (f0f55a5) into master (71dd694) will increase coverage by 0.00%.
Report is 2 commits behind head on master.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #628   +/-   ##
=======================================
  Coverage   94.04%   94.05%           
=======================================
  Files          43       43           
  Lines        6230     6236    +6     
=======================================
+ Hits         5859     5865    +6     
  Misses        371      371           

see 4 files with indirect coverage changes

see 4 files with indirect coverage changes

@vaithak vaithak changed the title Add expression templates in array and array_ref class Initial support for expression templates in array and array_ref class Sep 18, 2023
@vaithak vaithak force-pushed the expression-template branch from 7da6de8 to fdf2549 Compare September 18, 2023 06:29
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

include/clad/Differentiator/ArrayExpression.h Outdated Show resolved Hide resolved
@vaithak
Copy link
Collaborator Author

vaithak commented Sep 18, 2023

This improves the timing for the weighted sum benchmark by a factor of 3 (from around 650ns to about 200ns), but this can be improved further. For the benchmark of the simple case, this doesn't add any improvement mainly because it consists of a loop of the following form:

for (int i = 0; i < dim; i++)
    r += p[i];

The reason is that this current implementation evaluates array_expression into to array on the usage of the += operator.
A possibly better solution can be only to evaluate the expression when using indexing functions, i.e. [i] and slice() operations.

I will send a separate PR trying this improvement.

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

operator=(const array_expression<L, BinaryOp, R>& arr_exp) {
assert(arr_exp.size() == m_size);
for (std::size_t i = 0; i < m_size; i++)
m_arr[i] = static_cast<T>(arr_exp[i]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the static_cast here. Doesn't that signal a potential issue due to type incompatibility?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed 👍🏼

@vaithak vaithak force-pushed the expression-template branch from 51b659f to f0f55a5 Compare September 23, 2023 20:02
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good to me. Are we covered with tests? Perhaps we should write a benchmark making sure we do not regress the implementation?

Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vgvassilev vgvassilev merged commit b54fcd1 into vgvassilev:master Sep 26, 2023
77 checks passed
@vaithak vaithak deleted the expression-template branch March 13, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants