Skip to content

Commit

Permalink
Merge branch 'master' into loop_inv
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-hitonami committed Sep 20, 2022
2 parents 18b0747 + 966f7fa commit f8ce5e8
Show file tree
Hide file tree
Showing 105 changed files with 2,269 additions and 789 deletions.
18 changes: 2 additions & 16 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
Related issue = #
Issue: #

<!--
Thank you for your contribution!
If it is your first time contributing to Taichi, please read our Contributor Guidelines:
https://docs.taichi-lang.org/docs/contributor_guide
- Please always prepend your PR title with tags such as [CUDA], [Lang], [Doc], [Example]. For a complete list of valid PR tags, please check out https://github.com/taichi-dev/taichi/blob/master/misc/prtags.json.
- Use upper-case tags (e.g., [Metal]) for PRs that change public APIs. Otherwise, please use lower-case tags (e.g., [metal]).
- More details: https://docs.taichi-lang.org/docs/contributor_guide#pr-title-format-and-tags
- Please fill in the issue number that this PR relates to.
- If your PR fixes the issue **completely**, use the `close` or `fixes` prefix so that GitHub automatically closes the issue when the PR is merged. For example,
Related issue = close #2345
- If the PR does not belong to any existing issue, free to leave it blank.
-->
### Brief Summary
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
mkdir -m777 shared
docker create --user dev --name taichi_build --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY -e PY -e GPU_BUILD -e TAICHI_CMAKE_ARGS -e PROJECT_NAME \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.2 \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.4 \
/home/dev/taichi/.github/workflows/scripts/unix_build.sh
tar -cf - ../${{ github.event.repository.name }} --mode u=+rwx,g=+rwx,o=+rwx --owner 1000 --group 1000 | docker cp - taichi_build:/home/dev/
docker start -a taichi_build
Expand All @@ -111,7 +111,7 @@ jobs:
run: |
docker create --user dev --name taichi_test --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY -e PY -e GPU_TEST \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.2 \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.4 \
/home/dev/unix_test.sh
docker cp .github/workflows/scripts/unix_test.sh taichi_test:/home/dev/unix_test.sh
docker cp .github/workflows/scripts/common-utils.sh taichi_test:/home/dev/common-utils.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/win_build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if (!$llvmVer.CompareTo("10")) {
} else {
if (-not (Test-Path "taichi_llvm_15")) {
WriteInfo("Download and extract LLVM")
curl.exe --retry 10 --retry-delay 5 https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang_220731/taichi-llvm-15.0.0-msvc2019.zip -LO
curl.exe --retry 10 --retry-delay 5 https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang/taichi-llvm-15.0.0-msvc2019.zip -LO
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE; }
7z x taichi-llvm-15.0.0-msvc2019.zip -otaichi_llvm_15
}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scripts/win_build_test_cpu.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ if (!$llvmVer.CompareTo("10")) {
} else {
$env:TAICHI_CMAKE_ARGS += " -DLLVM_AS_EXECUTABLE=C:\\taichi_llvm_15\\bin\\llvm-as.exe -DTI_WITH_VULKAN:BOOL=OFF"
$env:TAICHI_CMAKE_ARGS += " -DTI_LLVM_15:BOOL=ON"
$env:TAICHI_CMAKE_ARGS += " -DTI_WITH_DX12:BOOL=ON"
}


Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
python: 3.7
with_cc: OFF
with_cpp_tests: ON
wanted_archs: 'cpu'
wanted_archs: 'cpu,vulkan'
runs-on:
- self-hosted
- ${{ matrix.os }}
Expand Down Expand Up @@ -405,7 +405,7 @@ jobs:
--gpus 'all,"capabilities=graphics,utility,display,video,compute"' \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e PY -e GPU_BUILD -e PROJECT_NAME -e TAICHI_CMAKE_ARGS -e DISPLAY \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.3 \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.4 \
/home/dev/taichi/.github/workflows/scripts/unix_build.sh
# A tarball is needed because sccache needs some permissions that only the file owner has.
# 1000 is the uid and gid of user "dev" in the container.
Expand Down Expand Up @@ -444,7 +444,7 @@ jobs:
-e TI_LITE_TEST \
-e TI_TEST_OFFLINE_CACHE \
-e DISPLAY -e PY -e GPU_TEST -e TI_WANTED_ARCHS -e TI_RUN_RELEASE_TESTS \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.3 \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.4 \
/home/dev/unix_test.sh
docker cp .github/workflows/scripts/unix_test.sh taichi_test:/home/dev/unix_test.sh
docker cp .github/workflows/scripts/common-utils.sh taichi_test:/home/dev/common-utils.sh
Expand Down Expand Up @@ -671,7 +671,7 @@ jobs:
docker run --user dev --name taichi_build_host \
$DOCKER_RUN_ARGS \
-v $TAICHI_WHEEL_DIR:/home/dev/taichi/dist \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.3 \
registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.4 \
/home/dev/taichi/.github/workflows/scripts/unix-build-v2.sh
env:
TAICHI_CMAKE_ARGS: >-
Expand Down
27 changes: 9 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ cmake_minimum_required(VERSION 3.17)

project(taichi)

# Taichi does not set target architecture explicitly,
# but rather rely on CMake to detect the host arch.
#
# However on Mac m1, there are two available architectures namely x86_64 and arm64.
# On some combination of "OSX version" and "CMake version", CMake will use x86_64 as default architecture even if it's on m1 chip.
# This causes conflicts with the precompiled LLVM/Clang binaries downloaded from Taichi's repo (pre-built for arm64)
#
# Therefore we force CMake to choose arm64 architecture on arm64 chips.
if (APPLE)
if( "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "arm64" )
set(CMAKE_OSX_ARCHITECTURES ${CMAKE_HOST_SYSTEM_PROCESSOR})
endif()
endif()

if (NOT DEFINED TI_VERSION_MAJOR)
message(WARNING "It seems that you are running cmake manually, which may cause issues. Please use setup.py to build taichi from source, see https://docs.taichi-lang.org/docs/dev_install for more details.")
set(TI_VERSION_MAJOR 0)
Expand Down Expand Up @@ -117,15 +103,12 @@ if (TI_BUILD_TESTS)
endif()

option(TI_BUILD_EXAMPLES "Build the CPP examples" ON)
option(TI_BUILD_RHI_EXAMPLES "Build the Unified Device API examples" OFF)

if(NOT TI_WITH_LLVM OR NOT TI_WITH_METAL)
set(TI_BUILD_EXAMPLES OFF)
endif()

if (TI_BUILD_EXAMPLES)
include(cmake/TaichiExamples.cmake)
endif()

message("C++ Flags: ${CMAKE_CXX_FLAGS}")
message("Build type: ${CMAKE_BUILD_TYPE}")

Expand Down Expand Up @@ -216,6 +199,14 @@ if (TI_WITH_C_API)
endif()
endif()

if (TI_BUILD_EXAMPLES)
include(cmake/TaichiExamples.cmake)
endif()

if (TI_BUILD_RHI_EXAMPLES)
add_subdirectory(cpp_examples/rhi_examples)
endif()


option(TI_WITH_GRAPHVIZ "generate dependency graphs between targets" OFF)
if (TI_WITH_GRAPHVIZ)
Expand Down
1 change: 1 addition & 0 deletions c_api/include/taichi/cpp/taichi.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// C++ wrapper of Taichi C-API
#pragma once
#include <cstring>
#include <list>
#include <vector>
Expand Down
18 changes: 9 additions & 9 deletions ci/Dockerfile.ubuntu.18.04
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh &
bash Miniconda3-latest-Linux-x86_64.sh -p /home/dev/miniconda -b
ENV PATH="/home/dev/miniconda/bin:$PATH"

# Set up multi-python environment
RUN conda init bash
RUN conda create -n py36 python=3.6 pytorch cudatoolkit=10.2 -c pytorch -y
RUN conda create -n py37 python=3.7 pytorch cudatoolkit=10.2 -c pytorch -y
RUN conda create -n py38 python=3.8 pytorch cudatoolkit=10.2 -c pytorch -y
RUN conda create -n py39 python=3.9 pytorch cudatoolkit=10.2 -c pytorch -y
# TODO add torch to 3.10 when supported
RUN conda create -n py310 python=3.10 -y

# Remove mesa EGL driver, which interferes with the propritary NVIDIA drivers
RUN rm -f /usr/lib/x86_64-linux-gnu/libEGL_mesa*

WORKDIR /home/dev
ENV LANG="C.UTF-8"

# Set up multi-python environment
RUN conda init bash
RUN conda create -n py36 python=3.6 pytorch cudatoolkit=11.3 -c pytorch -y
RUN conda create -n py37 python=3.7 pytorch cudatoolkit=11.3 -c pytorch -y
RUN conda create -n py38 python=3.8 pytorch cudatoolkit=11.3 -c pytorch -y
RUN conda create -n py39 python=3.9 pytorch cudatoolkit=11.3 -c pytorch -y
# TODO add torch to 3.10 when supported
RUN conda create -n py310 python=3.10 -y
2 changes: 1 addition & 1 deletion ci/windows/win_build_test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (!$llvmVer.CompareTo("10")) {
} else {
if (-not (Test-Path "taichi_llvm_15")) {
WriteInfo("Download and extract LLVM")
curl.exe --retry 10 --retry-delay 5 https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang_220731/taichi-llvm-15.0.0-msvc2019.zip -LO
curl.exe --retry 10 --retry-delay 5 https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang/taichi-llvm-15.0.0-msvc2019.zip -LO
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE; }
7z x taichi-llvm-15.0.0-msvc2019.zip -otaichi_llvm_15
}
Expand Down
11 changes: 9 additions & 2 deletions cmake/TaichiCXXFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}"
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"TI_ARCH_x64\"")
else()
message("Setting -march=nehalem for x86_64 processors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=nehalem -DTI_ARCH_x64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_ARCH_x64")
if ("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
# TODO: (penguinliong) Will probably need this in a future version
# of Clang. Clang11 doesn't recognize this.
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=apple-m1")
else()
message("Setting -march=nehalem for x86_64 processors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=nehalem")
endif()
endif()
set(ARCH "x64")
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
Expand Down
5 changes: 5 additions & 0 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ if (TI_WITH_OPENGL OR TI_WITH_VULKAN OR TI_WITH_DX11)
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE gfx_runtime)
endif()

if (TI_WITH_OPENGL OR TI_WITH_DX11)
set(SPIRV_CROSS_CLI false)
add_subdirectory(${PROJECT_SOURCE_DIR}/external/SPIRV-Cross ${PROJECT_BINARY_DIR}/external/SPIRV-Cross)
endif()

# Vulkan Device API
if (TI_WITH_VULKAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_VULKAN")
Expand Down
3 changes: 2 additions & 1 deletion cmake/TaichiTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ file(GLOB_RECURSE TAICHI_TESTS_SOURCE
"tests/cpp/llvm/*.cpp"
"tests/cpp/program/*.cpp"
"tests/cpp/struct/*.cpp"
"tests/cpp/transforms/*.cpp")
"tests/cpp/transforms/*.cpp"
"tests/cpp/offline_cache/*.cpp")

if (TI_WITH_OPENGL OR TI_WITH_VULKAN)
file(GLOB TAICHI_TESTS_GFX_UTILS_SOURCE
Expand Down
31 changes: 31 additions & 0 deletions cpp_examples/rhi_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
macro(make_sample executable_name src_file)
add_executable(${executable_name})
set_property(TARGET ${executable_name} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${executable_name} PROPERTY C_STANDARD 17)
target_sources(${executable_name} PRIVATE ${src_file} "common.h")
target_include_directories(${executable_name}
PRIVATE
${PROJECT_SOURCE_DIR}

${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include
${PROJECT_SOURCE_DIR}/external/eigen
${PROJECT_SOURCE_DIR}/external/FP16/include
${PROJECT_SOURCE_DIR}/external/SPIRV-Reflect
${PROJECT_SOURCE_DIR}/external/spdlog/include
${LLVM_INCLUDE_DIRS}

${PROJECT_SOURCE_DIR}/external/volk
${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include
${PROJECT_SOURCE_DIR}/external/glfw/include
${PROJECT_SOURCE_DIR}/external/glm
${PROJECT_SOURCE_DIR}/external/imgui
)
target_include_directories(${executable_name} SYSTEM
PUBLIC
${PROJECT_SOURCE_DIR}/external/VulkanMemoryAllocator/include
)
target_link_libraries(${executable_name} taichi_c_api glfw)
endmacro()

make_sample(sample_1_window sample_1_window.cpp)
make_sample(sample_2_triangle sample_2_triangle.cpp)
129 changes: 129 additions & 0 deletions cpp_examples/rhi_examples/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#pragma once

#include "taichi/rhi/vulkan/vulkan_device.h"
#include "taichi/rhi/vulkan/vulkan_common.h"
#include "taichi/rhi/vulkan/vulkan_loader.h"
#include "taichi/rhi/vulkan/vulkan_device_creator.h"

#define GLFW_INCLUDE_NONE
#include "GLFW/glfw3.h"
#include "glm/glm.hpp"

using namespace taichi::lang;

static void glfw_error_callback(int code, const char *description) {
TI_WARN("GLFW Error {}: {}", code, description);
}

std::vector<std::string> get_required_instance_extensions() {
std::vector<std::string> extensions;

uint32_t glfw_ext_count = 0;
const char **glfw_extensions;
glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_ext_count);

for (int i = 0; i < glfw_ext_count; ++i) {
extensions.push_back(glfw_extensions[i]);
}
// VulkanDeviceCreator will check that these are supported
extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);

return extensions;
}

std::vector<std::string> get_required_device_extensions() {
static std::vector<std::string> extensions{
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};

return extensions;
}

class App {
public:
App(int width, int height, const std::string &title) {
TI_INFO("Creating App '{}' of {}x{}", title, width, height);

TI_ASSERT(taichi::lang::vulkan::is_vulkan_api_available());

if (glfwInit()) {
TI_INFO("Initialized GLFW");

glfwSetErrorCallback(glfw_error_callback);

glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfw_window =
glfwCreateWindow(width, height, "Sample Window", nullptr, nullptr);

TI_INFO("Initialized GLFWWindow");
} else {
TI_ERROR("failed to init GLFW");
}

{
vulkan::VulkanDeviceCreator::Params evd_params;
evd_params.api_version = std::nullopt;
evd_params.additional_instance_extensions =
get_required_instance_extensions();
evd_params.additional_device_extensions =
get_required_device_extensions();
evd_params.is_for_ui = true;
evd_params.surface_creator = [&](VkInstance instance) -> VkSurfaceKHR {
VkSurfaceKHR surface = VK_NULL_HANDLE;

if (glfwCreateWindowSurface(instance, glfw_window, nullptr, &surface) !=
VK_SUCCESS) {
TI_ERROR("failed to create window surface!");
}
return surface;
};
evd_params.enable_validation_layer = true;

device_creator =
std::make_unique<vulkan::VulkanDeviceCreator>(evd_params);
device = device_creator->device();

TI_INFO("Initialized VulkanDevice");
}

{
SurfaceConfig config;
config.window_handle = glfw_window;
config.native_surface_handle = device_creator->get_surface();

surface = device->create_surface(config);
}
}

virtual ~App() {
surface.reset();
device_creator.reset();
glfwDestroyWindow(glfw_window);
glfwTerminate();
}

virtual std::vector<StreamSemaphore> render_loop(
StreamSemaphore image_available_semaphore) {
return {};
}

void run() {
while (!glfwWindowShouldClose(glfw_window)) {
auto image_available_semaphore = surface->acquire_next_image();

glfwPollEvents();

surface->present_image(render_loop(image_available_semaphore));
}
}

public:
// Owned
GLFWwindow *glfw_window;
std::unique_ptr<vulkan::VulkanDeviceCreator> device_creator;
std::unique_ptr<Surface> surface;

// Weak references
vulkan::VulkanDevice *device;
};
Loading

0 comments on commit f8ce5e8

Please sign in to comment.