-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Adding support for Hexagon User DMA Engine #10217
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba1f6e3
initial hexagon user dma impl
adstraw 75fe422
Hexagon User DMA descriptor, instruction and register headers
adstraw 9387827
Synchronous 1D DMA working
adstraw 7b53e94
HexagonBuffer unit tests passing with memcpy
adstraw a74d73b
cleanup
adstraw 8fc0281
comments and orgnanize code
adstraw 5e12171
format and lint
adstraw cad1d3e
init function + other code review feedback
adstraw bfce91e
Merge branch 'main' into hexagon-user-dma-1d-sync
adstraw 6db3915
add ifdef hexagon around inline asm
adstraw 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 <algorithm> | ||
|
|
||
| #include "hexagon_common.h" | ||
| #include "hexagon_user_dma_descriptors.h" | ||
| #include "hexagon_user_dma_instructions.h" | ||
| #include "hexagon_user_dma_registers.h" | ||
|
|
||
| namespace tvm { | ||
| namespace runtime { | ||
| namespace hexagon { | ||
|
|
||
| int hexagon_user_dma_1d_sync(void* dst, void* src, uint32_t length) { | ||
| #if defined(__hexagon__) | ||
| // not thread safe | ||
| static int config_dma = 0; | ||
| if (!config_dma) { | ||
| // register configuraiton to go here | ||
| // reset DMA engine | ||
| unsigned int status = dmpause() & DM0_STATUS_MASK; | ||
| if (status != DM0_STATUS_IDLE) { | ||
| return DMA_FAILURE; | ||
| } | ||
| config_dma = 1; | ||
| } | ||
|
|
||
| void* dma_desc = nullptr; | ||
|
|
||
| #ifdef _WIN32 | ||
| dma_desc = _aligned_malloc(DMA_DESC_2D_SIZE, DMA_DESC_2D_SIZE); | ||
| #else | ||
| int ret = posix_memalign(&dma_desc, DMA_DESC_2D_SIZE, DMA_DESC_2D_SIZE); | ||
| if (ret) { | ||
| return DMA_FAILURE; | ||
| } | ||
| #endif | ||
|
|
||
| if (!dma_desc) { | ||
| return DMA_FAILURE; | ||
| } | ||
|
|
||
| uint64_t src64 = reinterpret_cast<uint64_t>(src); | ||
| // source address limited to 32 bits | ||
| if (src64 > DESC_SRC_MASK) { | ||
| return DMA_FAILURE; | ||
| } | ||
|
|
||
| uint64_t dst64 = reinterpret_cast<uint64_t>(dst); | ||
| // destination address limited to 32 bits | ||
| if (dst64 > DESC_DST_MASK) { | ||
| return DMA_FAILURE; | ||
| } | ||
|
|
||
| // length limited to 24 bits | ||
| if (length > DESC_LENGTH_MASK) { | ||
| return DMA_FAILURE; | ||
| } | ||
|
|
||
| uint32_t src32 = src64 & DESC_SRC_MASK; | ||
| uint32_t dst32 = dst64 & DESC_DST_MASK; | ||
|
|
||
| dma_desc_set_next(dma_desc, DMA_NULL_PTR); | ||
| dma_desc_set_length(dma_desc, length); | ||
| dma_desc_set_desctype(dma_desc, DESC_DESCTYPE_1D); | ||
| dma_desc_set_dstcomp(dma_desc, DESC_COMP_NONE); | ||
| dma_desc_set_srccomp(dma_desc, DESC_COMP_NONE); | ||
| dma_desc_set_bypassdst(dma_desc, DESC_BYPASS_OFF); | ||
| dma_desc_set_bypasssrc(dma_desc, DESC_BYPASS_OFF); | ||
| dma_desc_set_order(dma_desc, DESC_ORDER_ORDER); | ||
| dma_desc_set_dstate(dma_desc, DESC_DSTATE_INCOMPLETE); | ||
| dma_desc_set_src(dma_desc, src32); | ||
| dma_desc_set_dst(dma_desc, dst32); | ||
|
|
||
| dmstart(dma_desc); | ||
| unsigned int status = dmwait() & DM0_STATUS_MASK; | ||
| unsigned int done = dma_desc_get_dstate(dma_desc); | ||
|
|
||
| #ifdef _WIN32 | ||
| _aligned_free(dma_desc); | ||
| #else | ||
| free(dma_desc); | ||
| #endif | ||
|
|
||
| if (status == DM0_STATUS_IDLE && done == DESC_DSTATE_COMPLETE) { | ||
| return DMA_SUCCESS; | ||
| } | ||
| return DMA_FAILURE; | ||
| #else | ||
| memcpy(dst, src, length); | ||
| return DMA_SUCCESS; | ||
| #endif | ||
| } | ||
|
|
||
| } // namespace hexagon | ||
| } // namespace runtime | ||
| } // namespace tvm | ||
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.
Uh oh!
There was an error while loading. Please reload this page.