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

Refactor main C++ function to avoid use "constant" memory and avoid new/delete #55

Merged
merged 19 commits into from
Feb 9, 2018

Conversation

unzvfu
Copy link

@unzvfu unzvfu commented Jan 15, 2018

This is a low priority PR that came up while looking into data61/anonlink-entity-service#59

The improvement it implements is to use "essentially" constant stack space of size k rather than heap space equivalent to the input length n. So we avoid memory allocation/deallocation, heap usage, and it's also somewhat shorter.

Also included are some minor syntactical and semantic clean-ups, and some comments for future improvements.

Details:

Previous behaviour was to

  1. allocate a big array all_scores on the heap
  2. calculate (almost) all the scores in turn and put each one in all_scores
  3. scan through all_scores to pick the top k matches (using the essentially fixed-sized prio queue)
  4. deallocate all_scores

Now we skip all_scores altogether and just calculate (almost) the scores in turn, inserting each one into the fixed-sized prio queue.

@unzvfu unzvfu requested a review from hardbyte January 15, 2018 01:15
@@ -139,14 +139,17 @@ extern "C"
const uint64_t *comp1 = (const uint64_t *) one;
const uint64_t *comp2 = (const uint64_t *) many;

// TODO: Given that k is 10 by default, often 5 in practice,
// and probably never ever more than 20 or so, the use of a
Copy link
Collaborator

Choose a reason for hiding this comment

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

This statement isn't (well shouldn't be) correct - anonlink needs to support computing all raw similarity scores.


if(max_k_scores.size() > k) max_k_scores.pop();
// TODO: double precision is overkill for this
// problem; just use float.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good

@@ -155,39 +158,32 @@ extern "C"

for (int j = 0; j < n; j++) {
const uint64_t *current = comp2 + j * KEYWORDS;
const uint32_t counts_many_j = counts_many[j];
Copy link
Collaborator

Choose a reason for hiding this comment

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

It always suprises me what you have to help the compiler with

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, this can be more or less important depending on the context. Here it's more about showing intent to fellow programmers than to the compiler.

@unzvfu unzvfu self-assigned this Jan 15, 2018
@hardbyte hardbyte added this to the Sprint 2018-01-29 milestone Jan 24, 2018
@unzvfu unzvfu merged commit 5cab824 into develop Feb 9, 2018
@unzvfu unzvfu deleted the hlaw-refactor-cpp branch February 9, 2018 05:48
unzvfu pushed a commit that referenced this pull request Mar 15, 2018
* Skip conversion to cffi char[] unless required

* Libraries shouldn't configure logging

* Version bump to 0.6.3

* Improvements to benchmark (#58)

* Refactor Dice coefficient calculation.

* Temporary fiddling with benchmark code.

* Calculate and report popcount speed from native code implementation.

* Give some values more sensible variable names.

* Remove unused import.

* Add documentation.

* Expand reporting of various measurements.

* Comments.

* Update README.

* Bring test suite up-to-date.

* Address Brian's comments.

* Update tests; also test native code version.

* Print popcount throughput; give some variables better names.

* Update README with throughput data.

* Refactor main C++ function to avoid use "constant" memory and avoid new/delete (#55)

* Refactor main C++ function to avoid use "constant" memory and avoid new/delete.

* Refactor Dice coefficient calculation.

* Temporary fiddling with benchmark code.

* Calculate and report popcount speed from native code implementation.

* Give some values more sensible variable names.

* Remove unused import.

* Add documentation.

* Expand reporting of various measurements.

* Comments.

* Update README.

* Bring test suite up-to-date.

* Refactor main C++ function to avoid use "constant" memory and avoid new/delete.

* Address Brian's comments.

* Update tests; also test native code version.

* Print popcount throughput; give some variables better names.

* Feature build on Travis CI (#61)

Run tests with travis ci

* Fix #include file name.

* Use pytest (#68)

* Update README and requirements.txt files.

* Add missing line in README.

* Use pytest on Jenkins.

* Make Jenkins test commands the same as Travis.

* Generate test output and coverage data properly.

* Move 'checkout scm' command to start of function; remove redundant cleaning code.

Fix #65

* Feature use jenkinslibrary (#70)

* Update jenkinsfile to use jenkins library.

* Reduce the number of OSX build and which node in Jenkinsfile (see #71)

* Arbitrary length Dice coefficients (#63)

* Refactor main C++ function to avoid use "constant" memory and avoid new/delete.

* Implement popcount on (almost) arbitrary length arrays.

* First pass at integrating arbitrary length keys. Slows things down a bit.

* Refactor Dice coefficient calculation.

* Temporary fiddling with benchmark code.

* Calculate and report popcount speed from native code implementation.

* Give some values more sensible variable names.

* Remove unused import.

* Add documentation.

* Expand reporting of various measurements.

* Comments.

* Update README.

* Bring test suite up-to-date.

* Refactor main C++ function to avoid use "constant" memory and avoid new/delete.

* Screw everything up by unrolling with C++ templates, apparently.

* Magical argument that makes the compiler generate the correct (performant) code.

* Address Brian's comments.

* Update tests; also test native code version.

* Print popcount throughput; give some variables better names.

* Make some functions static inline.

* Tidy up some expressions.

* Put some braces in the right place; make fn inline.

* Reinstate comment on origin of popcount assembler.

* Make constant a template parameter.

* Comment.

* Complete version working with multiples of 1024 bits.

* Add -march=native compiler option.

* Implementation of arbitrary length CLKs.

* Fix dumb mistakes in updating array pointer and popcounts.

* Tests for arbitrary length popcounts.

* Update some comments.

* Arbitrary length Dice coefficient.

* Rename function.

* Move native dicecoeff calculation into its own function.

* Add tests for native Dice coefficient calculation.

* Move dicecoeff tests to bloommatcher tests; move common bitarray utilities to their own file.

* Simplify slow path / reduce branches in fast path.

* Adapt entitymatcher to arbitrary length CLK interface.

* Remove unused function.

* Update README.

* Address Brian's comments.

* Exit early if filter is zero.

* Specialise popcount arrays calls on array length.

* Fix performance regression.

* Remove storage class specifiers from explicit template specialisations.

* Update README and requirements.txt files.

* Disable unused function.

* Put stars in their proper place.

* Add documentation.

* Prepare changelog and bump version for release 0.7.0

* Add clkhash as dependency (required for benchmark)
Add travis badge to readme
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.

None yet

2 participants