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

feat(dipu): implement setter/getter for offset&seed of diopiGenerator #762

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions dipu/torch_dipu/csrc_dipu/diopirt/diopirt_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ DIOPI_RT_API diopiError_t diopiGeneratorSetState(
return diopiSuccess;
}

DIOPI_RT_API diopiError_t diopiGeneratorGetSeedAndOffset(
diopiGeneratorHandle_t th, uint64_t& seed, uint64_t& offset) {
auto generator = reinterpret_cast<at::Generator*>(th);
auto gen_impl = at::check_generator<dipu::DIPUGeneratorImpl>(*generator);
offset = gen_impl->get_offset();
seed = gen_impl->current_seed();
return diopiSuccess;
}

DIOPI_RT_API diopiError_t diopiGeneratorSetSeedAndOffset(
diopiGeneratorHandle_t th, uint64_t seed, uint64_t offset) {
auto generator = reinterpret_cast<at::Generator*>(th);
auto gen_impl = at::check_generator<dipu::DIPUGeneratorImpl>(*generator);
gen_impl->set_offset(offset);
gen_impl->set_current_seed(seed);
return diopiSuccess;
}

DIOPI_RT_API diopiError_t diopiRecordStart(const char* record_name,
void** record) {
*record = new RecordBlockCreator(record_name);
Expand Down