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

Allow changing the reserved keys #191

Merged
merged 1 commit into from
May 17, 2024
Merged

Allow changing the reserved keys #191

merged 1 commit into from
May 17, 2024

Conversation

jq
Copy link

@jq jq commented May 9, 2024

Allow changing the reserved keys in the confliction, call init_reserved_keys to change it

@jq jq changed the title enable reserve key enable reservee key May 9, 2024
@jq jq changed the title enable reservee key enable reserved key May 9, 2024
@jq jq changed the title enable reserved key Allow changing the reserved keys May 9, 2024
@jq jq force-pushed the r3 branch 5 times, most recently from aafcbd2 to 1789f38 Compare May 10, 2024 22:18
Copy link

__constant__ uint64_t LOCKED_KEY = UINT64_C(0xFFFFFFFFFFFFFFFD);
template <class K>
__forceinline__ __device__ bool IS_RESERVED_KEY(K key) {
return key == EMPTY_KEY || key == RECLAIM_KEY || key == LOCKED_KEY;
Copy link
Member

Choose a reason for hiding this comment

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

Considering the performance(IS_RESERVED_KEY will be called anytime on each threads), it would be better to use & operator, so we can use one reserved mask to indicate the reserved keys space like RESERVED_KEY_MASK = UINT64_C(0xFFFFFFFFFFFFFFFC);, by default, it should be 0x3, if we wanna reserve 0xFFFFFFFFFFFFFFxF(x = E, C, D), we can let the user give a mask valued 0x30.

@jq jq force-pushed the r3 branch 5 times, most recently from a1b3116 to 1fc4abb Compare May 15, 2024 02:49
Copy link

@MoFHeka MoFHeka left a comment

Choose a reason for hiding this comment

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

LGTM

@jq jq force-pushed the r3 branch 13 times, most recently from 63f502e to c950300 Compare May 15, 2024 15:27
@jq jq force-pushed the r3 branch 4 times, most recently from 27f39f7 to 767c84f Compare May 16, 2024 15:37
uint64_t lockedKey = emptyKey & ~(UINT64_C(2) << index);
EMPTY_KEY_CPU = emptyKey;

printf("reserved keys are emptyKey, reclaimKey, lockedKey and reservedKeyMask2\n");
Copy link
Author

Choose a reason for hiding this comment

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

@MoFHeka @rhdong print out the new generated reserved key here.

printf("lockedKey: %lx, reservedKeyMask1: %lx\n", lockedKey, reservedKeyMask1);
printf("reservedKeyMask2: %lx, vacantKeyMask1: %lx\n", reservedKeyMask2, vacantKeyMask1);

cudaMemcpyToSymbol(EMPTY_KEY, &emptyKey, sizeof(uint64_t));
Copy link
Member

Choose a reason for hiding this comment

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

CUDA_CHECK

@@ -98,6 +98,7 @@ struct HashTableOptions {
int device_id = -1; ///< The ID of device.
bool io_by_cpu = false; ///< The flag indicating if the CPU handles IO.
bool use_constant_memory = false; ///< reserved
int reserved_key_index = 0; ///< The binary index of reserved key.
Copy link
Member

@rhdong rhdong May 16, 2024

Choose a reason for hiding this comment

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

Need more detail comment which allows user know the configuration effect exactly. For example: index=0 means which keys will be reserved.

Copy link
Author

Choose a reason for hiding this comment

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

updated

@@ -3437,6 +3440,12 @@ void test_bucket_size(bool load_scores = true) {
CudaCheckError();
}


TEST(MerlinHashTableTest, test_basic) {
Copy link
Member

Choose a reason for hiding this comment

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

Why change the position?

Copy link
Author

Choose a reason for hiding this comment

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

change back

@@ -145,6 +145,8 @@ void test_basic(size_t max_hbm_for_vectors) {
options.dim = DIM;
options.max_bucket_size = BUCKET_MAX_SIZE;
options.max_hbm_for_vectors = nv::merlin::GB(max_hbm_for_vectors);
options.reserved_key_index = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Please add test cases like this for the other API.

Copy link
Author

Choose a reason for hiding this comment

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

added

README.md Outdated
- The keys of `0xFFFFFFFFFFFFFFFC`, `0xFFFFFFFFFFFFFFFD`, `0xFFFFFFFFFFFFFFFE`, and `0xFFFFFFFFFFFFFFFF` are reserved for internal using.

- The keys of `0xFFFFFFFFFFFFFFFD`, `0xFFFFFFFFFFFFFFFE`, and `0xFFFFFFFFFFFFFFFF` are reserved for internal using.
- Call set options.reserved_key_index to change the reserved keys if the default one conflicted with your keys.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe 'reserved_key_start_index' would be better?

Copy link
Author

Choose a reason for hiding this comment

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

done

@jq jq force-pushed the r3 branch 6 times, most recently from 9367c46 to 7733b72 Compare May 17, 2024 04:19
@rhdong
Copy link
Member

rhdong commented May 17, 2024

/blossom-ci

@@ -865,6 +876,7 @@ class HashTable : public HashTableBase<K, V, S> {
return;
}
options_ = options;
CUDA_CHECK(init_reserved_keys(options.reserved_key_start_bit));
Copy link
Member

Choose a reason for hiding this comment

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

Pls use MERLIN_CHECK to check if the value falls in [0, 61]

* reserved_key_start_bit = 0, is the default behavior, HKV reserves `0xFFFFFFFFFFFFFFFD`,
* `0xFFFFFFFFFFFFFFFE`, and `0xFFFFFFFFFFFFFFFF` for internal using.
* if the default one conflicted with your keys, change the reserved_key_start_bit
* value to a numbers between 1 and 61, reserved_key_start_bit = 1 means using the
Copy link
Member

Choose a reason for hiding this comment

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

Why is the 62 not valid?

Copy link
Author

Choose a reason for hiding this comment

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

62 meaning using 62 and 63, then it is no longer neg number, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

62 should be valid.

@jq jq force-pushed the r3 branch 3 times, most recently from d9b9047 to 7e7d0af Compare May 17, 2024 16:36
@rhdong
Copy link
Member

rhdong commented May 17, 2024

/blossom-ci

Copy link
Member

@rhdong rhdong left a comment

Choose a reason for hiding this comment

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

LGTM

@rhdong rhdong merged commit e4aba46 into NVIDIA-Merlin:master May 17, 2024
2 checks passed
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

3 participants