parent
8784aa3b2f
commit
fa86129228
@ -0,0 +1,41 @@
|
||||
if(ENABLE_GITEE)
|
||||
set(REQ_URL "https://gitee.com/mirrors/Vulkan-Headers/archive/v1.2.166.zip")
|
||||
set(MD5 "8797a525aff953ea536ebe338a9f5ef6")
|
||||
set(PKG_GIT_TAG "")
|
||||
__download_pkg_with_git(Vulkan-Headers ${REQ_URL} ${PKG_GIT_TAG} ${MD5})
|
||||
else()
|
||||
set(REQ_URL "https://github.com/KhronosGroup/Vulkan-Headers/archive/v1.2.166.zip")
|
||||
set(MD5 "91eae880a0ad9ad77c89d79b95b7399a")
|
||||
__download_pkg(Vulkan-Headers ${REQ_URL} ${MD5})
|
||||
endif()
|
||||
|
||||
function(gene_spirv BASEPATH)
|
||||
string(CONCAT CL_SRC_DIR "${BASEPATH}" "/src/runtime/kernel/vulkan/glsl")
|
||||
message(STATUS "**********gene spirv*********base path: " "${BASEPATH}" ", glsl path: " "${CL_SRC_DIR}")
|
||||
if(NOT EXISTS ${CL_SRC_DIR})
|
||||
return()
|
||||
endif()
|
||||
file(GLOB_RECURSE CL_LIST ${CL_SRC_DIR}/*.cl)
|
||||
foreach(file_path ${CL_LIST})
|
||||
file(REMOVE ${file_path}.inc)
|
||||
string(REGEX REPLACE ".+/(.+)\\..*" "\\1" kernel_name "${file_path}")
|
||||
set(inc_file_ex "${kernel_name}.cl.inc")
|
||||
execute_process(
|
||||
COMMAND bash -c "sed 's/\\\\/\\\\\\\\/g' "
|
||||
COMMAND bash -c "sed 's/\\\"/\\\\\\\"/g' "
|
||||
COMMAND bash -c "sed 's/$/\\\\n\\\" \\\\/' "
|
||||
COMMAND bash -c "sed 's/^/\\\"/' "
|
||||
WORKING_DIRECTORY ${CL_SRC_DIR}
|
||||
INPUT_FILE ${file_path}
|
||||
OUTPUT_FILE ${inc_file_ex}
|
||||
RESULT_VARIABLE RESULT)
|
||||
if(NOT RESULT EQUAL "0")
|
||||
message(FATAL_ERROR "error! when generate ${inc_file_ex}")
|
||||
endif()
|
||||
__exec_cmd(COMMAND sed -i
|
||||
"1i\\static const char *${kernel_name}_source =\\\"\\\\n\\\" \\\\"
|
||||
${inc_file_ex} WORKING_DIRECTORY ${CL_SRC_DIR}
|
||||
)
|
||||
__exec_cmd(COMMAND sed -i "$a\\\\\;" ${inc_file_ex} WORKING_DIRECTORY ${CL_SRC_DIR})
|
||||
endforeach()
|
||||
endfunction()
|
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "src/runtime/gpu/cuda/cuda_device.h"
|
||||
#include <unordered_set>
|
||||
|
||||
namespace mindspore::lite::cuda {
|
||||
CudaDevice::~CudaDevice() {}
|
||||
} // namespace mindspore::lite::cuda
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 MINDSPORE_LITE_SRC_CUDA_DEVICE_H_
|
||||
#define MINDSPORE_LITE_SRC_CUDA_DEVICE_H_
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <assert.h>
|
||||
#include <exception>
|
||||
#include <algorithm>
|
||||
#include "src/runtime/gpu/gpu_runtime.h"
|
||||
|
||||
namespace mindspore::lite::cuda {
|
||||
class CudaDevice {
|
||||
public:
|
||||
CudaDevice() {}
|
||||
virtual ~CudaDevice();
|
||||
};
|
||||
} // namespace mindspore::lite::cuda
|
||||
#endif // MINDSPORE_LITE_SRC_CUDA_DEVICE_H_
|
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "src/runtime/gpu/cuda/cuda_runtime.h"
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include "include/errorcode.h"
|
||||
#include "src/common/file_utils.h"
|
||||
|
||||
namespace mindspore::lite::cuda {
|
||||
|
||||
static std::mutex g_mtx;
|
||||
|
||||
bool CudaRuntime::initialized_ = false;
|
||||
uint32_t CudaRuntime::instance_count_ = 0;
|
||||
CudaRuntime *CudaRuntime::cuda_runtime_instance_ = nullptr;
|
||||
|
||||
CudaRuntime *CudaRuntime::GetInstance() {
|
||||
std::unique_lock<std::mutex> lck(g_mtx);
|
||||
static CudaRuntime vk_runtime;
|
||||
if (instance_count_ == 0) {
|
||||
cuda_runtime_instance_ = &vk_runtime;
|
||||
cuda_runtime_instance_->Init();
|
||||
}
|
||||
instance_count_++;
|
||||
return cuda_runtime_instance_;
|
||||
}
|
||||
|
||||
void CudaRuntime::DeleteInstance() {
|
||||
std::unique_lock<std::mutex> lck(g_mtx);
|
||||
if (instance_count_ == 0) {
|
||||
MS_LOG(ERROR) << "No VulkanRuntime instance could delete!";
|
||||
}
|
||||
instance_count_--;
|
||||
if (instance_count_ == 0) {
|
||||
cuda_runtime_instance_->Uninit();
|
||||
}
|
||||
}
|
||||
|
||||
CudaRuntime::CudaRuntime() {}
|
||||
|
||||
// Init will get platforms info, get devices info, create opencl context.
|
||||
int CudaRuntime::Init() {
|
||||
if (initialized_) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
initialized_ = true;
|
||||
MS_LOG(INFO) << "CudaRuntime init done!";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CudaRuntime::Uninit() {
|
||||
if (!initialized_) {
|
||||
return RET_OK;
|
||||
}
|
||||
initialized_ = false;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
CudaRuntime::~CudaRuntime() { Uninit(); }
|
||||
|
||||
const GpuInfo &CudaRuntime::GetGpuInfo() { return gpu_info_; }
|
||||
bool CudaRuntime::GetFp16Enable() const { return true; }
|
||||
|
||||
} // namespace mindspore::lite::cuda
|
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 MINDSPORE_LITE_SRC_CUDA_RUNTIME_H_
|
||||
#define MINDSPORE_LITE_SRC_CUDA_RUNTIME_H_
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include "src/common/log_adapter.h"
|
||||
#include "src/runtime/gpu/gpu_runtime.h"
|
||||
#include "schema/gpu_cache_generated.h"
|
||||
|
||||
using mindspore::lite::gpu::GpuInfo;
|
||||
using mindspore::lite::gpu::GpuRuntime;
|
||||
using mindspore::lite::gpu::GpuRuntimeWrapper;
|
||||
|
||||
namespace mindspore::lite::cuda {
|
||||
|
||||
class CudaRuntime : public GpuRuntime {
|
||||
public:
|
||||
friend GpuRuntimeWrapper<CudaRuntime>;
|
||||
~CudaRuntime() override;
|
||||
CudaRuntime(const CudaRuntime &) = delete;
|
||||
CudaRuntime &operator=(const CudaRuntime &) = delete;
|
||||
|
||||
int Init() override;
|
||||
int Uninit() override;
|
||||
const GpuInfo &GetGpuInfo() override;
|
||||
bool GetFp16Enable() const override;
|
||||
|
||||
static CudaRuntime *GetInstance();
|
||||
static void DeleteInstance();
|
||||
|
||||
private:
|
||||
CudaRuntime();
|
||||
|
||||
private:
|
||||
static bool initialized_;
|
||||
static uint32_t instance_count_;
|
||||
static CudaRuntime *cuda_runtime_instance_;
|
||||
};
|
||||
} // namespace mindspore::lite::cuda
|
||||
#endif // MINDSPORE_LITE_SRC_CUDA_RUNTIME_H_
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "src/runtime/gpu/gpu_runtime.h"
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
#include <mutex>
|
||||
#ifdef SHARING_MEM_WITH_OPENGL
|
||||
#include <EGL/egl.h>
|
||||
#endif
|
||||
#include "include/errorcode.h"
|
||||
#include "src/common/file_utils.h"
|
||||
|
||||
namespace mindspore::lite::gpu {
|
||||
|
||||
const GpuInfo &GpuRuntime::GetGpuInfo() { return gpu_info_; }
|
||||
|
||||
} // namespace mindspore::lite::gpu
|
@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 MINDSPORE_LITE_SRC_GPU_RUNTIME_H_
|
||||
#define MINDSPORE_LITE_SRC_GPU_RUNTIME_H_
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include "include/errorcode.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
#include "src/runtime/allocator.h"
|
||||
#include "schema/gpu_cache_generated.h"
|
||||
|
||||
namespace mindspore::lite::gpu {
|
||||
|
||||
enum GpuType { OTHER = 0, ADRENO = 1, MALI = 2, MALI_T = 3, MALI_G = 4 };
|
||||
struct GpuInfo {
|
||||
GpuType type = OTHER;
|
||||
int model_num = 0;
|
||||
float version = 0;
|
||||
uint64_t global_memery_cachesize{0};
|
||||
uint64_t global_memery_size{0};
|
||||
uint64_t max_alloc_size{0};
|
||||
uint32_t max_work_group_size{1};
|
||||
uint32_t compute_units{0};
|
||||
uint32_t max_freq{0};
|
||||
uint32_t image_pitch_align{0};
|
||||
std::vector<size_t> max_work_item_sizes;
|
||||
bool support_fp16{false};
|
||||
bool support_svm{false};
|
||||
};
|
||||
enum class GpuBackendType { OPENCL = 0, CUDA = 1, VULKAN = 2 };
|
||||
class DevKey {
|
||||
public:
|
||||
std::string name{""};
|
||||
};
|
||||
class GpuContext {
|
||||
public:
|
||||
GpuBackendType type;
|
||||
};
|
||||
class GpuDevice {
|
||||
public:
|
||||
GpuDevice();
|
||||
~GpuDevice();
|
||||
};
|
||||
class DevKernel {
|
||||
public:
|
||||
void *data{nullptr};
|
||||
};
|
||||
class GpuAllocator : public Allocator {};
|
||||
class GpuRuntime {
|
||||
public:
|
||||
GpuRuntime() {}
|
||||
virtual ~GpuRuntime() {}
|
||||
GpuRuntime(const GpuRuntime &) = delete;
|
||||
GpuRuntime &operator=(const GpuRuntime &) = delete;
|
||||
|
||||
virtual int Init() { return RET_ERROR; }
|
||||
virtual int Uninit() { return RET_ERROR; }
|
||||
virtual const GpuInfo &GetGpuInfo() = 0;
|
||||
virtual bool GetFp16Enable() const = 0;
|
||||
|
||||
uint64_t GetGlobalMemSize() const { return gpu_info_.global_memery_size; }
|
||||
uint64_t GetMaxAllocSize() const { return gpu_info_.max_alloc_size; }
|
||||
const std::vector<size_t> &GetWorkItemSize() const { return gpu_info_.max_work_item_sizes; }
|
||||
|
||||
protected:
|
||||
// gpu hal native defines
|
||||
std::unordered_map<std::string, DevKernel *> dev_kernels_;
|
||||
GpuContext *context_{nullptr};
|
||||
GpuDevice *device_{nullptr};
|
||||
GpuInfo gpu_info_;
|
||||
|
||||
private:
|
||||
};
|
||||
template <class T>
|
||||
class GpuRuntimeWrapper {
|
||||
public:
|
||||
GpuRuntimeWrapper() { gpu_runtime_ = T::GetInstance(); }
|
||||
~GpuRuntimeWrapper() { T::DeleteInstance(); }
|
||||
GpuRuntimeWrapper(const GpuRuntimeWrapper &) = delete;
|
||||
GpuRuntimeWrapper &operator=(const GpuRuntimeWrapper &) = delete;
|
||||
T *GetInstance() { return gpu_runtime_; }
|
||||
|
||||
private:
|
||||
T *gpu_runtime_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace mindspore::lite::gpu
|
||||
#endif // MINDSPORE_LITE_SRC_GPU_RUNTIME_H_
|
@ -0,0 +1,6 @@
|
||||
file(GLOB_RECURSE CUDA_KERNEL_SRC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kernel/*.cc)
|
||||
add_library(cuda_kernel_mid OBJECT ${CUDA_KERNEL_SRC})
|
||||
add_dependencies(cuda_kernel_mid fbs_src)
|
||||
|
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "src/runtime/kernel/cuda/cuda_kernel.h"
|
||||
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
|
||||
namespace mindspore::kernel {} // namespace mindspore::kernel
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 MINDSPORE_LITE_SRC_CUDA_KERNEL_H_
|
||||
#define MINDSPORE_LITE_SRC_CUDA_KERNEL_H_
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "src/lite_kernel.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "src/runtime/gpu/gpu_runtime.h"
|
||||
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
|
||||
namespace mindspore::kernel {} // namespace mindspore::kernel
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_CUDA_KERNEL_H_
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "src/runtime/kernel/cuda/cuda_subgraph.h"
|
||||
#include <set>
|
||||
#include "include/errorcode.h"
|
||||
#include "src/common/utils.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
|
||||
} // namespace mindspore::kernel
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CUDA_KERNEL_CUDA_SUBGRAPH_KERNEL_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CUDA_KERNEL_CUDA_SUBGRAPH_KERNEL_H_
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "src/sub_graph_kernel.h"
|
||||
|
||||
namespace mindspore::kernel {} // namespace mindspore::kernel
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CUDA_KERNEL_CUDA_SUBGRAPH_KERNEL_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue