-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR for the GDS AIO code. --------- Co-authored-by: Olatunji Ruwase <olruwase@microsoft.com> Co-authored-by: Logan Adams <loadams@microsoft.com> Co-authored-by: Ubuntu <deepspeed@H100-VM2.shlnn55tgwve1eacvp21ie45dg.jx.internal.cloudapp.net> Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
- Loading branch information
1 parent
c2e3a70
commit 5f0d177
Showing
43 changed files
with
2,144 additions
and
761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// DeepSpeed Team | ||
|
||
#include "deepspeed_aio_op_desc.h" | ||
|
||
using namespace std; | ||
|
||
io_op_desc_t::io_op_desc_t(const bool read_op, | ||
const torch::Tensor& buffer, | ||
const int fd, | ||
const char* filename, | ||
const long long int file_num_bytes, | ||
const int num_threads, | ||
const bool validate) | ||
: _read_op(read_op), | ||
_buffer(buffer), | ||
_fd(fd), | ||
_filename(filename), | ||
_file_num_bytes(file_num_bytes), | ||
_num_threads(num_threads), | ||
_num_bytes_per_thread(file_num_bytes / num_threads), | ||
_validate(validate) | ||
{ | ||
} | ||
|
||
char* io_op_desc_t::data_ptr() const { return (char*)_contiguous_buffer.data_ptr(); } | ||
|
||
void io_op_desc_t::finish() {} | ||
|
||
void io_op_desc_t::validate() {} | ||
|
||
void io_op_desc_t::run(const int tid, | ||
std::unique_ptr<aio_context>& aio_ctxt, | ||
deepspeed_aio_config_t* aio_config) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// DeepSpeed Team | ||
|
||
#ifndef _IO_OP_DESC_T_ | ||
#define _IO_OP_DESC_T_ | ||
#include <memory> | ||
#include <queue> | ||
#include "deepspeed_py_aio.h" | ||
|
||
struct io_op_desc_t { | ||
const bool _read_op; | ||
torch::Tensor _buffer; | ||
int _fd; | ||
const std::string _filename; | ||
const long long int _file_num_bytes; | ||
const int _num_threads; | ||
const int _num_bytes_per_thread; | ||
torch::Tensor _contiguous_buffer; | ||
const bool _validate; | ||
|
||
io_op_desc_t(const bool read_op, | ||
const torch::Tensor& buffer, | ||
const int fd, | ||
const char* filename, | ||
const long long int file_num_bytes, | ||
const int num_threads, | ||
const bool validate); | ||
|
||
virtual void run(const int tid, | ||
std::unique_ptr<aio_context>& aio_ctxt, | ||
deepspeed_aio_config_t* aio_config); | ||
|
||
virtual char* data_ptr() const; | ||
|
||
virtual void validate(); | ||
|
||
virtual void finish(); | ||
}; | ||
#endif // _IO_OP_DESC_T_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// DeepSpeed Team | ||
|
||
#include "deepspeed_cpu_op.h" | ||
|
||
using namespace std; | ||
|
||
cpu_op_desc_t::cpu_op_desc_t(const bool read_op, | ||
const torch::Tensor& buffer, | ||
const int fd, | ||
const char* filename, | ||
const long long int file_num_bytes, | ||
const int num_threads, | ||
const bool validate) | ||
: io_op_desc_t(read_op, buffer, fd, filename, file_num_bytes, num_threads, validate), | ||
_cpu_buffer(buffer) | ||
{ | ||
// Need to use CPU bounce buffer if buffer is not a page-locked DRAM memory. | ||
_use_bounce_buffer = !(_buffer.is_cpu() && _buffer.is_pinned()); | ||
if (_use_bounce_buffer) { | ||
if (_read_op) { | ||
auto options = torch::TensorOptions() | ||
.dtype(_buffer.dtype()) | ||
.layout(_buffer.layout()) | ||
.device(torch::kCPU); | ||
_cpu_buffer = torch::empty(_buffer.nbytes(), options).pin_memory(); | ||
} else { | ||
_cpu_buffer = _buffer.to(torch::kCPU).pin_memory(); | ||
} | ||
} | ||
_contiguous_buffer = _cpu_buffer.contiguous(); | ||
} | ||
|
||
char* cpu_op_desc_t::data_ptr() const { return (char*)_contiguous_buffer.data_ptr(); } | ||
|
||
void cpu_op_desc_t::finish() | ||
{ | ||
if (_read_op) { | ||
if (_buffer.is_cuda()) { _buffer.copy_(_cpu_buffer.to(torch::kCUDA)); } | ||
if (_buffer.is_xpu()) { _buffer.copy_(_cpu_buffer.to(torch::kXPU)); } | ||
#if defined(__ENABLE_CANN__) | ||
if (torch_npu::utils::is_npu(_buffer)) { | ||
auto device = at::Device("npu:0"); | ||
_buffer.copy_(_cpu_buffer.to(device)); | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
void cpu_op_desc_t::validate() | ||
{ | ||
validate_aio_operation(_read_op, _filename.c_str(), data_ptr(), _file_num_bytes); | ||
} | ||
|
||
void cpu_op_desc_t::run(const int tid, | ||
std::unique_ptr<aio_context>& aio_ctxt, | ||
deepspeed_aio_config_t* aio_config) | ||
{ | ||
assert(tid < _num_threads); | ||
const auto base_offset = _num_bytes_per_thread * tid; | ||
|
||
std::unique_ptr<io_xfer_ctxt> xfer_ctxt( | ||
new io_xfer_ctxt(_fd, base_offset, _num_bytes_per_thread, data_ptr())); | ||
|
||
if (aio_config->_overlap_events) { | ||
do_aio_operation_overlap(_read_op, aio_ctxt, xfer_ctxt, aio_config, nullptr); | ||
} else { | ||
do_aio_operation_sequential(_read_op, aio_ctxt, xfer_ctxt, aio_config, nullptr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// DeepSpeed Team | ||
|
||
#include <memory> | ||
#include <queue> | ||
#include "deepspeed_aio_op_desc.h" | ||
|
||
struct cpu_op_desc_t : io_op_desc_t { | ||
torch::Tensor _cpu_buffer; | ||
bool _use_bounce_buffer; | ||
|
||
cpu_op_desc_t(const bool read_op, | ||
const torch::Tensor& buffer, | ||
const int fd, | ||
const char* filename, | ||
const long long int file_num_bytes, | ||
const int num_threads, | ||
const bool validate); | ||
|
||
void run(const int tid, | ||
std::unique_ptr<aio_context>& aio_ctxt, | ||
deepspeed_aio_config_t* aio_config); | ||
|
||
char* data_ptr() const; | ||
|
||
void validate(); | ||
|
||
void finish(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.