This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,608 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
schedules: | ||
- cron: "0 0 * * *" | ||
displayName: Daily midnight check | ||
branches: | ||
include: | ||
- main | ||
|
||
pool: | ||
vmImage: ubuntu-latest | ||
|
||
steps: | ||
- script: | | ||
git config --global user.email "nnfusion_team@microsoft.com" | ||
git config --global user.name "NNFusion team" | ||
git config pull.rebase false | ||
git checkout origin main | ||
git checkout main | ||
git remote add tvm https://github.com/apache/tvm.git | ||
git pull tvm main | ||
git push https://${PAT}:PAT@dev.azure.com/TensorStar/TensorStar/_git/tvm main | ||
displayName: 'Add apache/tvm as new origin' |
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,20 @@ | ||
trigger: | ||
- develop | ||
|
||
pool: Default | ||
|
||
steps: | ||
- checkout: self | ||
submodules: true | ||
persistCredentials: true | ||
- task: PowerShell@2 | ||
inputs: | ||
targetType: 'inline' | ||
script: | | ||
F:\tool\vcpkg\vcpkg.exe install gtest:x64-windows | ||
- task: CMake@1 | ||
inputs: | ||
cmakeArgs: '.. -DUSE_DIRECTX=ON -DCMAKE_TOOLCHAIN_FILE="F:/tool/vcpkg/scripts/buildsystems/vcpkg.cmake"' | ||
- task: CMake@1 | ||
inputs: | ||
cmakeArgs: '--build . -j' |
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
Submodule DirectX-Headers
added at
0644e7
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,32 @@ | ||
# 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. | ||
|
||
# DirectX Module | ||
|
||
if(USE_DIRECTX) | ||
message(STATUS "Build with DirectX support") | ||
file(GLOB RUNTIME_DIRECTX_SRCS src/runtime/directx/*.cc) | ||
list(APPEND RUNTIME_SRCS ${RUNTIME_DIRECTX_SRCS}) | ||
if(GTEST_FOUND) | ||
file(GLOB RUNTIME_TEST_DIRECTX_SRCS src/runtime/directx/test/*.cc) | ||
add_executable(dx_test ${RUNTIME_TEST_DIRECTX_SRCS}) | ||
target_link_libraries(dx_test tvm_libinfo_objs tvm_objs tvm_runtime_objs GTest::GTest GTest::Main) | ||
gtest_discover_tests(dx_test) | ||
endif() | ||
else() | ||
list(APPEND COMPILER_SRCS src/target/opt/build_directx_off.cc) | ||
endif(USE_DIRECTX) |
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
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,123 @@ | ||
#include "directx_header.h" | ||
|
||
using namespace tvm::runtime::dx; | ||
|
||
DirectBuffer::DirectBuffer(DirectXDevice* _dev, UINT64 size, DLDataType type) : _dxdev(_dev) { | ||
_res = _dev->device_allocate(size); | ||
D3D12_RESOURCE_DESC desc = _res->GetDesc(); | ||
this->size = desc.Width; | ||
this->type = type; | ||
} | ||
|
||
DirectBuffer::DirectBuffer(DirectXDevice* _dev, ComPtr<ID3D12Resource> res, DLDataType type) | ||
: _dxdev(_dev), _res(res) { | ||
D3D12_RESOURCE_DESC desc = _res->GetDesc(); | ||
this->size = desc.Width; | ||
this->type = type; | ||
} | ||
|
||
DirectHostBuffer::DirectHostBuffer(DirectXDevice* _dev, UINT64 size, DLDataType type, hostbuffer_state state) | ||
: _cur_state(state), ptr(nullptr) { | ||
if (state == hostbuffer_state::upload) | ||
_host_res = _dev->upload_allocate(size); | ||
else if (state == hostbuffer_state::readback) | ||
_host_res = _dev->readback_allocate(size); | ||
else | ||
throw std::invalid_argument(_msg_("Buffer state is not supported")); | ||
D3D12_RESOURCE_DESC desc = _host_res->GetDesc(); | ||
this->size = desc.Width; | ||
range = {0, static_cast<SIZE_T>(size)}; | ||
_dxdev = _dev; | ||
this->type = type; | ||
} | ||
|
||
void* DirectHostBuffer::open_data_ptr() { | ||
if (ptr != nullptr) return ptr; | ||
ThrowIfFailed(_host_res->Map(0, &range, reinterpret_cast<void**>(&ptr))); | ||
return ptr; | ||
} | ||
|
||
void DirectHostBuffer::close_data_ptr() { | ||
ptr = nullptr; | ||
if (_cur_state == hostbuffer_state::readback) | ||
// Use begin = end to tell no data is changed; | ||
{ | ||
D3D12_RANGE range = {0, 0}; | ||
_host_res->Unmap(0, &range); | ||
} else | ||
_host_res->Unmap(0, &range); | ||
} | ||
|
||
// todo(wenxh): use resource barrier to support call this transition in async way; | ||
void DirectHostBuffer::change_state(hostbuffer_state hs) { | ||
if (hs == _cur_state) return; | ||
D3D12_RESOURCE_DESC desc = _host_res->GetDesc(); | ||
if (hs == hostbuffer_state::upload) { | ||
// readback to upload, need to memcpy | ||
auto tgt = _dxdev->upload_allocate(size); | ||
// cpu memcpy | ||
{ | ||
// open ptr | ||
void* t_ptr = nullptr; | ||
ThrowIfFailed(tgt->Map(0, &range, reinterpret_cast<void**>(&t_ptr))); | ||
open_data_ptr(); | ||
memcpy(t_ptr, ptr, size); | ||
|
||
// close ptr | ||
close_data_ptr(); | ||
tgt->Unmap(0, &range); | ||
} | ||
|
||
_host_res = tgt; | ||
} else if (hs == hostbuffer_state::readback) { | ||
close_data_ptr(); | ||
auto tgt = _dxdev->readback_allocate(size); | ||
_dxdev->copy(tgt, _host_res); | ||
_host_res = tgt; | ||
} else { | ||
throw std::invalid_argument(_msg_("Target buffer state is not supported.")); | ||
} | ||
_cur_state = hs; | ||
} | ||
|
||
DirectReadBackBuffer::DirectReadBackBuffer(DirectXDevice* _dev, UINT64 size, DLDataType type) | ||
: DirectBuffer(_dev, size, type) { | ||
_host_res = _dev->readback_allocate(size); | ||
range = {0, static_cast<SIZE_T>(size)}; | ||
this->ptr = nullptr; | ||
} | ||
|
||
void* DirectReadBackBuffer::open_data_ptr() { | ||
if (ptr != nullptr) return ptr; | ||
ThrowIfFailed(_host_res->Map(0, &range, reinterpret_cast<void**>(&ptr))); | ||
return ptr; | ||
} | ||
|
||
void DirectReadBackBuffer::to_host(bool async) { _dxdev->copy(_host_res, _res, async); } | ||
|
||
void DirectReadBackBuffer::close_data_ptr() { | ||
ptr = nullptr; | ||
// Use begin = end to tell no data is changed; | ||
D3D12_RANGE range = {0, 0}; | ||
_host_res->Unmap(0, &range); | ||
} | ||
|
||
DirectUploadBuffer::DirectUploadBuffer(DirectXDevice* _dev, UINT64 size, DLDataType type) | ||
: DirectBuffer(_dev, size, type) { | ||
_host_res = _dev->upload_allocate(size); | ||
range = {0, static_cast<SIZE_T>(size)}; | ||
this->ptr = nullptr; | ||
} | ||
|
||
void* DirectUploadBuffer::open_data_ptr() { | ||
if (ptr != nullptr) return ptr; | ||
ThrowIfFailed(_host_res->Map(0, &range, reinterpret_cast<void**>(&ptr))); | ||
return ptr; | ||
} | ||
|
||
void DirectUploadBuffer::close_data_ptr() { | ||
ptr = nullptr; | ||
_host_res->Unmap(0, &range); | ||
} | ||
|
||
void DirectUploadBuffer::to_device(bool async) { _dxdev->copy(_res, _host_res, async); } |
Oops, something went wrong.