Skip to content

Commit

Permalink
add dummy impl for LowerToSPIRV in case vulkan is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
masahi committed May 7, 2023
1 parent 715e5de commit d70c2eb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmake/modules/OpenCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ endif(USE_AOCL)

if(USE_OPENCL)
tvm_file_glob(GLOB RUNTIME_OPENCL_SRCS src/runtime/opencl/*.cc)
list(APPEND COMPILER_SRCS src/target/spirv/spirv_utils.cc)

if(${USE_OPENCL} MATCHES ${IS_TRUE_PATTERN})
message(STATUS "Enabled runtime search for OpenCL library location")
Expand Down
1 change: 1 addition & 0 deletions cmake/modules/Vulkan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ if(USE_VULKAN)
list(APPEND COMPILER_SRCS ${COMPILER_VULKAN_SRCS})
list(APPEND TVM_LINKER_LIBS ${Vulkan_SPIRV_TOOLS_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${Vulkan_LIBRARY})
add_definitions(-DTVM_USE_VULKAN=1)
endif(USE_VULKAN)
6 changes: 3 additions & 3 deletions src/runtime/vulkan/spirv_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_VULKAN_VULKAN_SHADER_H_
#define TVM_RUNTIME_VULKAN_VULKAN_SHADER_H_
#ifndef TVM_RUNTIME_VULKAN_SPIRV_SHADER_H_
#define TVM_RUNTIME_VULKAN_SPIRV_SHADER_H_

#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/device_api.h>
Expand Down Expand Up @@ -57,4 +57,4 @@ using vulkan::SPIRVShader;
namespace dmlc {
DMLC_DECLARE_TRAITS(has_saveload, ::tvm::runtime::vulkan::SPIRVShader, true);
} // namespace dmlc
#endif // TVM_RUNTIME_VULKAN_VULKAN_SHADER_H_
#endif // TVM_RUNTIME_VULKAN_SPIRV_SHADER_H_
24 changes: 21 additions & 3 deletions src/target/spirv/spirv_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@
* \brief Build SPIRV block
*/
// Use libspirv for parsing and validating code.
#include <dmlc/memory_io.h>
#include "spirv_utils.h"

#if TVM_USE_VULKAN
#include <libspirv.h>

#include "codegen_spirv.h"
#endif

#include <tvm/tir/transform.h>

#include <algorithm>
#include <fstream>
#include <sstream>
#include <vector>

#include "../../runtime/vulkan/spirv_shader.h"
#include "../../support/utils.h"
#include "codegen_spirv.h"
#include "spirv_utils.h"

namespace tvm {
namespace codegen {

#if TVM_USE_VULKAN

class SPIRVTools {
public:
explicit SPIRVTools(Target target) {
Expand Down Expand Up @@ -166,5 +174,15 @@ std::pair<std::unordered_map<std::string, runtime::SPIRVShader>, std::string> Lo
return std::make_pair(smap, code_data.str());
}

#else

std::pair<std::unordered_map<std::string, runtime::SPIRVShader>, std::string> LowerToSPIRV(
IRModule mod, Target target) {
LOG(FATAL) << "LowerToSPIRV is called but Vulkan is not enabled.";
return {};
}

#endif

} // namespace codegen
} // namespace tvm
1 change: 1 addition & 0 deletions src/target/spirv/spirv_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <string>
#include <unordered_map>
#include <utility>

#include "../../runtime/vulkan/spirv_shader.h"

Expand Down

0 comments on commit d70c2eb

Please sign in to comment.