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

Keccak CPU backend #622

Merged
merged 10 commits into from
Oct 8, 2024
Merged

Keccak CPU backend #622

merged 10 commits into from
Oct 8, 2024

Conversation

yshekel
Copy link
Collaborator

@yshekel yshekel commented Oct 7, 2024

Implement Keccak and SHA-3 for CPU backend, including tests.

cuda-backend-branch: yshekel/keccak_cuda

#define SHA3_USE_KECCAK_FLAG (0x80000000)
#define SHA3_CW(x) ((x) & (~SHA3_USE_KECCAK_FLAG))

#if defined(_MSC_VER)
Copy link
Contributor

Choose a reason for hiding this comment

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

might consider adding modifers in
icicle/icicle/include/icicle/utils/modifiers.h

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


for (unsigned batch_idx = 0; batch_idx < config.batch; ++batch_idx) {
eIcicleError err = sha3_hash_buffer(
8 * digest_size_in_bytes, m_is_keccak, input + batch_idx * single_input_size, single_input_size,
Copy link
Contributor

Choose a reason for hiding this comment

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

worth adding a comment that the 8 is for byte to bit conversion

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -61,7 +61,7 @@ if (HASH)
target_include_directories(test_hash_api PRIVATE ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(test_hash_api PRIVATE GTest::gtest_main icicle_device icicle_hash)
gtest_discover_tests(test_hash_api)
if (POSEIDON)
if (POSEIDON AND (FIELD OR CURVE))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should Have a flag for Hashes. maye we can replace POSEIDON with HASH to compile and test all hashes includiong poseidon

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we have a flag for hashes but then fields can also support poseidon but they don't have to so some will have it and some don't.
I should maybe set the poseidon to OFF in that case but I am not sure it's a good idea.
Will leave it like that for now

@yshekel yshekel requested a review from aviadingo October 8, 2024 09:31
aviadingo and others added 2 commits October 8, 2024 12:35
static const uint64_t s_keccakf_rndc[24];
static const unsigned s_keccakf_rotc[24];
static const unsigned s_keccakf_piln[24];
const bool m_is_keccak;
Copy link
Contributor

Choose a reason for hiding this comment

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

what is that memeber for?

Copy link
Collaborator Author

@yshekel yshekel Oct 8, 2024

Choose a reason for hiding this comment

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

The implementation that Aviad used needs to know that since it's both for keccak and sha3.
Since the same object implements keccak and sha3, it is stored. maybe an enum is better but I don't think it will be ever extended. If we need we can make it enum later, it's really just an implementation detail here.

@@ -26,3 +26,9 @@
#define __host__
#define __device__
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

we are not compatible with windows anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know but the source was like that. Do you prefer deleting it? no way we support windows?

@@ -134,6 +247,7 @@ class HashSumBackend : public HashBackend

TEST_F(HashApiTest, MerkleTree)
{
ICICLE_CHECK(icicle_set_device(s_reference_target)); // TODO CUDA too
Copy link
Contributor

@mickeyasa mickeyasa Oct 8, 2024

Choose a reason for hiding this comment

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

what about the TODO
we have cuda

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there is no merkle tree for GPU yet so the TODO is for Roman I guess :)

// TODO: add tests for all hashes
TEST_F(HashApiTest, sha3)
{
auto config = default_hash_config();
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we testing it only on CPU?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we test all devices including CUDA in the loop below

Copy link
Contributor

@mickeyasa mickeyasa left a comment

Choose a reason for hiding this comment

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

maybe I didn;t understand but tests should also run on GPU

@yshekel yshekel merged commit 0cd54fe into main Oct 8, 2024
28 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.

3 participants