forked from Samsung/ONE
-
Notifications
You must be signed in to change notification settings - Fork 0
TEST #1
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
Closed
Closed
TEST #1
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d84669e
[onert] Add BulkPipelineBuffer for NPU buffer management (#16330)
batcheu 31acaa4
[onert] Fix Python typing for the benchmark_inference() function (#16…
arkq e248efe
[onert] Add MockSycallManager for customized system call mocking (#16…
batcheu efee6c8
[luci-value-test] Add tolerance for Mean_U8_000 test (#16337)
hseok-oh 413f9e2
[luci-value-test] Add input data logging for test failures (#16338)
hseok-oh 5b5a249
[onert] Implement BulkPipelineModel for Trix model execution (#16332)
batcheu dae2d8a
[onert] Add BulkPipelineManager for multi-model orchestration (#16339)
batcheu e37d6e7
[onert] Refactor header guard and namespace formatting in BulkPipelin…
batcheu d3587cc
[circle-schema] Add MX dtype restrictions comment (#16344)
hseok-oh bbd17bd
[onert] Add BulkPipelineLayer implementation for trix backend (#16343)
batcheu 6816ad7
[onert] Implement pipeline execution for bulk operations
batcheu 1dd4da2
[onert] Implement buffer sharing optimization for BulkPipeline
batcheu 784f6ea
[onert] Add model verification for I/O consistency
batcheu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,167 @@ | ||
| /* | ||
| * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "BulkPipelineBuffer.h" | ||
|
|
||
| #include <fcntl.h> | ||
| #include <sys/ioctl.h> | ||
| #include <sys/mman.h> | ||
| #include <unistd.h> | ||
| #include <cstring> | ||
| #include <iostream> | ||
|
|
||
| namespace onert::backend::trix::ops | ||
| { | ||
|
|
||
| // FIXME: Using higher level API instead of raw API | ||
| struct trix_ioctl_hwmem | ||
| { | ||
| int32_t type; | ||
| uint64_t size; | ||
| int32_t dbuf_fd; | ||
| } __attribute__((packed)); | ||
|
|
||
| #define TRIX_IOCTL_HWMEM_ALLOC _IOW(136, 21, struct trix_ioctl_hwmem) | ||
| #define TRIX_IOCTL_HWMEM_DEALLOC _IOW(136, 22, struct trix_ioctl_hwmem) | ||
|
|
||
| BulkPipelineBuffer::BulkPipelineBuffer(BufferType type, size_t size, int device_id) | ||
| : _type(type), _size(size), _device_id(device_id) | ||
| { | ||
| // DO NOTHING | ||
| } | ||
|
|
||
| BulkPipelineBuffer::~BulkPipelineBuffer() { deallocate(); } | ||
|
|
||
| size_t BulkPipelineBuffer::size() const { return _buffer ? _buffer->size : 0; } | ||
|
|
||
| bool BulkPipelineBuffer::isReady() const { return _buffer && _buffer->addr != nullptr; } | ||
|
|
||
| void BulkPipelineBuffer::allocate() | ||
| { | ||
| if (_buffer && _buffer->addr != nullptr) | ||
| { | ||
| // Already allocated | ||
| return; | ||
| } | ||
|
|
||
| if (!_buffer) | ||
| { | ||
| _buffer = new generic_buffer{}; | ||
| } | ||
|
|
||
| // Open the device | ||
| char devname[16]; | ||
| snprintf(devname, sizeof(devname), "/dev/triv2-%d", _device_id); | ||
| _dev_fd = open(devname, O_RDWR); | ||
| if (_dev_fd < 0) | ||
| { | ||
| throw std::runtime_error("Failed to open NPU device: " + std::string(devname)); | ||
| } | ||
|
|
||
| // Allocate a buffer | ||
| struct trix_ioctl_hwmem hwmem; | ||
| hwmem.type = (_type == BufferType::DMABUF_CONT) ? 0 : 1; | ||
| hwmem.size = getAlignedSize(_size); | ||
|
|
||
| _buffer->dmabuf = ioctl(_dev_fd, TRIX_IOCTL_HWMEM_ALLOC, &hwmem); | ||
| if (_buffer->dmabuf < 0) | ||
| { | ||
| close(_dev_fd); | ||
| _dev_fd = -1; | ||
| throw std::runtime_error("Failed to allocate DMA buffer, size: " + std::to_string(hwmem.size)); | ||
| } | ||
|
|
||
| // Mapping the buffer | ||
| _buffer->addr = mmap(nullptr, hwmem.size, PROT_READ | PROT_WRITE, MAP_SHARED, _buffer->dmabuf, 0); | ||
| if (_buffer->addr == MAP_FAILED) | ||
| { | ||
| close(_buffer->dmabuf); | ||
| close(_dev_fd); | ||
| _buffer->dmabuf = -1; | ||
| _dev_fd = -1; | ||
| _buffer->addr = nullptr; | ||
| throw std::runtime_error("Failed to mmap DMA buffer"); | ||
| } | ||
|
|
||
| _buffer->size = _size; | ||
| _buffer->type = BUFFER_DMABUF; | ||
| } | ||
|
|
||
| void BulkPipelineBuffer::deallocate() | ||
| { | ||
| if (!_buffer) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (_buffer->addr != nullptr) | ||
| { | ||
| size_t aligned_sz = getAlignedSize(_buffer->size); | ||
| munmap(_buffer->addr, aligned_sz); | ||
| _buffer->addr = nullptr; | ||
| } | ||
|
|
||
| if (_buffer->dmabuf >= 0) | ||
| { | ||
| struct trix_ioctl_hwmem hwmem; | ||
| hwmem.dbuf_fd = _buffer->dmabuf; | ||
| ioctl(_dev_fd, TRIX_IOCTL_HWMEM_DEALLOC, &hwmem); | ||
| close(_buffer->dmabuf); | ||
| _buffer->dmabuf = -1; | ||
| } | ||
|
|
||
| if (_dev_fd >= 0) | ||
| { | ||
| close(_dev_fd); | ||
| _dev_fd = -1; | ||
| } | ||
|
|
||
| delete _buffer; | ||
| _buffer = nullptr; | ||
| } | ||
|
|
||
| void BulkPipelineBuffer::fillFromFile(FILE *fp, size_t offset) | ||
| { | ||
| if (!isReady()) | ||
| { | ||
| throw std::runtime_error("Buffer is not allocated"); | ||
| } | ||
|
|
||
| if (!fp) | ||
| { | ||
| throw std::runtime_error("Invalid file pointer"); | ||
| } | ||
|
|
||
| if (fseek(fp, static_cast<long>(offset), SEEK_SET) != 0) | ||
| { | ||
| throw std::runtime_error("Failed to seek file to offset: " + std::to_string(offset)); | ||
| } | ||
|
|
||
| if (fread(_buffer->addr, _buffer->size, 1, fp) != 1) | ||
| { | ||
| throw std::runtime_error("Failed to read " + std::to_string(_buffer->size) + | ||
| " bytes from file"); | ||
| } | ||
| } | ||
|
|
||
| size_t BulkPipelineBuffer::getAlignedSize(size_t size) const | ||
| { | ||
| // 4 KB (= Page size) aligned size | ||
| constexpr size_t _4KB_M_1 = (1 << 12) - 1; | ||
| return (size + _4KB_M_1) & ~_4KB_M_1; | ||
| } | ||
|
|
||
| } // namespace onert::backend::trix::ops | ||
This file contains hidden or 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,69 @@ | ||
| /* | ||
| * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef __ONERT_BACKEND_TRIX_OPS_BULK_PIPELINE_BUFFER_H__ | ||
| #define __ONERT_BACKEND_TRIX_OPS_BULK_PIPELINE_BUFFER_H__ | ||
|
|
||
| #include <memory> | ||
| #include <cstdio> | ||
| #include <stdexcept> | ||
| #include <libnpuhost.h> | ||
|
|
||
| namespace onert::backend::trix::ops | ||
| { | ||
|
|
||
| class BulkPipelineBuffer | ||
| { | ||
| public: | ||
| enum class BufferType | ||
| { | ||
| DMABUF_CONT, // Contiguous DMA buffer | ||
| DMABUF_IOMMU // IOMMU DMA buffer | ||
| }; | ||
|
|
||
| public: | ||
| BulkPipelineBuffer(BufferType type, size_t size, int device_id); | ||
| ~BulkPipelineBuffer(); | ||
|
|
||
| // Disallow copying | ||
| BulkPipelineBuffer(const BulkPipelineBuffer &) = delete; | ||
| BulkPipelineBuffer &operator=(const BulkPipelineBuffer &) = delete; | ||
|
|
||
| // Buffer management functions | ||
| void allocate(); | ||
| void deallocate(); | ||
| size_t size() const; | ||
|
|
||
| generic_buffer *getGenericBuffer() { return _buffer; } | ||
|
|
||
| // Data manipulation functions | ||
| void fillFromFile(FILE *fp, size_t offset = 0); | ||
| bool isReady() const; | ||
|
|
||
| private: | ||
| size_t getAlignedSize(size_t size) const; | ||
|
|
||
| private: | ||
| BufferType _type; | ||
| size_t _size; | ||
| int _device_id; | ||
| int _dev_fd{-1}; | ||
| generic_buffer *_buffer{nullptr}; | ||
| }; | ||
|
|
||
| } // namespace onert::backend::trix::ops | ||
|
|
||
| #endif // __ONERT_BACKEND_TRIX_OPS_BULK_PIPELINE_BUFFER_H__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Return value from
ioctl()not checked correctlyThe code assigns the return value of
ioctl()to_buffer->dmabufand checks if it's negative. However,ioctl()returns-1on error (not the fd). The actual dmabuf fd should come from thehwmem.dbuf_fdfield after a successful call.Prompt To Fix With AI