From e669537a62d029815dbe74146ab5bee560569dff Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Wed, 7 Dec 2022 15:26:06 +0800 Subject: [PATCH 01/42] test_to_allocMemory --- c_api/include/taichi/cpp/taichi.hpp | 3 + c_api/include/taichi/taichi_core.h | 740 ++++++++++++--------------- c_api/include/taichi/taichi_cpu.h | 18 +- c_api/include/taichi/taichi_cuda.h | 18 +- c_api/include/taichi/taichi_opengl.h | 25 +- c_api/include/taichi/taichi_unity.h | 71 +-- c_api/include/taichi/taichi_vulkan.h | 153 +++--- c_api/src/taichi_core_impl.cpp | 2 +- c_api/tests/c_api_behavior_test.cpp | 111 ++++ c_api/tests/c_api_interface_test.cpp | 11 +- setup.py | 2 +- taichi/rhi/opengl/opengl_device.cpp | 7 + 12 files changed, 613 insertions(+), 548 deletions(-) diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index 1b96a0906030b..8bb223387a297 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -20,11 +20,14 @@ inline std::vector get_available_archs() { } inline bool is_arch_available(TiArch arch) { std::vector archs = get_available_archs(); + std::cout << "available archs: "; for (size_t i = 0; i < archs.size(); ++i) { + std::cout << archs[i] << " "; if (archs.at(i) == arch) { return true; } } + std::cout << std::endl; return false; } diff --git a/c_api/include/taichi/taichi_core.h b/c_api/include/taichi/taichi_core.h index d8f7c7febe9da..2909fca45c957 100644 --- a/c_api/include/taichi/taichi_core.h +++ b/c_api/include/taichi/taichi_core.h @@ -1,14 +1,11 @@ // # Core Functionality -// -// Taichi Core exposes all necessary interfaces for offloading the AOT modules -// to Taichi. The following is a list of features that are available regardless -// of your backend. The corresponding APIs are still under development and -// subject to change. -// +// +// Taichi Core exposes all necessary interfaces for offloading the AOT modules to Taichi. The following is a list of features that are available regardless of your backend. The corresponding APIs are still under development and subject to change. +// // ## Availability -// +// // Taichi C-API intends to support the following backends: -// +// // |Backend |Offload Target |Maintenance Tier | // |------------|-----------------|-----------------| // |Vulkan |GPU |Tier 1 | @@ -17,153 +14,121 @@ // |OpenGL |GPU |Tier 2 | // |DirectX 11 |GPU (Windows) |N/A | // |Metal |GPU (macOS, iOS) |N/A | -// -// The backends with tier-1 support are being developed and tested more -// intensively. And most new features will be available on Vulkan first because -// it has the most outstanding cross-platform compatibility among all the tier-1 -// backends. For the backends with tier-2 support, you should expect a delay in -// the fixes to minor issues. -// -// For convenience, in the following text and other C-API documents, the term -// *host* refers to the user of the C-API; the term *device* refers to the -// logical (conceptual) compute device, to which Taichi's runtime offloads its -// compute tasks. A *device* may not be a physical discrete processor other than -// the CPU and the *host* may *not* be able to access the memory allocated on -// the *device*. -// -// Unless otherwise specified, **device**, **backend**, **offload target**, and -// **GPU** are interchangeable; **host**, **user code**, **user procedure**, and -// **CPU** are interchangeable. -// +// +// The backends with tier-1 support are being developed and tested more intensively. And most new features will be available on Vulkan first because it has the most outstanding cross-platform compatibility among all the tier-1 backends. +// For the backends with tier-2 support, you should expect a delay in the fixes to minor issues. +// +// For convenience, in the following text and other C-API documents, the term *host* refers to the user of the C-API; the term *device* refers to the logical (conceptual) compute device, to which Taichi's runtime offloads its compute tasks. A *device* may not be a physical discrete processor other than the CPU and the *host* may *not* be able to access the memory allocated on the *device*. +// +// Unless otherwise specified, **device**, **backend**, **offload target**, and **GPU** are interchangeable; **host**, **user code**, **user procedure**, and **CPU** are interchangeable. +// // ## HowTo -// +// // The following section provides a brief introduction to the Taichi C-API. -// +// // ### Create and destroy a Runtime Instance -// -// You *must* create a runtime instance before working with Taichi, and *only* -// one runtime per thread. Currently, we do not officially claim that multiple -// runtime instances can coexist in a process, but please feel free to [file an -// issue with us](https://github.com/taichi-dev/taichi/issues) if you run into -// any problem with runtime instance coexistence. -// +// +// You *must* create a runtime instance before working with Taichi, and *only* one runtime per thread. Currently, we do not officially claim that multiple runtime instances can coexist in a process, but please feel free to [file an issue with us](https://github.com/taichi-dev/taichi/issues) if you run into any problem with runtime instance coexistence. +// // ```cpp // TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); // ``` -// +// // When your program runs to the end, ensure that: // - You destroy the runtime instance, -// - All related resources are destroyed before the -// [`TiRuntime`](#handle-tiruntime) itself. -// +// - All related resources are destroyed before the [`TiRuntime`](#handle-tiruntime) itself. +// // ```cpp // ti_destroy_runtime(runtime); // ``` -// +// // ### Allocate and free memory -// -// Allocate a piece of memory that is visible only to the device. On the GPU -// backends, it usually means that the memory is located in the graphics memory -// (GRAM). -// +// +// Allocate a piece of memory that is visible only to the device. On the GPU backends, it usually means that the memory is located in the graphics memory (GRAM). +// // ```cpp // TiMemoryAllocateInfo mai {}; // mai.size = 1024; // Size in bytes. // mai.usage = TI_MEMORY_USAGE_STORAGE_BIT; // TiMemory memory = ti_allocate_memory(runtime, &mai); // ``` -// -// Allocated memory is automatically freed when the related -// [`TiRuntime`](#handle-tiruntime) is destroyed. You can also manually free the -// allocated memory. -// +// +// Allocated memory is automatically freed when the related [`TiRuntime`](#handle-tiruntime) is destroyed. You can also manually free the allocated memory. +// // ```cpp // ti_free_memory(runtime, memory); // ``` -// +// // ### Allocate host-accessible memory -// -// By default, memory allocations are physically or conceptually local to the -// offload target for performance reasons. You can configure the -// [`TiMemoryAllocateInfo`](#structure-timemoryallocateinfo) to enable host -// access to memory allocations. But please note that host-accessible -// allocations *may* slow down computation on GPU because of the limited bus -// bandwidth between the host memory and the device. -// -// You *must* set `host_write` to [`TI_TRUE`](#definition-ti_true) to allow -// zero-copy data streaming to the memory. -// +// +// By default, memory allocations are physically or conceptually local to the offload target for performance reasons. You can configure the [`TiMemoryAllocateInfo`](#structure-timemoryallocateinfo) to enable host access to memory allocations. But please note that host-accessible allocations *may* slow down computation on GPU because of the limited bus bandwidth between the host memory and the device. +// +// You *must* set `host_write` to [`TI_TRUE`](#definition-ti_true) to allow zero-copy data streaming to the memory. +// // ```cpp // TiMemoryAllocateInfo mai {}; // mai.size = 1024; // Size in bytes. // mai.host_write = TI_TRUE; // mai.usage = TI_MEMORY_USAGE_STORAGE_BIT; // TiMemory steaming_memory = ti_allocate_memory(runtime, &mai); -// +// // // ... -// +// // std::vector src = some_random_data_source(); -// +// // void* dst = ti_map_memory(runtime, steaming_memory); // std::memcpy(dst, src.data(), src.size()); // ti_unmap_memory(runtime, streaming_memory); // ``` -// -// To read data back to the host, `host_read` *must* be set to -// [`TI_TRUE`](#definition-ti_true). -// +// +// To read data back to the host, `host_read` *must* be set to [`TI_TRUE`](#definition-ti_true). +// // ```cpp // TiMemoryAllocateInfo mai {}; // mai.size = 1024; // Size in bytes. // mai.host_read = TI_TRUE; // mai.usage = TI_MEMORY_USAGE_STORAGE_BIT; // TiMemory read_back_memory = ti_allocate_memory(runtime, &mai); -// +// // // ... -// +// // std::vector dst(1024); // void* src = ti_map_memory(runtime, read_back_memory); // std::memcpy(dst.data(), src, dst.size()); // ti_unmap_memory(runtime, read_back_memory); -// +// // ti_free_memory(runtime, read_back_memory); // ``` -// +// // > You can set `host_read` and `host_write` at the same time. -// +// // ### Load and destroy a Taichi AOT module -// +// // You can load a Taichi AOT module from the filesystem. -// +// // ```cpp // TiAotModule aot_module = ti_load_aot_module(runtime, "/path/to/aot/module"); // ``` -// -// `/path/to/aot/module` should point to the directory that contains a -// `metadata.tcb`. -// -// You can destroy an unused AOT module, but please ensure that there is no -// kernel or compute graph related to it pending to -// [`ti_submit`](#function-ti_submit). -// +// +// `/path/to/aot/module` should point to the directory that contains a `metadata.tcb`. +// +// You can destroy an unused AOT module, but please ensure that there is no kernel or compute graph related to it pending to [`ti_submit`](#function-ti_submit). +// // ```cpp // ti_destroy_aot_module(aot_module); // ``` -// +// // ### Launch kernels and compute graphs -// -// You can extract kernels and compute graphs from an AOT module. Kernel and -// compute graphs are a part of the module, so you don't have to destroy them. -// +// +// You can extract kernels and compute graphs from an AOT module. Kernel and compute graphs are a part of the module, so you don't have to destroy them. +// // ```cpp // TiKernel kernel = ti_get_aot_module_kernel(aot_module, "foo"); -// TiComputeGraph compute_graph = ti_get_aot_module_compute_graph(aot_module, -// "bar"); +// TiComputeGraph compute_graph = ti_get_aot_module_compute_graph(aot_module, "bar"); // ``` -// -// You can launch a kernel with positional arguments. Please ensure the types, -// the sizes and the order matches the source code in Python. -// +// +// You can launch a kernel with positional arguments. Please ensure the types, the sizes and the order matches the source code in Python. +// // ```cpp // TiNdArray ndarray{}; // ndarray.memory = get_some_memory(); @@ -173,27 +138,26 @@ // ndarray.elem_shape.dims[0] = 4; // ndarray.elem_shape.dims[1] = 4; // ndarray.elem_type = TI_DATA_TYPE_F32; -// +// // std::array args{}; -// +// // TiArgument& arg0 = args[0]; // arg0.type = TI_ARGUMENT_TYPE_I32; // arg0.value.i32 = 123; -// +// // TiArgument& arg1 = args[1]; // arg1.type = TI_ARGUMENT_TYPE_F32; // arg1.value.f32 = 123.0f; -// +// // TiArgument& arg2 = args[2]; // arg2.type = TI_ARGUMENT_TYPE_NDARRAY; // arg2.value.ndarray = ndarray; -// +// // ti_launch_kernel(runtime, kernel, args.size(), args.data()); // ``` -// -// You can launch a compute graph in a similar way. But additionally please -// ensure the argument names matches those in the Python source. -// +// +// You can launch a compute graph in a similar way. But additionally please ensure the argument names matches those in the Python source. +// // ```cpp // std::array named_args{}; // TiNamedArgument& named_arg0 = named_args[0]; @@ -205,148 +169,122 @@ // TiNamedArgument& named_arg2 = named_args[2]; // named_arg2.name = "baz"; // named_arg2.argument = args[2]; -// -// ti_launch_compute_graph(runtime, compute_graph, named_args.size(), -// named_args.data()); +// +// ti_launch_compute_graph(runtime, compute_graph, named_args.size(), named_args.data()); // ``` -// -// When you have launched all kernels and compute graphs for this batch, you -// should [`ti_submit`](#function-ti_submit) and [`ti_wait`](#function-ti_wait) -// for the execution to finish. -// +// +// When you have launched all kernels and compute graphs for this batch, you should [`ti_submit`](#function-ti_submit) and [`ti_wait`](#function-ti_wait) for the execution to finish. +// // ```cpp // ti_submit(runtime); // ti_wait(runtime); // ``` -// -// **WARNING** This part is subject to change. We will introduce multi-queue in -// the future. -// +// +// **WARNING** This part is subject to change. We will introduce multi-queue in the future. +// #pragma once #ifndef TI_C_API_VERSION #define TI_C_API_VERSION 1000002 -#endif // TI_C_API_VERSION +#endif // TI_C_API_VERSION #include #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif // __cplusplus + // Alias `TiBool` -// -// A boolean value. Can be either [`TI_TRUE`](#definition-ti_true) or -// [`TI_FALSE`](#definition-ti_false). Assignment with other values could lead -// to undefined behavior. +// +// A boolean value. Can be either [`TI_TRUE`](#definition-ti_true) or [`TI_FALSE`](#definition-ti_false). Assignment with other values could lead to undefined behavior. typedef uint32_t TiBool; // Definition `TI_FALSE` -// +// // A condition or a predicate is not satisfied; a statement is invalid. #define TI_FALSE 0 // Definition `TI_TRUE` -// +// // A condition or a predicate is satisfied; a statement is valid. #define TI_TRUE 1 // Alias `TiFlags` -// -// A bit field that can be used to represent 32 orthogonal flags. Bits -// unspecified in the corresponding flag enum are ignored. -// -// > Enumerations and bit-field flags in the C-API have a `TI_XXX_MAX_ENUM` case -// to ensure the enum has a 32-bit range and in-memory size. It has no -// semantical impact and can be safely ignored. +// +// A bit field that can be used to represent 32 orthogonal flags. Bits unspecified in the corresponding flag enum are ignored. +// +// > Enumerations and bit-field flags in the C-API have a `TI_XXX_MAX_ENUM` case to ensure the enum has a 32-bit range and in-memory size. It has no semantical impact and can be safely ignored. typedef uint32_t TiFlags; // Definition `TI_NULL_HANDLE` -// -// A sentinal invalid handle that will never be produced from a valid call to -// Taichi C-API. +// +// A sentinal invalid handle that will never be produced from a valid call to Taichi C-API. #define TI_NULL_HANDLE 0 // Handle `TiRuntime` -// -// Taichi runtime represents an instance of a logical backend and its internal -// dynamic state. The user is responsible to synchronize any use of -// [`TiRuntime`](#handle-tiruntime). The user *must not* manipulate multiple -// [`TiRuntime`](#handle-tiruntime)s in the same thread. -typedef struct TiRuntime_t *TiRuntime; +// +// Taichi runtime represents an instance of a logical backend and its internal dynamic state. The user is responsible to synchronize any use of [`TiRuntime`](#handle-tiruntime). The user *must not* manipulate multiple [`TiRuntime`](#handle-tiruntime)s in the same thread. +typedef struct TiRuntime_t* TiRuntime; // Handle `TiAotModule` -// -// An ahead-of-time (AOT) compiled Taichi module, which contains a collection of -// kernels and compute graphs. -typedef struct TiAotModule_t *TiAotModule; +// +// An ahead-of-time (AOT) compiled Taichi module, which contains a collection of kernels and compute graphs. +typedef struct TiAotModule_t* TiAotModule; // Handle `TiEvent` -// -// A synchronization primitive to manage device execution flows in multiple -// queues. -typedef struct TiEvent_t *TiEvent; +// +// A synchronization primitive to manage device execution flows in multiple queues. +typedef struct TiEvent_t* TiEvent; // Handle `TiMemory` -// +// // A contiguous allocation of device memory. -typedef struct TiMemory_t *TiMemory; +typedef struct TiMemory_t* TiMemory; // Handle `TiImage` -// +// // A contiguous allocation of device image. -typedef struct TiImage_t *TiImage; +typedef struct TiImage_t* TiImage; // Handle `TiSampler` -// -// An image sampler. [`TI_NULL_HANDLE`](#definition-ti_null_handle) represents a -// default image sampler provided by the runtime implementation. The filter -// modes and address modes of default samplers depend on backend implementation. -typedef struct TiSampler_t *TiSampler; +// +// An image sampler. [`TI_NULL_HANDLE`](#definition-ti_null_handle) represents a default image sampler provided by the runtime implementation. The filter modes and address modes of default samplers depend on backend implementation. +typedef struct TiSampler_t* TiSampler; // Handle `TiKernel` -// +// // A Taichi kernel that can be launched on the offload target for execution. -typedef struct TiKernel_t *TiKernel; +typedef struct TiKernel_t* TiKernel; // Handle `TiComputeGraph` -// -// A collection of Taichi kernels (a compute graph) to launch on the offload -// target in a predefined order. -typedef struct TiComputeGraph_t *TiComputeGraph; +// +// A collection of Taichi kernels (a compute graph) to launch on the offload target in a predefined order. +typedef struct TiComputeGraph_t* TiComputeGraph; // Enumeration `TiError` -// +// // Errors reported by the Taichi C-API. typedef enum TiError { // The Taichi C-API invocation finished gracefully. TI_ERROR_SUCCESS = 0, - // The invoked API, or the combination of parameters is not supported by the - // Taichi C-API. + // The invoked API, or the combination of parameters is not supported by the Taichi C-API. TI_ERROR_NOT_SUPPORTED = -1, // Provided data is corrupted. TI_ERROR_CORRUPTED_DATA = -2, // Provided name does not refer to any existing item. TI_ERROR_NAME_NOT_FOUND = -3, - // One or more function arguments violate constraints specified in C-API - // documents, or kernel arguments mismatch the kernel argument list defined in - // the AOT module. + // One or more function arguments violate constraints specified in C-API documents, or kernel arguments mismatch the kernel argument list defined in the AOT module. TI_ERROR_INVALID_ARGUMENT = -4, // One or more by-reference (pointer) function arguments point to null. TI_ERROR_ARGUMENT_NULL = -5, - // One or more function arguments are out of its acceptable range; or - // enumeration arguments have undefined value. + // One or more function arguments are out of its acceptable range; or enumeration arguments have undefined value. TI_ERROR_ARGUMENT_OUT_OF_RANGE = -6, // One or more kernel arguments are missing. TI_ERROR_ARGUMENT_NOT_FOUND = -7, - // The intended interoperation is not possible on the current arch. For - // example, attempts to export a Vulkan object from a CUDA runtime are not - // allowed. + // The intended interoperation is not possible on the current arch. For example, attempts to export a Vulkan object from a CUDA runtime are not allowed. TI_ERROR_INVALID_INTEROP = -8, - // The Taichi C-API enters an unrecoverable invalid state. Related Taichi - // objects are potentially corrupted. The users *should* release the - // contaminated resources for stability. Please feel free to file an issue if - // you encountered this error in a normal routine. + // The Taichi C-API enters an unrecoverable invalid state. Related Taichi objects are potentially corrupted. The users *should* release the contaminated resources for stability. Please feel free to file an issue if you encountered this error in a normal routine. TI_ERROR_INVALID_STATE = -9, // The AOT module is not compatible with the current runtime. TI_ERROR_INCOMPATIBLE_MODULE = -10, @@ -355,7 +293,7 @@ typedef enum TiError { } TiError; // Enumeration `TiArch` -// +// // Types of backend archs. typedef enum TiArch { // x64 native CPU backend. @@ -416,10 +354,8 @@ typedef struct TiCapabilityLevelInfo { } TiCapabilityLevelInfo; // Enumeration `TiDataType` -// -// Elementary (primitive) data types. There might be vendor-specific constraints -// on the available data types so it's recommended to use 32-bit data types if -// multi-platform distribution is desired. +// +// Elementary (primitive) data types. There might be vendor-specific constraints on the available data types so it's recommended to use 32-bit data types if multi-platform distribution is desired. typedef enum TiDataType { // 16-bit IEEE 754 half-precision floating-point number. TI_DATA_TYPE_F16 = 0, @@ -450,7 +386,7 @@ typedef enum TiDataType { } TiDataType; // Enumeration `TiArgumentType` -// +// // Types of kernel and compute graph argument. typedef enum TiArgumentType { // 32-bit one's complement signed integer. @@ -465,9 +401,8 @@ typedef enum TiArgumentType { } TiArgumentType; // BitField `TiMemoryUsageFlags` -// -// Usages of a memory allocation. Taichi requires kernel argument memories to be -// allocated with `TI_MEMORY_USAGE_STORAGE_BIT`. +// +// Usages of a memory allocation. Taichi requires kernel argument memories to be allocated with `TI_MEMORY_USAGE_STORAGE_BIT`. typedef enum TiMemoryUsageFlagBits { // The memory can be read/write accessed by any kernel. TI_MEMORY_USAGE_STORAGE_BIT = 1 << 0, @@ -481,7 +416,7 @@ typedef enum TiMemoryUsageFlagBits { typedef TiFlags TiMemoryUsageFlags; // Structure `TiMemoryAllocateInfo` -// +// // Parameters of a newly allocated memory. typedef struct TiMemoryAllocateInfo { // Size of the allocation in bytes. @@ -490,18 +425,15 @@ typedef struct TiMemoryAllocateInfo { TiBool host_write; // True if the host needs to read from the allocated memory. TiBool host_read; - // True if the memory allocation needs to be exported to other backends (e.g., - // from Vulkan to CUDA). + // True if the memory allocation needs to be exported to other backends (e.g., from Vulkan to CUDA). TiBool export_sharing; - // All possible usage of this memory allocation. In most cases, - // `bit_field.memory_usage.storage` is enough. + // All possible usage of this memory allocation. In most cases, `bit_field.memory_usage.storage` is enough. TiMemoryUsageFlags usage; } TiMemoryAllocateInfo; // Structure `TiMemorySlice` -// -// A subsection of a memory allocation. The sum of `offset` and `size` cannot -// exceed the size of `memory`. +// +// A subsection of a memory allocation. The sum of `offset` and `size` cannot exceed the size of `memory`. typedef struct TiMemorySlice { // The subsectioned memory allocation. TiMemory memory; @@ -512,9 +444,8 @@ typedef struct TiMemorySlice { } TiMemorySlice; // Structure `TiNdShape` -// -// Multi-dimensional size of an ND-array. Dimension sizes after `dim_count` are -// ignored. +// +// Multi-dimensional size of an ND-array. Dimension sizes after `dim_count` are ignored. typedef struct TiNdShape { // Number of dimensions. uint32_t dim_count; @@ -523,37 +454,34 @@ typedef struct TiNdShape { } TiNdShape; // Structure `TiNdArray` -// +// // Multi-dimensional array of dense primitive data. typedef struct TiNdArray { // Memory bound to the ND-array. TiMemory memory; // Shape of the ND-array. TiNdShape shape; - // Shape of the ND-array elements. It *must not* be empty for vector or matrix - // ND-arrays. + // Shape of the ND-array elements. It *must not* be empty for vector or matrix ND-arrays. TiNdShape elem_shape; // Primitive data type of the ND-array elements. TiDataType elem_type; } TiNdArray; // BitField `TiImageUsageFlags` -// -// Usages of an image allocation. Taichi requires kernel argument images to be -// allocated with `TI_IMAGE_USAGE_STORAGE_BIT` and `TI_IMAGE_USAGE_SAMPLED_BIT`. +// +// Usages of an image allocation. Taichi requires kernel argument images to be allocated with `TI_IMAGE_USAGE_STORAGE_BIT` and `TI_IMAGE_USAGE_SAMPLED_BIT`. typedef enum TiImageUsageFlagBits { // The image can be read/write accessed by any kernel. TI_IMAGE_USAGE_STORAGE_BIT = 1 << 0, // The image can be read-only accessed by any kernel. TI_IMAGE_USAGE_SAMPLED_BIT = 1 << 1, - // The image can be used as a color or depth-stencil attachment depending on - // its format. + // The image can be used as a color or depth-stencil attachment depending on its format. TI_IMAGE_USAGE_ATTACHMENT_BIT = 1 << 2, } TiImageUsageFlagBits; typedef TiFlags TiImageUsageFlags; // Enumeration `TiImageDimension` -// +// // Dimensions of an image allocation. typedef enum TiImageDimension { // The image is 1-dimensional. @@ -566,16 +494,14 @@ typedef enum TiImageDimension { TI_IMAGE_DIMENSION_1D_ARRAY = 3, // The image is 2-dimensional and it has one or more layers. TI_IMAGE_DIMENSION_2D_ARRAY = 4, - // The image is 2-dimensional and it has 6 layers for the faces towards +X, - // -X, +Y, -Y, +Z, -Z in sequence. + // The image is 2-dimensional and it has 6 layers for the faces towards +X, -X, +Y, -Y, +Z, -Z in sequence. TI_IMAGE_DIMENSION_CUBE = 5, TI_IMAGE_DIMENSION_MAX_ENUM = 0xffffffff, } TiImageDimension; // Enumeration `TiImageLayout` typedef enum TiImageLayout { - // Undefined layout. An image in this layout does not contain any semantical - // information. + // Undefined layout. An image in this layout does not contain any semantical information. TI_IMAGE_LAYOUT_UNDEFINED = 0, // Optimal layout for read-only access, including sampling. TI_IMAGE_LAYOUT_SHADER_READ = 1, @@ -650,52 +576,35 @@ typedef enum TiFormat { } TiFormat; // Structure `TiImageOffset` -// +// // Offsets of an image in X, Y, Z, and array layers. typedef struct TiImageOffset { // Image offset in the X direction. uint32_t x; - // Image offset in the Y direction. *Must* be 0 if the image has a dimension - // of `enumeration.image_dimension.1d` or - // `enumeration.image_dimension.1d_array`. + // Image offset in the Y direction. *Must* be 0 if the image has a dimension of `enumeration.image_dimension.1d` or `enumeration.image_dimension.1d_array`. uint32_t y; - // Image offset in the Z direction. *Must* be 0 if the image has a dimension - // of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, - // `enumeration.image_dimension.1d_array`, - // `enumeration.image_dimension.2d_array` or - // `enumeration.image_dimension.cube_array`. + // Image offset in the Z direction. *Must* be 0 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, `enumeration.image_dimension.1d_array`, `enumeration.image_dimension.2d_array` or `enumeration.image_dimension.cube_array`. uint32_t z; - // Image offset in array layers. *Must* be 0 if the image has a dimension of - // `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or - // `enumeration.image_dimension.3d`. + // Image offset in array layers. *Must* be 0 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or `enumeration.image_dimension.3d`. uint32_t array_layer_offset; } TiImageOffset; // Structure `TiImageExtent` -// +// // Extents of an image in X, Y, Z, and array layers. typedef struct TiImageExtent { // Image extent in the X direction. uint32_t width; - // Image extent in the Y direction. *Must* be 1 if the image has a dimension - // of `enumeration.image_dimension.1d` or - // `enumeration.image_dimension.1d_array`. + // Image extent in the Y direction. *Must* be 1 if the image has a dimension of `enumeration.image_dimension.1d` or `enumeration.image_dimension.1d_array`. uint32_t height; - // Image extent in the Z direction. *Must* be 1 if the image has a dimension - // of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, - // `enumeration.image_dimension.1d_array`, - // `enumeration.image_dimension.2d_array` or - // `enumeration.image_dimension.cube_array`. + // Image extent in the Z direction. *Must* be 1 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, `enumeration.image_dimension.1d_array`, `enumeration.image_dimension.2d_array` or `enumeration.image_dimension.cube_array`. uint32_t depth; - // Image extent in array layers. *Must* be 1 if the image has a dimension of - // `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or - // `enumeration.image_dimension.3d`. *Must* be 6 if the image has a dimension - // of `enumeration.image_dimension.cube_array`. + // Image extent in array layers. *Must* be 1 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or `enumeration.image_dimension.3d`. *Must* be 6 if the image has a dimension of `enumeration.image_dimension.cube_array`. uint32_t array_layer_count; } TiImageExtent; // Structure `TiImageAllocateInfo` -// +// // Parameters of a newly allocated image. typedef struct TiImageAllocateInfo { // Image dimension. @@ -706,18 +615,15 @@ typedef struct TiImageAllocateInfo { uint32_t mip_level_count; // Image texel format. TiFormat format; - // True if the memory allocation needs to be exported to other backends (e.g., - // from Vulkan to CUDA). + // True if the memory allocation needs to be exported to other backends (e.g., from Vulkan to CUDA). TiBool export_sharing; - // All possible usages of this image allocation. In most cases, - // `bit_field.image_usage.storage` and `bit_field.image_usage.sampled` enough. + // All possible usages of this image allocation. In most cases, `bit_field.image_usage.storage` and `bit_field.image_usage.sampled` enough. TiImageUsageFlags usage; } TiImageAllocateInfo; // Structure `TiImageSlice` -// -// A subsection of a memory allocation. The sum of `offset` and `extent` in each -// dimension cannot exceed the size of `image`. +// +// A subsection of a memory allocation. The sum of `offset` and `extent` in each dimension cannot exceed the size of `image`. typedef struct TiImageSlice { // The subsectioned image allocation. TiImage image; @@ -753,13 +659,12 @@ typedef struct TiSamplerCreateInfo { } TiSamplerCreateInfo; // Structure `TiTexture` -// +// // Image data bound to a sampler. typedef struct TiTexture { // Image bound to the texture. TiImage image; - // The bound sampler that controls the sampling behavior of - // `structure.texture.image`. + // The bound sampler that controls the sampling behavior of `structure.texture.image`. TiSampler sampler; // Image Dimension. TiImageDimension dimension; @@ -770,7 +675,7 @@ typedef struct TiTexture { } TiTexture; // Union `TiArgumentValue` -// +// // A scalar or structured argument value. typedef union TiArgumentValue { // Value of a 32-bit one's complement signed integer. @@ -784,7 +689,7 @@ typedef union TiArgumentValue { } TiArgumentValue; // Structure `TiArgument` -// +// // An argument value to feed kernels. typedef struct TiArgument { // Type of the argument. @@ -794,63 +699,61 @@ typedef struct TiArgument { } TiArgument; // Structure `TiNamedArgument` -// +// // A named argument value to feed compute graphs. typedef struct TiNamedArgument { // Name of the argument. - const char *name; + const char* name; // Argument body. TiArgument argument; } TiNamedArgument; // Function `ti_get_available_archs` -// -// Gets a list of available archs on the current platform. An arch is only -// available if: -// +// +// Gets a list of available archs on the current platform. An arch is only available if: +// // 1. The Runtime library is compiled with its support; -// 2. The current platform is installed with a capable hardware or an emulation -// software. -// -// An available arch has at least one device available, i.e., device index 0 is -// always available. If an arch is not available on the current platform, a call -// to [`ti_create_runtime`](#function-ti_create_runtime) with that arch is -// guaranteed failing. -TI_DLL_EXPORT void TI_API_CALL ti_get_available_archs(uint32_t *arch_count, - TiArch *archs); +// 2. The current platform is installed with a capable hardware or an emulation software. +// +// An available arch has at least one device available, i.e., device index 0 is always available. If an arch is not available on the current platform, a call to [`ti_create_runtime`](#function-ti_create_runtime) with that arch is guaranteed failing. +TI_DLL_EXPORT void TI_API_CALL ti_get_available_archs( + uint32_t* arch_count, + TiArch* archs +); // Function `ti_get_last_error` -// -// Gets the last error raised by Taichi C-API invocations. Returns the -// semantical error code. +// +// Gets the last error raised by Taichi C-API invocations. Returns the semantical error code. TI_DLL_EXPORT TiError TI_API_CALL ti_get_last_error( - // Size of textual error message in `function.get_last_error.message` - uint64_t message_size, - // Text buffer for the textual error message. Ignored when `message_size` is - // 0. - char *message); + // Size of textual error message in `function.get_last_error.message` + uint64_t message_size, + // Text buffer for the textual error message. Ignored when `message_size` is 0. + char* message +); // Function `ti_set_last_error` -// -// Sets the provided error as the last error raised by Taichi C-API invocations. -// It can be useful in extended validation procedures in Taichi C-API wrappers -// and helper libraries. +// +// Sets the provided error as the last error raised by Taichi C-API invocations. It can be useful in extended validation procedures in Taichi C-API wrappers and helper libraries. TI_DLL_EXPORT void TI_API_CALL ti_set_last_error( - // Semantical error code. - TiError error, - // A null-terminated string of the textual error message or `nullptr` for - // empty error message. - const char *message); + // Semantical error code. + TiError error, + // A null-terminated string of the textual error message or `nullptr` for empty error message. + const char* message +); // Function `ti_create_runtime` -// +// // Creates a Taichi Runtime with the specified [`TiArch`](#enumeration-tiarch). -TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime(TiArch arch); +TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime( + TiArch arch +); // Function `ti_destroy_runtime` -// +// // Destroys a Taichi Runtime. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_runtime(TiRuntime runtime); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_runtime( + TiRuntime runtime +); // Function `ti_set_runtime_capabilities_ext` TI_DLL_EXPORT void TI_API_CALL @@ -869,185 +772,214 @@ ti_get_runtime_capabilities(TiRuntime runtime, TiCapabilityLevelInfo *capabilities); // Function `ti_allocate_memory` -// +// // Allocates a contiguous device memory with provided parameters. -TI_DLL_EXPORT TiMemory TI_API_CALL -ti_allocate_memory(TiRuntime runtime, - const TiMemoryAllocateInfo *allocate_info); +TI_DLL_EXPORT TiMemory TI_API_CALL ti_allocate_memory( + TiRuntime runtime, + const TiMemoryAllocateInfo* allocate_info +); // Function `ti_free_memory` -// +// // Frees a memory allocation. -TI_DLL_EXPORT void TI_API_CALL ti_free_memory(TiRuntime runtime, - TiMemory memory); +TI_DLL_EXPORT void TI_API_CALL ti_free_memory( + TiRuntime runtime, + TiMemory memory +); // Function `ti_map_memory` -// -// Maps a device memory to a host-addressable space. You *must* ensure that the -// device is not being used by any device command before the mapping. -TI_DLL_EXPORT void *TI_API_CALL ti_map_memory(TiRuntime runtime, - TiMemory memory); +// +// Maps a device memory to a host-addressable space. You *must* ensure that the device is not being used by any device command before the mapping. +TI_DLL_EXPORT void* TI_API_CALL ti_map_memory( + TiRuntime runtime, + TiMemory memory +); // Function `ti_unmap_memory` -// -// Unmaps a device memory and makes any host-side changes about the memory -// visible to the device. You *must* ensure that there is no further access to -// the previously mapped host-addressable space. -TI_DLL_EXPORT void TI_API_CALL ti_unmap_memory(TiRuntime runtime, - TiMemory memory); +// +// Unmaps a device memory and makes any host-side changes about the memory visible to the device. You *must* ensure that there is no further access to the previously mapped host-addressable space. +TI_DLL_EXPORT void TI_API_CALL ti_unmap_memory( + TiRuntime runtime, + TiMemory memory +); // Function `ti_allocate_image` -// +// // Allocates a device image with provided parameters. -TI_DLL_EXPORT TiImage TI_API_CALL -ti_allocate_image(TiRuntime runtime, const TiImageAllocateInfo *allocate_info); +TI_DLL_EXPORT TiImage TI_API_CALL ti_allocate_image( + TiRuntime runtime, + const TiImageAllocateInfo* allocate_info +); // Function `ti_free_image` -// +// // Frees an image allocation. -TI_DLL_EXPORT void TI_API_CALL ti_free_image(TiRuntime runtime, TiImage image); +TI_DLL_EXPORT void TI_API_CALL ti_free_image( + TiRuntime runtime, + TiImage image +); // Function `ti_create_sampler` -TI_DLL_EXPORT TiSampler TI_API_CALL -ti_create_sampler(TiRuntime runtime, const TiSamplerCreateInfo *create_info); +TI_DLL_EXPORT TiSampler TI_API_CALL ti_create_sampler( + TiRuntime runtime, + const TiSamplerCreateInfo* create_info +); // Function `ti_destroy_sampler` -TI_DLL_EXPORT void TI_API_CALL ti_destroy_sampler(TiRuntime runtime, - TiSampler sampler); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_sampler( + TiRuntime runtime, + TiSampler sampler +); // Function `ti_create_event` -// +// // Creates an event primitive. -TI_DLL_EXPORT TiEvent TI_API_CALL ti_create_event(TiRuntime runtime); +TI_DLL_EXPORT TiEvent TI_API_CALL ti_create_event( + TiRuntime runtime +); // Function `ti_destroy_event` -// +// // Destroys an event primitive. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_event(TiEvent event); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_event( + TiEvent event +); // Function `ti_copy_memory_device_to_device` (Device Command) -// -// Copies the data in a contiguous subsection of the device memory to another -// subsection. The two subsections *must not* overlap. -TI_DLL_EXPORT void TI_API_CALL -ti_copy_memory_device_to_device(TiRuntime runtime, - const TiMemorySlice *dst_memory, - const TiMemorySlice *src_memory); +// +// Copies the data in a contiguous subsection of the device memory to another subsection. The two subsections *must not* overlap. +TI_DLL_EXPORT void TI_API_CALL ti_copy_memory_device_to_device( + TiRuntime runtime, + const TiMemorySlice* dst_memory, + const TiMemorySlice* src_memory +); // Function `ti_copy_image_device_to_device` (Device Command) -// -// Copies the image data in a contiguous subsection of the device image to -// another subsection. The two subsections *must not* overlap. -TI_DLL_EXPORT void TI_API_CALL -ti_copy_image_device_to_device(TiRuntime runtime, - const TiImageSlice *dst_image, - const TiImageSlice *src_image); +// +// Copies the image data in a contiguous subsection of the device image to another subsection. The two subsections *must not* overlap. +TI_DLL_EXPORT void TI_API_CALL ti_copy_image_device_to_device( + TiRuntime runtime, + const TiImageSlice* dst_image, + const TiImageSlice* src_image +); // Function `ti_track_image_ext` -// -// Tracks the device image with the provided image layout. Because Taichi tracks -// image layouts internally, it is *only* useful to inform Taichi that the image -// is transitioned to a new layout by external procedures. -TI_DLL_EXPORT void TI_API_CALL ti_track_image_ext(TiRuntime runtime, - TiImage image, - TiImageLayout layout); +// +// Tracks the device image with the provided image layout. Because Taichi tracks image layouts internally, it is *only* useful to inform Taichi that the image is transitioned to a new layout by external procedures. +TI_DLL_EXPORT void TI_API_CALL ti_track_image_ext( + TiRuntime runtime, + TiImage image, + TiImageLayout layout +); // Function `ti_transition_image` (Device Command) -// -// Transitions the image to the provided image layout. Because Taichi tracks -// image layouts internally, it is *only* useful to enforce an image layout for -// external procedures to use. -TI_DLL_EXPORT void TI_API_CALL ti_transition_image(TiRuntime runtime, - TiImage image, - TiImageLayout layout); +// +// Transitions the image to the provided image layout. Because Taichi tracks image layouts internally, it is *only* useful to enforce an image layout for external procedures to use. +TI_DLL_EXPORT void TI_API_CALL ti_transition_image( + TiRuntime runtime, + TiImage image, + TiImageLayout layout +); // Function `ti_launch_kernel` (Device Command) -// -// Launches a Taichi kernel with the provided arguments. The arguments *must* -// have the same count and types in the same order as in the source code. -TI_DLL_EXPORT void TI_API_CALL ti_launch_kernel(TiRuntime runtime, - TiKernel kernel, - uint32_t arg_count, - const TiArgument *args); +// +// Launches a Taichi kernel with the provided arguments. The arguments *must* have the same count and types in the same order as in the source code. +TI_DLL_EXPORT void TI_API_CALL ti_launch_kernel( + TiRuntime runtime, + TiKernel kernel, + uint32_t arg_count, + const TiArgument* args +); // Function `ti_launch_compute_graph` (Device Command) -// -// Launches a Taichi compute graph with provided named arguments. The named -// arguments *must* have the same count, names, and types as in the source code. -TI_DLL_EXPORT void TI_API_CALL -ti_launch_compute_graph(TiRuntime runtime, - TiComputeGraph compute_graph, - uint32_t arg_count, - const TiNamedArgument *args); +// +// Launches a Taichi compute graph with provided named arguments. The named arguments *must* have the same count, names, and types as in the source code. +TI_DLL_EXPORT void TI_API_CALL ti_launch_compute_graph( + TiRuntime runtime, + TiComputeGraph compute_graph, + uint32_t arg_count, + const TiNamedArgument* args +); // Function `ti_signal_event` (Device Command) -// -// Sets an event primitive to a signaled state so that the queues waiting for it -// can go on execution. If the event has been signaled, you *must* call -// [`ti_reset_event`](#function-ti_reset_event-device-command) to reset it; -// otherwise, an undefined behavior would occur. -TI_DLL_EXPORT void TI_API_CALL ti_signal_event(TiRuntime runtime, - TiEvent event); +// +// Sets an event primitive to a signaled state so that the queues waiting for it can go on execution. If the event has been signaled, you *must* call [`ti_reset_event`](#function-ti_reset_event-device-command) to reset it; otherwise, an undefined behavior would occur. +TI_DLL_EXPORT void TI_API_CALL ti_signal_event( + TiRuntime runtime, + TiEvent event +); // Function `ti_reset_event` (Device Command) -// +// // Sets a signaled event primitive back to an unsignaled state. -TI_DLL_EXPORT void TI_API_CALL ti_reset_event(TiRuntime runtime, TiEvent event); +TI_DLL_EXPORT void TI_API_CALL ti_reset_event( + TiRuntime runtime, + TiEvent event +); // Function `ti_wait_event` (Device Command) -// -// Waits until an event primitive transitions to a signaled state. The awaited -// event *must* be signaled by an external procedure or a previous invocation to -// [`ti_reset_event`](#function-ti_reset_event-device-command); otherwise, an -// undefined behavior would occur. -TI_DLL_EXPORT void TI_API_CALL ti_wait_event(TiRuntime runtime, TiEvent event); +// +// Waits until an event primitive transitions to a signaled state. The awaited event *must* be signaled by an external procedure or a previous invocation to [`ti_reset_event`](#function-ti_reset_event-device-command); otherwise, an undefined behavior would occur. +TI_DLL_EXPORT void TI_API_CALL ti_wait_event( + TiRuntime runtime, + TiEvent event +); // Function `ti_submit` -// -// Submits all previously invoked device commands to the offload device for -// execution. -TI_DLL_EXPORT void TI_API_CALL ti_submit(TiRuntime runtime); +// +// Submits all previously invoked device commands to the offload device for execution. +TI_DLL_EXPORT void TI_API_CALL ti_submit( + TiRuntime runtime +); // Function `ti_wait` -// -// Waits until all previously invoked device commands are executed. Any invoked -// command that has not been submitted is submitted first. -TI_DLL_EXPORT void TI_API_CALL ti_wait(TiRuntime runtime); +// +// Waits until all previously invoked device commands are executed. Any invoked command that has not been submitted is submitted first. +TI_DLL_EXPORT void TI_API_CALL ti_wait( + TiRuntime runtime +); // Function `ti_load_aot_module` -// +// // Loads a pre-compiled AOT module from the file system. -// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the runtime fails -// to load the AOT module from the specified path. -TI_DLL_EXPORT TiAotModule TI_API_CALL -ti_load_aot_module(TiRuntime runtime, const char *module_path); +// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the runtime fails to load the AOT module from the specified path. +TI_DLL_EXPORT TiAotModule TI_API_CALL ti_load_aot_module( + TiRuntime runtime, + const char* module_path +); // Function `ti_create_aot_module` -TI_DLL_EXPORT TiAotModule TI_API_CALL ti_create_aot_module(TiRuntime runtime, - const void *tcm, - uint64_t size); +TI_DLL_EXPORT TiAotModule TI_API_CALL ti_create_aot_module( + TiRuntime runtime, + const void* tcm, + uint64_t size +); // Function `ti_destroy_aot_module` -// +// // Destroys a loaded AOT module and releases all related resources. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_aot_module(TiAotModule aot_module); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_aot_module( + TiAotModule aot_module +); // Function `ti_get_aot_module_kernel` -// +// // Retrieves a pre-compiled Taichi kernel from the AOT module. -// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not -// have a kernel of the specified name. -TI_DLL_EXPORT TiKernel TI_API_CALL -ti_get_aot_module_kernel(TiAotModule aot_module, const char *name); +// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not have a kernel of the specified name. +TI_DLL_EXPORT TiKernel TI_API_CALL ti_get_aot_module_kernel( + TiAotModule aot_module, + const char* name +); // Function `ti_get_aot_module_compute_graph` -// +// // Retrieves a pre-compiled compute graph from the AOT module. -// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not -// have a compute graph of the specified name. -TI_DLL_EXPORT TiComputeGraph TI_API_CALL -ti_get_aot_module_compute_graph(TiAotModule aot_module, const char *name); +// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not have a compute graph of the specified name. +TI_DLL_EXPORT TiComputeGraph TI_API_CALL ti_get_aot_module_compute_graph( + TiAotModule aot_module, + const char* name +); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_cpu.h b/c_api/include/taichi/taichi_cpu.h index ca0f7e7031462..58656f3a8374d 100644 --- a/c_api/include/taichi/taichi_cpu.h +++ b/c_api/include/taichi/taichi_cpu.h @@ -4,20 +4,22 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif // __cplusplus + // Structure `TiCpuMemoryInteropInfo` typedef struct TiCpuMemoryInteropInfo { - void *ptr; + void* ptr; uint64_t size; } TiCpuMemoryInteropInfo; // Function `ti_export_cpu_memory` -TI_DLL_EXPORT void TI_API_CALL -ti_export_cpu_memory(TiRuntime runtime, - TiMemory memory, - TiCpuMemoryInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_cpu_memory( + TiRuntime runtime, + TiMemory memory, + TiCpuMemoryInteropInfo* interop_info +); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_cuda.h b/c_api/include/taichi/taichi_cuda.h index 485953966a159..350269f859af9 100644 --- a/c_api/include/taichi/taichi_cuda.h +++ b/c_api/include/taichi/taichi_cuda.h @@ -4,20 +4,22 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif // __cplusplus + // Structure `TiCudaMemoryInteropInfo` typedef struct TiCudaMemoryInteropInfo { - void *ptr; + void* ptr; uint64_t size; } TiCudaMemoryInteropInfo; // Function `ti_export_cuda_memory` -TI_DLL_EXPORT void TI_API_CALL -ti_export_cuda_memory(TiRuntime runtime, - TiMemory memory, - TiCudaMemoryInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_cuda_memory( + TiRuntime runtime, + TiMemory memory, + TiCudaMemoryInteropInfo* interop_info +); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_opengl.h b/c_api/include/taichi/taichi_opengl.h index 0522de61ce047..34ef146c645f8 100644 --- a/c_api/include/taichi/taichi_opengl.h +++ b/c_api/include/taichi/taichi_opengl.h @@ -4,7 +4,8 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif // __cplusplus + // Structure `TiOpenglMemoryInteropInfo` typedef struct TiOpenglMemoryInteropInfo { @@ -13,17 +14,19 @@ typedef struct TiOpenglMemoryInteropInfo { } TiOpenglMemoryInteropInfo; // Function `ti_import_opengl_memory` -TI_DLL_EXPORT void TI_API_CALL -ti_import_opengl_memory(TiRuntime runtime, - TiMemory memory, - TiOpenglMemoryInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_import_opengl_memory( + TiRuntime runtime, + TiMemory memory, + TiOpenglMemoryInteropInfo* interop_info +); // Function `ti_export_opengl_memory` -TI_DLL_EXPORT void TI_API_CALL -ti_export_opengl_memory(TiRuntime runtime, - TiMemory memory, - TiOpenglMemoryInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_opengl_memory( + TiRuntime runtime, + TiMemory memory, + TiOpenglMemoryInteropInfo* interop_info +); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_unity.h b/c_api/include/taichi/taichi_unity.h index 43e8b5da2ebfa..6f4c6f5f4e734 100644 --- a/c_api/include/taichi/taichi_unity.h +++ b/c_api/include/taichi/taichi_unity.h @@ -4,52 +4,61 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif // __cplusplus + // Handle `TixNativeBufferUnity` -typedef struct TixNativeBufferUnity_t *TixNativeBufferUnity; +typedef struct TixNativeBufferUnity_t* TixNativeBufferUnity; // Function `tix_import_native_runtime_unity` -TI_DLL_EXPORT TiRuntime TI_API_CALL tix_import_native_runtime_unity(); +TI_DLL_EXPORT TiRuntime TI_API_CALL tix_import_native_runtime_unity( +); // Function `tix_launch_kernel_async_unity` -TI_DLL_EXPORT void TI_API_CALL -tix_launch_kernel_async_unity(TiRuntime runtime, - TiKernel kernel, - uint32_t arg_count, - const TiArgument *args); +TI_DLL_EXPORT void TI_API_CALL tix_launch_kernel_async_unity( + TiRuntime runtime, + TiKernel kernel, + uint32_t arg_count, + const TiArgument* args +); // Function `tix_launch_compute_graph_async_unity` -TI_DLL_EXPORT void TI_API_CALL -tix_launch_compute_graph_async_unity(TiRuntime runtime, - TiComputeGraph compute_graph, - uint32_t arg_count, - const TiNamedArgument *args); +TI_DLL_EXPORT void TI_API_CALL tix_launch_compute_graph_async_unity( + TiRuntime runtime, + TiComputeGraph compute_graph, + uint32_t arg_count, + const TiNamedArgument* args +); // Function `tix_copy_memory_to_native_buffer_async_unity` -TI_DLL_EXPORT void TI_API_CALL -tix_copy_memory_to_native_buffer_async_unity(TiRuntime runtime, - TixNativeBufferUnity dst, - uint64_t dst_offset, - const TiMemorySlice *src); +TI_DLL_EXPORT void TI_API_CALL tix_copy_memory_to_native_buffer_async_unity( + TiRuntime runtime, + TixNativeBufferUnity dst, + uint64_t dst_offset, + const TiMemorySlice* src +); // Function `tix_copy_memory_device_to_host_unity` -TI_DLL_EXPORT void TI_API_CALL -tix_copy_memory_device_to_host_unity(TiRuntime runtime, - void *dst, - uint64_t dst_offset, - const TiMemorySlice *src); +TI_DLL_EXPORT void TI_API_CALL tix_copy_memory_device_to_host_unity( + TiRuntime runtime, + void* dst, + uint64_t dst_offset, + const TiMemorySlice* src +); // Function `tix_copy_memory_host_to_device_unity` -TI_DLL_EXPORT void TI_API_CALL -tix_copy_memory_host_to_device_unity(TiRuntime runtime, - const TiMemorySlice *dst, - const void *src, - uint64_t src_offset); +TI_DLL_EXPORT void TI_API_CALL tix_copy_memory_host_to_device_unity( + TiRuntime runtime, + const TiMemorySlice* dst, + const void* src, + uint64_t src_offset +); // Function `tix_submit_async_unity` -TI_DLL_EXPORT void *TI_API_CALL tix_submit_async_unity(TiRuntime runtime); +TI_DLL_EXPORT void* TI_API_CALL tix_submit_async_unity( + TiRuntime runtime +); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_vulkan.h b/c_api/include/taichi/taichi_vulkan.h index 2a440092013fb..a7c68708248bd 100644 --- a/c_api/include/taichi/taichi_vulkan.h +++ b/c_api/include/taichi/taichi_vulkan.h @@ -1,26 +1,22 @@ // # Vulkan Backend Features -// -// Taichi's Vulkan API gives you further control over the Vulkan version and -// extension requirements and allows you to interop with external Vulkan -// applications with shared resources. -// +// +// Taichi's Vulkan API gives you further control over the Vulkan version and extension requirements and allows you to interop with external Vulkan applications with shared resources. +// #pragma once #include #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif // __cplusplus + // Structure `TiVulkanRuntimeInteropInfo` -// -// Necessary detail to share the same Vulkan runtime between Taichi and external -// procedures. -// -// -// **NOTE** `compute_queue` and `graphics_queue` can be the same if the queue -// family have `VK_QUEUE_COMPUTE_BIT` and `VK_QUEUE_GRAPHICS_BIT` set at the -// same tiem. +// +// Necessary detail to share the same Vulkan runtime between Taichi and external procedures. +// +// +// **NOTE** `compute_queue` and `graphics_queue` can be the same if the queue family have `VK_QUEUE_COMPUTE_BIT` and `VK_QUEUE_GRAPHICS_BIT` set at the same tiem. typedef struct TiVulkanRuntimeInteropInfo { // Pointer to Vulkan loader function `vkGetInstanceProcAddr`. PFN_vkGetInstanceProcAddr get_instance_proc_addr; @@ -32,41 +28,35 @@ typedef struct TiVulkanRuntimeInteropInfo { VkPhysicalDevice physical_device; // Vulkan logical device handle. VkDevice device; - // Vulkan queue handle created in the queue family at - // `structure.vulkan_runtime_interop_info.compute_queue_family_index`. + // Vulkan queue handle created in the queue family at `structure.vulkan_runtime_interop_info.compute_queue_family_index`. VkQueue compute_queue; // Index of a Vulkan queue family with the `VK_QUEUE_COMPUTE_BIT` set. uint32_t compute_queue_family_index; - // Vulkan queue handle created in the queue family at - // `structure.vulkan_runtime_interop_info.graphics_queue_family_index`. + // Vulkan queue handle created in the queue family at `structure.vulkan_runtime_interop_info.graphics_queue_family_index`. VkQueue graphics_queue; // Index of a Vulkan queue family with the `VK_QUEUE_GRAPHICS_BIT` set. uint32_t graphics_queue_family_index; } TiVulkanRuntimeInteropInfo; // Structure `TiVulkanMemoryInteropInfo` -// -// Necessary detail to share the same piece of Vulkan buffer between Taichi and -// external procedures. +// +// Necessary detail to share the same piece of Vulkan buffer between Taichi and external procedures. typedef struct TiVulkanMemoryInteropInfo { // Vulkan buffer. VkBuffer buffer; // Size of the piece of memory in bytes. uint64_t size; - // Vulkan buffer usage. In most of the cases, Taichi requires the - // `VK_BUFFER_USAGE_STORAGE_BUFFER_BIT`. + // Vulkan buffer usage. In most of the cases, Taichi requires the `VK_BUFFER_USAGE_STORAGE_BUFFER_BIT`. VkBufferUsageFlags usage; // Device memory binded to the Vulkan buffer. VkDeviceMemory memory; - // Offset in `VkDeviceMemory` object to the beginning of this allocation, in - // bytes. + // Offset in `VkDeviceMemory` object to the beginning of this allocation, in bytes. uint64_t offset; } TiVulkanMemoryInteropInfo; // Structure `TiVulkanImageInteropInfo` -// -// Necessary detail to share the same piece of Vulkan image between Taichi and -// external procedures. +// +// Necessary detail to share the same piece of Vulkan image between Taichi and external procedures. typedef struct TiVulkanImageInteropInfo { // Vulkan image. VkImage image; @@ -84,90 +74,97 @@ typedef struct TiVulkanImageInteropInfo { VkSampleCountFlagBits sample_count; // Image tiling. VkImageTiling tiling; - // Vulkan image usage. In most cases, Taichi requires the - // `VK_IMAGE_USAGE_STORAGE_BIT` and the `VK_IMAGE_USAGE_SAMPLED_BIT`. + // Vulkan image usage. In most cases, Taichi requires the `VK_IMAGE_USAGE_STORAGE_BIT` and the `VK_IMAGE_USAGE_SAMPLED_BIT`. VkImageUsageFlags usage; } TiVulkanImageInteropInfo; // Structure `TiVulkanEventInteropInfo` -// -// Necessary detail to share the same Vulkan event synchronization primitive -// between Taichi and the user application. +// +// Necessary detail to share the same Vulkan event synchronization primitive between Taichi and the user application. typedef struct TiVulkanEventInteropInfo { // Vulkan event handle. VkEvent event; } TiVulkanEventInteropInfo; // Function `ti_create_vulkan_runtime_ext` -// +// // Creates a Vulkan Taichi runtime with user-controlled capability settings. -TI_DLL_EXPORT TiRuntime TI_API_CALL -ti_create_vulkan_runtime_ext(uint32_t api_version, - uint32_t instance_extension_count, - const char **instance_extensions, - uint32_t device_extension_count, - const char **device_extensions); +TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_vulkan_runtime_ext( + uint32_t api_version, + uint32_t instance_extension_count, + const char** instance_extensions, + uint32_t device_extension_count, + const char** device_extensions +); // Function `ti_import_vulkan_runtime` -// +// // Imports the Vulkan runtime owned by Taichi to external procedures. -TI_DLL_EXPORT TiRuntime TI_API_CALL -ti_import_vulkan_runtime(const TiVulkanRuntimeInteropInfo *interop_info); +TI_DLL_EXPORT TiRuntime TI_API_CALL ti_import_vulkan_runtime( + const TiVulkanRuntimeInteropInfo* interop_info +); // Function `ti_export_vulkan_runtime` -// +// // Exports a Vulkan runtime from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL -ti_export_vulkan_runtime(TiRuntime runtime, - TiVulkanRuntimeInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_runtime( + TiRuntime runtime, + TiVulkanRuntimeInteropInfo* interop_info +); // Function `ti_import_vulkan_memory` -// +// // Imports the Vulkan buffer owned by Taichi to external procedures. -TI_DLL_EXPORT TiMemory TI_API_CALL -ti_import_vulkan_memory(TiRuntime runtime, - const TiVulkanMemoryInteropInfo *interop_info); +TI_DLL_EXPORT TiMemory TI_API_CALL ti_import_vulkan_memory( + TiRuntime runtime, + const TiVulkanMemoryInteropInfo* interop_info +); // Function `ti_export_vulkan_memory` -// +// // Exports a Vulkan buffer from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL -ti_export_vulkan_memory(TiRuntime runtime, - TiMemory memory, - TiVulkanMemoryInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_memory( + TiRuntime runtime, + TiMemory memory, + TiVulkanMemoryInteropInfo* interop_info +); // Function `ti_import_vulkan_image` -// +// // Imports the Vulkan image owned by Taichi to external procedures. -TI_DLL_EXPORT TiImage TI_API_CALL -ti_import_vulkan_image(TiRuntime runtime, - const TiVulkanImageInteropInfo *interop_info, - VkImageViewType view_type, - VkImageLayout layout); +TI_DLL_EXPORT TiImage TI_API_CALL ti_import_vulkan_image( + TiRuntime runtime, + const TiVulkanImageInteropInfo* interop_info, + VkImageViewType view_type, + VkImageLayout layout +); // Function `ti_export_vulkan_image` -// +// // Exports a Vulkan image from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL -ti_export_vulkan_image(TiRuntime runtime, - TiImage image, - TiVulkanImageInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_image( + TiRuntime runtime, + TiImage image, + TiVulkanImageInteropInfo* interop_info +); // Function `ti_import_vulkan_event` -// +// // Imports the Vulkan event owned by Taichi to external procedures. -TI_DLL_EXPORT TiEvent TI_API_CALL -ti_import_vulkan_event(TiRuntime runtime, - const TiVulkanEventInteropInfo *interop_info); +TI_DLL_EXPORT TiEvent TI_API_CALL ti_import_vulkan_event( + TiRuntime runtime, + const TiVulkanEventInteropInfo* interop_info +); // Function `ti_export_vulkan_event` -// +// // Exports a Vulkan event from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL -ti_export_vulkan_event(TiRuntime runtime, - TiEvent event, - TiVulkanEventInteropInfo *interop_info); +TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_event( + TiRuntime runtime, + TiEvent event, + TiVulkanEventInteropInfo* interop_info +); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index 784d47f8ef92e..4551ee4f3ceaf 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -346,7 +346,7 @@ TiMemory ti_allocate_memory(TiRuntime runtime, try { out = ((Runtime *)runtime)->allocate_memory(params); - } catch (const std::bad_alloc &e) { + } catch (const std::bad_alloc& e) { ti_set_last_error(TI_ERROR_OUT_OF_MEMORY, "allocate_memory"); return TI_NULL_HANDLE; } diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index bb1d341662d69..1147d90b20ed6 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -113,3 +113,114 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { inner(TI_ARCH_VULKAN); } + +TEST_F(CapiTest, TestBehaviorAllocateMemory) +{ + TiError error = TI_ERROR_SUCCESS; + + //不同用法测一轮,内存极大测一轮,多种arch测一轮,runtime为空测一波,info为空测一波 + TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + if(ti::is_arch_available(TI_ARCH_VULKAN)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + for(int i = 0;i<4;++i) + { + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; + ti_allocate_memory(runtime,allocate_info); + error = ti_get_last_error(0,nullptr); + //std::cout<size = 1024; + } + allocate_info->size = 1024; + if(ti::is_arch_available(TI_ARCH_CUDA)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_CUDA); + for(int i = 0;i<4;++i) + { + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; + ti_allocate_memory(runtime,allocate_info); + error = ti_get_last_error(0,nullptr); + //std::cout<size = 1024; + } + if(ti::is_arch_available(TI_ARCH_OPENGL)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_OPENGL); + for(int i = 0;i<4;++i) + { + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; + ti_allocate_memory(runtime,allocate_info); + error = ti_get_last_error(0,nullptr); + //std::cout<size = 1024; + } + if(ti::is_arch_available(TI_ARCH_X64)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_X64); + for(int i = 0;i<4;++i) + { + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; + ti_allocate_memory(runtime,allocate_info); + error = ti_get_last_error(0,nullptr); + //std::cout<size = 1024; + } + + ti_allocate_memory(TI_NULL_HANDLE,nullptr); + error = ti_get_last_error(0,nullptr); + TI_ASSERT(error==TI_ERROR_ARGUMENT_NULL); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); + +} + + +TEST_F(CapiTest, TestBehaviorFreeMemory) +{ + if(ti::is_arch_available(TI_ARCH_VULKAN)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime,allocate_info); + ti_free_memory(runtime,memory); + TiError error = ti_get_last_error(0,nullptr); + + TI_ASSERT(error==TI_ERROR_ARGUMENT_NOT_FOUND); + } +} + +TEST_F (CapiTest, TestBehaviorMapMemory) +{ + if(ti::is_arch_available(TI_ARCH_VULKAN)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime,allocate_info); + + } +} diff --git a/c_api/tests/c_api_interface_test.cpp b/c_api/tests/c_api_interface_test.cpp index 95f4464409a50..613406e6e71af 100644 --- a/c_api/tests/c_api_interface_test.cpp +++ b/c_api/tests/c_api_interface_test.cpp @@ -7,8 +7,7 @@ TEST_F(CapiTest, DryRunAvailableArchs) { std::vector archs = ti::get_available_archs(); } -TEST_F(CapiTest, DryRunRuntime) { - { +TEST_F(CapiTest, DryRunRuntime) {{ // CPU Runtime TiArch arch = TiArch::TI_ARCH_X64; ti::Runtime runtime(arch); @@ -38,7 +37,7 @@ TEST_F(CapiTest, DryRunRuntime) { } TEST_F(CapiTest, DryRunCapabilities) { - if (ti::is_arch_available(TI_ARCH_VULKAN)) { + if (ti::is_arch_available(TI_ARCH_VULKAN)) { // Vulkan Runtime { ti::Runtime runtime(TI_ARCH_VULKAN); @@ -95,7 +94,7 @@ TEST_F(CapiTest, SetCapabilities) { } } -TEST_F(CapiTest, DryRunMemoryAllocation) { +TEST_F(CapiTest, DryRunMemoryAllocation) { { // CPU Runtime TiArch arch = TiArch::TI_ARCH_X64; @@ -106,7 +105,7 @@ TEST_F(CapiTest, DryRunMemoryAllocation) { if (ti::is_arch_available(TI_ARCH_VULKAN)) { // Vulkan Runtime - TiArch arch = TiArch::TI_ARCH_VULKAN; + TiArch arch = TiArch::TI_ARCH_VULKAN; ti::Runtime runtime(arch); ti::Memory memory = runtime.allocate_memory(100); ti::NdArray ndarray = runtime.allocate_ndarray({100}, {}); @@ -114,7 +113,7 @@ TEST_F(CapiTest, DryRunMemoryAllocation) { if (ti::is_arch_available(TI_ARCH_OPENGL)) { // Opengl Runtime - TiArch arch = TiArch::TI_ARCH_OPENGL; + TiArch arch = TiArch::TI_ARCH_OPENGL; ti::Runtime runtime(arch); ti::Memory memory = runtime.allocate_memory(100); ti::NdArray ndarray = runtime.allocate_ndarray({100}, {}); diff --git a/setup.py b/setup.py index 5530bffe4e1ac..97f47abf34610 100644 --- a/setup.py +++ b/setup.py @@ -128,7 +128,7 @@ def get_cmake_args(): if use_msbuild: build_options.extend(['-G', 'Visual Studio 17 2022']) else: - build_options.extend(['-G', 'Ninja', '--skip-generator-test']) + build_options.extend(['-G', 'Ninja']) sys.argv[2:2] = build_options cmake_args += [ diff --git a/taichi/rhi/opengl/opengl_device.cpp b/taichi/rhi/opengl/opengl_device.cpp index ede8b1576a48c..ff15f666ef633 100644 --- a/taichi/rhi/opengl/opengl_device.cpp +++ b/taichi/rhi/opengl/opengl_device.cpp @@ -556,6 +556,13 @@ DeviceAllocation GLDevice::allocate_memory(const AllocParams ¶ms) { } check_opengl_error("glBufferData"); + if(alloc_res==GL_OUT_OF_MEMORY) + { + throw std::bad_alloc(); + } + check_opengl_error("glBufferData"); + + DeviceAllocation alloc; alloc.device = this; alloc.alloc_id = buffer; From 77f81fae62685ffbc3ec1d766d7013a4b3fc152b Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Wed, 7 Dec 2022 16:23:24 +0800 Subject: [PATCH 02/42] MapMemory --- c_api/tests/c_api_behavior_test.cpp | 82 ++++++++++++++--------------- taichi/rhi/opengl/opengl_device.cpp | 1 - 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 1147d90b20ed6..1003ccc13e415 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -118,7 +118,7 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; - //不同用法测一轮,内存极大测一轮,多种arch测一轮,runtime为空测一波,info为空测一波 + TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; allocate_info->size = 1024; if(ti::is_arch_available(TI_ARCH_VULKAN)) @@ -139,22 +139,7 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) allocate_info->size = 1024; } allocate_info->size = 1024; - if(ti::is_arch_available(TI_ARCH_CUDA)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_CUDA); - for(int i = 0;i<4;++i) - { - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; - ti_allocate_memory(runtime,allocate_info); - error = ti_get_last_error(0,nullptr); - //std::cout<size = 1024; - } + if(ti::is_arch_available(TI_ARCH_OPENGL)) { TiRuntime runtime = ti_create_runtime(TI_ARCH_OPENGL); @@ -171,31 +156,13 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) TI_ASSERT(error==TI_ERROR_OUT_OF_MEMORY); allocate_info->size = 1024; } - if(ti::is_arch_available(TI_ARCH_X64)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_X64); - for(int i = 0;i<4;++i) - { - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; - ti_allocate_memory(runtime,allocate_info); - error = ti_get_last_error(0,nullptr); - //std::cout<size = 1024; - } ti_allocate_memory(TI_NULL_HANDLE,nullptr); error = ti_get_last_error(0,nullptr); TI_ASSERT(error==TI_ERROR_ARGUMENT_NULL); ti_set_last_error(TI_ERROR_SUCCESS,nullptr); - } - TEST_F(CapiTest, TestBehaviorFreeMemory) { if(ti::is_arch_available(TI_ARCH_VULKAN)) @@ -207,20 +174,53 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) TiMemory memory = ti_allocate_memory(runtime,allocate_info); ti_free_memory(runtime,memory); TiError error = ti_get_last_error(0,nullptr); - - TI_ASSERT(error==TI_ERROR_ARGUMENT_NOT_FOUND); + TI_ASSERT(error == TI_ERROR_SUCCESS); } } TEST_F (CapiTest, TestBehaviorMapMemory) { + TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; if(ti::is_arch_available(TI_ARCH_VULKAN)) { TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(runtime,allocate_info); - + ti_map_memory(runtime,memory); + TiError error = ti_get_last_error(0,nullptr); + TI_ASSERT(error == TI_ERROR_SUCCESS); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); } + if(ti::is_arch_available(TI_ARCH_CUDA)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_CUDA); + TiMemory memory = ti_allocate_memory(runtime,allocate_info); + ti_map_memory(runtime,memory); + TiError error = ti_get_last_error(0,nullptr); + TI_ASSERT(error == TI_ERROR_SUCCESS); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); + } + if(ti::is_arch_available(TI_ARCH_X64)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_X64); + TiMemory memory = ti_allocate_memory(runtime,allocate_info); + ti_map_memory(runtime,memory); + TiError error = ti_get_last_error(0,nullptr); + TI_ASSERT(error == TI_ERROR_SUCCESS); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); + } + if(ti::is_arch_available(TI_ARCH_OPENGL)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_OPENGL); + TiMemory memory = ti_allocate_memory(runtime,allocate_info); + ti_map_memory(runtime,memory); + TiError error = ti_get_last_error(0,nullptr); + TI_ASSERT(error == TI_ERROR_SUCCESS); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); + } + ti_map_memory(TI_NULL_HANDLE,TI_NULL_HANDLE); + TiError error = ti_get_last_error(0,nullptr); + TI_ASSERT(error,TI_ERROR_ARGUMENT_NULL); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); } diff --git a/taichi/rhi/opengl/opengl_device.cpp b/taichi/rhi/opengl/opengl_device.cpp index ff15f666ef633..e2df31075bd34 100644 --- a/taichi/rhi/opengl/opengl_device.cpp +++ b/taichi/rhi/opengl/opengl_device.cpp @@ -546,7 +546,6 @@ DeviceAllocation GLDevice::allocate_memory(const AllocParams ¶ms) { check_opengl_error("glGenBuffers"); glBindBuffer(target_hint, buffer); check_opengl_error("glBindBuffer"); - glBufferData(target_hint, params.size, nullptr, params.host_read ? GL_STATIC_COPY : GL_DYNAMIC_READ); GLuint alloc_res = glGetError(); From fa98a3c3de4263d8717b36199fa8a482c92c65db Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Thu, 8 Dec 2022 10:49:17 +0800 Subject: [PATCH 03/42] testAllocate/freeImage --- c_api/tests/c_api_behavior_test.cpp | 113 ++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 1003ccc13e415..102dc6751c8a3 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -224,3 +224,116 @@ TEST_F (CapiTest, TestBehaviorMapMemory) TI_ASSERT(error,TI_ERROR_ARGUMENT_NULL); ti_set_last_error(TI_ERROR_SUCCESS,nullptr); } + +TEST_F (CapiTest, TestBehaviorUnmapMemory) +{ + TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + if(ti::is_arch_available(TI_ARCH_VULKAN)) + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + TiMemory memory = ti_allocate_memory(runtime,allocate_info); + ti_map_memory(runtime,memory); + ti_unmap_memory(runtime,memory); + TiError error = ti_get_last_error(0,nullptr); + TI_ASSERT(error == TI_ERROR_SUCCESS); + ti_set_last_error(TI_ERROR_SUCCESS,nullptr); + } +} + +TEST_F (CapiTest,TestBehaviorAllocateImage) +{ + TiError error = TI_ERROR_SUCCESS; + TiImageExtent extent; + extent.height=512; + extent.width = 512; + extent.depth = 1; + extent.array_layer_count = 1; + TiImageAllocateInfo imageAllocateInfo; + imageAllocateInfo.dimension=TI_IMAGE_DIMENSION_2D; + imageAllocateInfo.format = TI_FORMAT_RGBA8; + imageAllocateInfo.extent = extent; + imageAllocateInfo.usage = TI_IMAGE_USAGE_STORAGE_BIT; + imageAllocateInfo.mip_level_count =1; + + if(ti::is_arch_available(TI_ARCH_VULKAN)) + { + std::cout<<"000"< Date: Thu, 8 Dec 2022 15:02:47 +0800 Subject: [PATCH 04/42] testToDstEvent step step step step [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci step testtoDstEvent testtoCopyMemoryDTD testToCopyMemoryDTD1 testToDestroyAOTModule testToGetComputeGraph rm_enter modify_modle_path --- c_api/include/taichi/cpp/taichi.hpp | 3 - c_api/include/taichi/taichi_core.h | 740 ++++++++++-------- c_api/include/taichi/taichi_cpu.h | 18 +- c_api/include/taichi/taichi_cuda.h | 18 +- c_api/include/taichi/taichi_opengl.h | 25 +- c_api/include/taichi/taichi_unity.h | 71 +- c_api/include/taichi/taichi_vulkan.h | 153 ++-- c_api/src/taichi_core_impl.cpp | 7 +- c_api/tests/c_api_behavior_test.cpp | 607 +++++++++----- c_api/tests/c_api_interface_test.cpp | 11 +- taichi/rhi/opengl/opengl_device.cpp | 7 - .../cpp/aot/python_scripts/aot_module_test.py | 34 + .../python_scripts/graph_aot_test_vulkan.py | 53 ++ tests/test_config.json | 12 + 14 files changed, 1080 insertions(+), 679 deletions(-) create mode 100644 tests/cpp/aot/python_scripts/aot_module_test.py create mode 100644 tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index 8bb223387a297..1b96a0906030b 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -20,14 +20,11 @@ inline std::vector get_available_archs() { } inline bool is_arch_available(TiArch arch) { std::vector archs = get_available_archs(); - std::cout << "available archs: "; for (size_t i = 0; i < archs.size(); ++i) { - std::cout << archs[i] << " "; if (archs.at(i) == arch) { return true; } } - std::cout << std::endl; return false; } diff --git a/c_api/include/taichi/taichi_core.h b/c_api/include/taichi/taichi_core.h index 2909fca45c957..d8f7c7febe9da 100644 --- a/c_api/include/taichi/taichi_core.h +++ b/c_api/include/taichi/taichi_core.h @@ -1,11 +1,14 @@ // # Core Functionality -// -// Taichi Core exposes all necessary interfaces for offloading the AOT modules to Taichi. The following is a list of features that are available regardless of your backend. The corresponding APIs are still under development and subject to change. -// +// +// Taichi Core exposes all necessary interfaces for offloading the AOT modules +// to Taichi. The following is a list of features that are available regardless +// of your backend. The corresponding APIs are still under development and +// subject to change. +// // ## Availability -// +// // Taichi C-API intends to support the following backends: -// +// // |Backend |Offload Target |Maintenance Tier | // |------------|-----------------|-----------------| // |Vulkan |GPU |Tier 1 | @@ -14,121 +17,153 @@ // |OpenGL |GPU |Tier 2 | // |DirectX 11 |GPU (Windows) |N/A | // |Metal |GPU (macOS, iOS) |N/A | -// -// The backends with tier-1 support are being developed and tested more intensively. And most new features will be available on Vulkan first because it has the most outstanding cross-platform compatibility among all the tier-1 backends. -// For the backends with tier-2 support, you should expect a delay in the fixes to minor issues. -// -// For convenience, in the following text and other C-API documents, the term *host* refers to the user of the C-API; the term *device* refers to the logical (conceptual) compute device, to which Taichi's runtime offloads its compute tasks. A *device* may not be a physical discrete processor other than the CPU and the *host* may *not* be able to access the memory allocated on the *device*. -// -// Unless otherwise specified, **device**, **backend**, **offload target**, and **GPU** are interchangeable; **host**, **user code**, **user procedure**, and **CPU** are interchangeable. -// +// +// The backends with tier-1 support are being developed and tested more +// intensively. And most new features will be available on Vulkan first because +// it has the most outstanding cross-platform compatibility among all the tier-1 +// backends. For the backends with tier-2 support, you should expect a delay in +// the fixes to minor issues. +// +// For convenience, in the following text and other C-API documents, the term +// *host* refers to the user of the C-API; the term *device* refers to the +// logical (conceptual) compute device, to which Taichi's runtime offloads its +// compute tasks. A *device* may not be a physical discrete processor other than +// the CPU and the *host* may *not* be able to access the memory allocated on +// the *device*. +// +// Unless otherwise specified, **device**, **backend**, **offload target**, and +// **GPU** are interchangeable; **host**, **user code**, **user procedure**, and +// **CPU** are interchangeable. +// // ## HowTo -// +// // The following section provides a brief introduction to the Taichi C-API. -// +// // ### Create and destroy a Runtime Instance -// -// You *must* create a runtime instance before working with Taichi, and *only* one runtime per thread. Currently, we do not officially claim that multiple runtime instances can coexist in a process, but please feel free to [file an issue with us](https://github.com/taichi-dev/taichi/issues) if you run into any problem with runtime instance coexistence. -// +// +// You *must* create a runtime instance before working with Taichi, and *only* +// one runtime per thread. Currently, we do not officially claim that multiple +// runtime instances can coexist in a process, but please feel free to [file an +// issue with us](https://github.com/taichi-dev/taichi/issues) if you run into +// any problem with runtime instance coexistence. +// // ```cpp // TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); // ``` -// +// // When your program runs to the end, ensure that: // - You destroy the runtime instance, -// - All related resources are destroyed before the [`TiRuntime`](#handle-tiruntime) itself. -// +// - All related resources are destroyed before the +// [`TiRuntime`](#handle-tiruntime) itself. +// // ```cpp // ti_destroy_runtime(runtime); // ``` -// +// // ### Allocate and free memory -// -// Allocate a piece of memory that is visible only to the device. On the GPU backends, it usually means that the memory is located in the graphics memory (GRAM). -// +// +// Allocate a piece of memory that is visible only to the device. On the GPU +// backends, it usually means that the memory is located in the graphics memory +// (GRAM). +// // ```cpp // TiMemoryAllocateInfo mai {}; // mai.size = 1024; // Size in bytes. // mai.usage = TI_MEMORY_USAGE_STORAGE_BIT; // TiMemory memory = ti_allocate_memory(runtime, &mai); // ``` -// -// Allocated memory is automatically freed when the related [`TiRuntime`](#handle-tiruntime) is destroyed. You can also manually free the allocated memory. -// +// +// Allocated memory is automatically freed when the related +// [`TiRuntime`](#handle-tiruntime) is destroyed. You can also manually free the +// allocated memory. +// // ```cpp // ti_free_memory(runtime, memory); // ``` -// +// // ### Allocate host-accessible memory -// -// By default, memory allocations are physically or conceptually local to the offload target for performance reasons. You can configure the [`TiMemoryAllocateInfo`](#structure-timemoryallocateinfo) to enable host access to memory allocations. But please note that host-accessible allocations *may* slow down computation on GPU because of the limited bus bandwidth between the host memory and the device. -// -// You *must* set `host_write` to [`TI_TRUE`](#definition-ti_true) to allow zero-copy data streaming to the memory. -// +// +// By default, memory allocations are physically or conceptually local to the +// offload target for performance reasons. You can configure the +// [`TiMemoryAllocateInfo`](#structure-timemoryallocateinfo) to enable host +// access to memory allocations. But please note that host-accessible +// allocations *may* slow down computation on GPU because of the limited bus +// bandwidth between the host memory and the device. +// +// You *must* set `host_write` to [`TI_TRUE`](#definition-ti_true) to allow +// zero-copy data streaming to the memory. +// // ```cpp // TiMemoryAllocateInfo mai {}; // mai.size = 1024; // Size in bytes. // mai.host_write = TI_TRUE; // mai.usage = TI_MEMORY_USAGE_STORAGE_BIT; // TiMemory steaming_memory = ti_allocate_memory(runtime, &mai); -// +// // // ... -// +// // std::vector src = some_random_data_source(); -// +// // void* dst = ti_map_memory(runtime, steaming_memory); // std::memcpy(dst, src.data(), src.size()); // ti_unmap_memory(runtime, streaming_memory); // ``` -// -// To read data back to the host, `host_read` *must* be set to [`TI_TRUE`](#definition-ti_true). -// +// +// To read data back to the host, `host_read` *must* be set to +// [`TI_TRUE`](#definition-ti_true). +// // ```cpp // TiMemoryAllocateInfo mai {}; // mai.size = 1024; // Size in bytes. // mai.host_read = TI_TRUE; // mai.usage = TI_MEMORY_USAGE_STORAGE_BIT; // TiMemory read_back_memory = ti_allocate_memory(runtime, &mai); -// +// // // ... -// +// // std::vector dst(1024); // void* src = ti_map_memory(runtime, read_back_memory); // std::memcpy(dst.data(), src, dst.size()); // ti_unmap_memory(runtime, read_back_memory); -// +// // ti_free_memory(runtime, read_back_memory); // ``` -// +// // > You can set `host_read` and `host_write` at the same time. -// +// // ### Load and destroy a Taichi AOT module -// +// // You can load a Taichi AOT module from the filesystem. -// +// // ```cpp // TiAotModule aot_module = ti_load_aot_module(runtime, "/path/to/aot/module"); // ``` -// -// `/path/to/aot/module` should point to the directory that contains a `metadata.tcb`. -// -// You can destroy an unused AOT module, but please ensure that there is no kernel or compute graph related to it pending to [`ti_submit`](#function-ti_submit). -// +// +// `/path/to/aot/module` should point to the directory that contains a +// `metadata.tcb`. +// +// You can destroy an unused AOT module, but please ensure that there is no +// kernel or compute graph related to it pending to +// [`ti_submit`](#function-ti_submit). +// // ```cpp // ti_destroy_aot_module(aot_module); // ``` -// +// // ### Launch kernels and compute graphs -// -// You can extract kernels and compute graphs from an AOT module. Kernel and compute graphs are a part of the module, so you don't have to destroy them. -// +// +// You can extract kernels and compute graphs from an AOT module. Kernel and +// compute graphs are a part of the module, so you don't have to destroy them. +// // ```cpp // TiKernel kernel = ti_get_aot_module_kernel(aot_module, "foo"); -// TiComputeGraph compute_graph = ti_get_aot_module_compute_graph(aot_module, "bar"); +// TiComputeGraph compute_graph = ti_get_aot_module_compute_graph(aot_module, +// "bar"); // ``` -// -// You can launch a kernel with positional arguments. Please ensure the types, the sizes and the order matches the source code in Python. -// +// +// You can launch a kernel with positional arguments. Please ensure the types, +// the sizes and the order matches the source code in Python. +// // ```cpp // TiNdArray ndarray{}; // ndarray.memory = get_some_memory(); @@ -138,26 +173,27 @@ // ndarray.elem_shape.dims[0] = 4; // ndarray.elem_shape.dims[1] = 4; // ndarray.elem_type = TI_DATA_TYPE_F32; -// +// // std::array args{}; -// +// // TiArgument& arg0 = args[0]; // arg0.type = TI_ARGUMENT_TYPE_I32; // arg0.value.i32 = 123; -// +// // TiArgument& arg1 = args[1]; // arg1.type = TI_ARGUMENT_TYPE_F32; // arg1.value.f32 = 123.0f; -// +// // TiArgument& arg2 = args[2]; // arg2.type = TI_ARGUMENT_TYPE_NDARRAY; // arg2.value.ndarray = ndarray; -// +// // ti_launch_kernel(runtime, kernel, args.size(), args.data()); // ``` -// -// You can launch a compute graph in a similar way. But additionally please ensure the argument names matches those in the Python source. -// +// +// You can launch a compute graph in a similar way. But additionally please +// ensure the argument names matches those in the Python source. +// // ```cpp // std::array named_args{}; // TiNamedArgument& named_arg0 = named_args[0]; @@ -169,122 +205,148 @@ // TiNamedArgument& named_arg2 = named_args[2]; // named_arg2.name = "baz"; // named_arg2.argument = args[2]; -// -// ti_launch_compute_graph(runtime, compute_graph, named_args.size(), named_args.data()); +// +// ti_launch_compute_graph(runtime, compute_graph, named_args.size(), +// named_args.data()); // ``` -// -// When you have launched all kernels and compute graphs for this batch, you should [`ti_submit`](#function-ti_submit) and [`ti_wait`](#function-ti_wait) for the execution to finish. -// +// +// When you have launched all kernels and compute graphs for this batch, you +// should [`ti_submit`](#function-ti_submit) and [`ti_wait`](#function-ti_wait) +// for the execution to finish. +// // ```cpp // ti_submit(runtime); // ti_wait(runtime); // ``` -// -// **WARNING** This part is subject to change. We will introduce multi-queue in the future. -// +// +// **WARNING** This part is subject to change. We will introduce multi-queue in +// the future. +// #pragma once #ifndef TI_C_API_VERSION #define TI_C_API_VERSION 1000002 -#endif // TI_C_API_VERSION +#endif // TI_C_API_VERSION #include #ifdef __cplusplus extern "C" { -#endif // __cplusplus - +#endif // __cplusplus // Alias `TiBool` -// -// A boolean value. Can be either [`TI_TRUE`](#definition-ti_true) or [`TI_FALSE`](#definition-ti_false). Assignment with other values could lead to undefined behavior. +// +// A boolean value. Can be either [`TI_TRUE`](#definition-ti_true) or +// [`TI_FALSE`](#definition-ti_false). Assignment with other values could lead +// to undefined behavior. typedef uint32_t TiBool; // Definition `TI_FALSE` -// +// // A condition or a predicate is not satisfied; a statement is invalid. #define TI_FALSE 0 // Definition `TI_TRUE` -// +// // A condition or a predicate is satisfied; a statement is valid. #define TI_TRUE 1 // Alias `TiFlags` -// -// A bit field that can be used to represent 32 orthogonal flags. Bits unspecified in the corresponding flag enum are ignored. -// -// > Enumerations and bit-field flags in the C-API have a `TI_XXX_MAX_ENUM` case to ensure the enum has a 32-bit range and in-memory size. It has no semantical impact and can be safely ignored. +// +// A bit field that can be used to represent 32 orthogonal flags. Bits +// unspecified in the corresponding flag enum are ignored. +// +// > Enumerations and bit-field flags in the C-API have a `TI_XXX_MAX_ENUM` case +// to ensure the enum has a 32-bit range and in-memory size. It has no +// semantical impact and can be safely ignored. typedef uint32_t TiFlags; // Definition `TI_NULL_HANDLE` -// -// A sentinal invalid handle that will never be produced from a valid call to Taichi C-API. +// +// A sentinal invalid handle that will never be produced from a valid call to +// Taichi C-API. #define TI_NULL_HANDLE 0 // Handle `TiRuntime` -// -// Taichi runtime represents an instance of a logical backend and its internal dynamic state. The user is responsible to synchronize any use of [`TiRuntime`](#handle-tiruntime). The user *must not* manipulate multiple [`TiRuntime`](#handle-tiruntime)s in the same thread. -typedef struct TiRuntime_t* TiRuntime; +// +// Taichi runtime represents an instance of a logical backend and its internal +// dynamic state. The user is responsible to synchronize any use of +// [`TiRuntime`](#handle-tiruntime). The user *must not* manipulate multiple +// [`TiRuntime`](#handle-tiruntime)s in the same thread. +typedef struct TiRuntime_t *TiRuntime; // Handle `TiAotModule` -// -// An ahead-of-time (AOT) compiled Taichi module, which contains a collection of kernels and compute graphs. -typedef struct TiAotModule_t* TiAotModule; +// +// An ahead-of-time (AOT) compiled Taichi module, which contains a collection of +// kernels and compute graphs. +typedef struct TiAotModule_t *TiAotModule; // Handle `TiEvent` -// -// A synchronization primitive to manage device execution flows in multiple queues. -typedef struct TiEvent_t* TiEvent; +// +// A synchronization primitive to manage device execution flows in multiple +// queues. +typedef struct TiEvent_t *TiEvent; // Handle `TiMemory` -// +// // A contiguous allocation of device memory. -typedef struct TiMemory_t* TiMemory; +typedef struct TiMemory_t *TiMemory; // Handle `TiImage` -// +// // A contiguous allocation of device image. -typedef struct TiImage_t* TiImage; +typedef struct TiImage_t *TiImage; // Handle `TiSampler` -// -// An image sampler. [`TI_NULL_HANDLE`](#definition-ti_null_handle) represents a default image sampler provided by the runtime implementation. The filter modes and address modes of default samplers depend on backend implementation. -typedef struct TiSampler_t* TiSampler; +// +// An image sampler. [`TI_NULL_HANDLE`](#definition-ti_null_handle) represents a +// default image sampler provided by the runtime implementation. The filter +// modes and address modes of default samplers depend on backend implementation. +typedef struct TiSampler_t *TiSampler; // Handle `TiKernel` -// +// // A Taichi kernel that can be launched on the offload target for execution. -typedef struct TiKernel_t* TiKernel; +typedef struct TiKernel_t *TiKernel; // Handle `TiComputeGraph` -// -// A collection of Taichi kernels (a compute graph) to launch on the offload target in a predefined order. -typedef struct TiComputeGraph_t* TiComputeGraph; +// +// A collection of Taichi kernels (a compute graph) to launch on the offload +// target in a predefined order. +typedef struct TiComputeGraph_t *TiComputeGraph; // Enumeration `TiError` -// +// // Errors reported by the Taichi C-API. typedef enum TiError { // The Taichi C-API invocation finished gracefully. TI_ERROR_SUCCESS = 0, - // The invoked API, or the combination of parameters is not supported by the Taichi C-API. + // The invoked API, or the combination of parameters is not supported by the + // Taichi C-API. TI_ERROR_NOT_SUPPORTED = -1, // Provided data is corrupted. TI_ERROR_CORRUPTED_DATA = -2, // Provided name does not refer to any existing item. TI_ERROR_NAME_NOT_FOUND = -3, - // One or more function arguments violate constraints specified in C-API documents, or kernel arguments mismatch the kernel argument list defined in the AOT module. + // One or more function arguments violate constraints specified in C-API + // documents, or kernel arguments mismatch the kernel argument list defined in + // the AOT module. TI_ERROR_INVALID_ARGUMENT = -4, // One or more by-reference (pointer) function arguments point to null. TI_ERROR_ARGUMENT_NULL = -5, - // One or more function arguments are out of its acceptable range; or enumeration arguments have undefined value. + // One or more function arguments are out of its acceptable range; or + // enumeration arguments have undefined value. TI_ERROR_ARGUMENT_OUT_OF_RANGE = -6, // One or more kernel arguments are missing. TI_ERROR_ARGUMENT_NOT_FOUND = -7, - // The intended interoperation is not possible on the current arch. For example, attempts to export a Vulkan object from a CUDA runtime are not allowed. + // The intended interoperation is not possible on the current arch. For + // example, attempts to export a Vulkan object from a CUDA runtime are not + // allowed. TI_ERROR_INVALID_INTEROP = -8, - // The Taichi C-API enters an unrecoverable invalid state. Related Taichi objects are potentially corrupted. The users *should* release the contaminated resources for stability. Please feel free to file an issue if you encountered this error in a normal routine. + // The Taichi C-API enters an unrecoverable invalid state. Related Taichi + // objects are potentially corrupted. The users *should* release the + // contaminated resources for stability. Please feel free to file an issue if + // you encountered this error in a normal routine. TI_ERROR_INVALID_STATE = -9, // The AOT module is not compatible with the current runtime. TI_ERROR_INCOMPATIBLE_MODULE = -10, @@ -293,7 +355,7 @@ typedef enum TiError { } TiError; // Enumeration `TiArch` -// +// // Types of backend archs. typedef enum TiArch { // x64 native CPU backend. @@ -354,8 +416,10 @@ typedef struct TiCapabilityLevelInfo { } TiCapabilityLevelInfo; // Enumeration `TiDataType` -// -// Elementary (primitive) data types. There might be vendor-specific constraints on the available data types so it's recommended to use 32-bit data types if multi-platform distribution is desired. +// +// Elementary (primitive) data types. There might be vendor-specific constraints +// on the available data types so it's recommended to use 32-bit data types if +// multi-platform distribution is desired. typedef enum TiDataType { // 16-bit IEEE 754 half-precision floating-point number. TI_DATA_TYPE_F16 = 0, @@ -386,7 +450,7 @@ typedef enum TiDataType { } TiDataType; // Enumeration `TiArgumentType` -// +// // Types of kernel and compute graph argument. typedef enum TiArgumentType { // 32-bit one's complement signed integer. @@ -401,8 +465,9 @@ typedef enum TiArgumentType { } TiArgumentType; // BitField `TiMemoryUsageFlags` -// -// Usages of a memory allocation. Taichi requires kernel argument memories to be allocated with `TI_MEMORY_USAGE_STORAGE_BIT`. +// +// Usages of a memory allocation. Taichi requires kernel argument memories to be +// allocated with `TI_MEMORY_USAGE_STORAGE_BIT`. typedef enum TiMemoryUsageFlagBits { // The memory can be read/write accessed by any kernel. TI_MEMORY_USAGE_STORAGE_BIT = 1 << 0, @@ -416,7 +481,7 @@ typedef enum TiMemoryUsageFlagBits { typedef TiFlags TiMemoryUsageFlags; // Structure `TiMemoryAllocateInfo` -// +// // Parameters of a newly allocated memory. typedef struct TiMemoryAllocateInfo { // Size of the allocation in bytes. @@ -425,15 +490,18 @@ typedef struct TiMemoryAllocateInfo { TiBool host_write; // True if the host needs to read from the allocated memory. TiBool host_read; - // True if the memory allocation needs to be exported to other backends (e.g., from Vulkan to CUDA). + // True if the memory allocation needs to be exported to other backends (e.g., + // from Vulkan to CUDA). TiBool export_sharing; - // All possible usage of this memory allocation. In most cases, `bit_field.memory_usage.storage` is enough. + // All possible usage of this memory allocation. In most cases, + // `bit_field.memory_usage.storage` is enough. TiMemoryUsageFlags usage; } TiMemoryAllocateInfo; // Structure `TiMemorySlice` -// -// A subsection of a memory allocation. The sum of `offset` and `size` cannot exceed the size of `memory`. +// +// A subsection of a memory allocation. The sum of `offset` and `size` cannot +// exceed the size of `memory`. typedef struct TiMemorySlice { // The subsectioned memory allocation. TiMemory memory; @@ -444,8 +512,9 @@ typedef struct TiMemorySlice { } TiMemorySlice; // Structure `TiNdShape` -// -// Multi-dimensional size of an ND-array. Dimension sizes after `dim_count` are ignored. +// +// Multi-dimensional size of an ND-array. Dimension sizes after `dim_count` are +// ignored. typedef struct TiNdShape { // Number of dimensions. uint32_t dim_count; @@ -454,34 +523,37 @@ typedef struct TiNdShape { } TiNdShape; // Structure `TiNdArray` -// +// // Multi-dimensional array of dense primitive data. typedef struct TiNdArray { // Memory bound to the ND-array. TiMemory memory; // Shape of the ND-array. TiNdShape shape; - // Shape of the ND-array elements. It *must not* be empty for vector or matrix ND-arrays. + // Shape of the ND-array elements. It *must not* be empty for vector or matrix + // ND-arrays. TiNdShape elem_shape; // Primitive data type of the ND-array elements. TiDataType elem_type; } TiNdArray; // BitField `TiImageUsageFlags` -// -// Usages of an image allocation. Taichi requires kernel argument images to be allocated with `TI_IMAGE_USAGE_STORAGE_BIT` and `TI_IMAGE_USAGE_SAMPLED_BIT`. +// +// Usages of an image allocation. Taichi requires kernel argument images to be +// allocated with `TI_IMAGE_USAGE_STORAGE_BIT` and `TI_IMAGE_USAGE_SAMPLED_BIT`. typedef enum TiImageUsageFlagBits { // The image can be read/write accessed by any kernel. TI_IMAGE_USAGE_STORAGE_BIT = 1 << 0, // The image can be read-only accessed by any kernel. TI_IMAGE_USAGE_SAMPLED_BIT = 1 << 1, - // The image can be used as a color or depth-stencil attachment depending on its format. + // The image can be used as a color or depth-stencil attachment depending on + // its format. TI_IMAGE_USAGE_ATTACHMENT_BIT = 1 << 2, } TiImageUsageFlagBits; typedef TiFlags TiImageUsageFlags; // Enumeration `TiImageDimension` -// +// // Dimensions of an image allocation. typedef enum TiImageDimension { // The image is 1-dimensional. @@ -494,14 +566,16 @@ typedef enum TiImageDimension { TI_IMAGE_DIMENSION_1D_ARRAY = 3, // The image is 2-dimensional and it has one or more layers. TI_IMAGE_DIMENSION_2D_ARRAY = 4, - // The image is 2-dimensional and it has 6 layers for the faces towards +X, -X, +Y, -Y, +Z, -Z in sequence. + // The image is 2-dimensional and it has 6 layers for the faces towards +X, + // -X, +Y, -Y, +Z, -Z in sequence. TI_IMAGE_DIMENSION_CUBE = 5, TI_IMAGE_DIMENSION_MAX_ENUM = 0xffffffff, } TiImageDimension; // Enumeration `TiImageLayout` typedef enum TiImageLayout { - // Undefined layout. An image in this layout does not contain any semantical information. + // Undefined layout. An image in this layout does not contain any semantical + // information. TI_IMAGE_LAYOUT_UNDEFINED = 0, // Optimal layout for read-only access, including sampling. TI_IMAGE_LAYOUT_SHADER_READ = 1, @@ -576,35 +650,52 @@ typedef enum TiFormat { } TiFormat; // Structure `TiImageOffset` -// +// // Offsets of an image in X, Y, Z, and array layers. typedef struct TiImageOffset { // Image offset in the X direction. uint32_t x; - // Image offset in the Y direction. *Must* be 0 if the image has a dimension of `enumeration.image_dimension.1d` or `enumeration.image_dimension.1d_array`. + // Image offset in the Y direction. *Must* be 0 if the image has a dimension + // of `enumeration.image_dimension.1d` or + // `enumeration.image_dimension.1d_array`. uint32_t y; - // Image offset in the Z direction. *Must* be 0 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, `enumeration.image_dimension.1d_array`, `enumeration.image_dimension.2d_array` or `enumeration.image_dimension.cube_array`. + // Image offset in the Z direction. *Must* be 0 if the image has a dimension + // of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, + // `enumeration.image_dimension.1d_array`, + // `enumeration.image_dimension.2d_array` or + // `enumeration.image_dimension.cube_array`. uint32_t z; - // Image offset in array layers. *Must* be 0 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or `enumeration.image_dimension.3d`. + // Image offset in array layers. *Must* be 0 if the image has a dimension of + // `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or + // `enumeration.image_dimension.3d`. uint32_t array_layer_offset; } TiImageOffset; // Structure `TiImageExtent` -// +// // Extents of an image in X, Y, Z, and array layers. typedef struct TiImageExtent { // Image extent in the X direction. uint32_t width; - // Image extent in the Y direction. *Must* be 1 if the image has a dimension of `enumeration.image_dimension.1d` or `enumeration.image_dimension.1d_array`. + // Image extent in the Y direction. *Must* be 1 if the image has a dimension + // of `enumeration.image_dimension.1d` or + // `enumeration.image_dimension.1d_array`. uint32_t height; - // Image extent in the Z direction. *Must* be 1 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, `enumeration.image_dimension.1d_array`, `enumeration.image_dimension.2d_array` or `enumeration.image_dimension.cube_array`. + // Image extent in the Z direction. *Must* be 1 if the image has a dimension + // of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d`, + // `enumeration.image_dimension.1d_array`, + // `enumeration.image_dimension.2d_array` or + // `enumeration.image_dimension.cube_array`. uint32_t depth; - // Image extent in array layers. *Must* be 1 if the image has a dimension of `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or `enumeration.image_dimension.3d`. *Must* be 6 if the image has a dimension of `enumeration.image_dimension.cube_array`. + // Image extent in array layers. *Must* be 1 if the image has a dimension of + // `enumeration.image_dimension.1d`, `enumeration.image_dimension.2d` or + // `enumeration.image_dimension.3d`. *Must* be 6 if the image has a dimension + // of `enumeration.image_dimension.cube_array`. uint32_t array_layer_count; } TiImageExtent; // Structure `TiImageAllocateInfo` -// +// // Parameters of a newly allocated image. typedef struct TiImageAllocateInfo { // Image dimension. @@ -615,15 +706,18 @@ typedef struct TiImageAllocateInfo { uint32_t mip_level_count; // Image texel format. TiFormat format; - // True if the memory allocation needs to be exported to other backends (e.g., from Vulkan to CUDA). + // True if the memory allocation needs to be exported to other backends (e.g., + // from Vulkan to CUDA). TiBool export_sharing; - // All possible usages of this image allocation. In most cases, `bit_field.image_usage.storage` and `bit_field.image_usage.sampled` enough. + // All possible usages of this image allocation. In most cases, + // `bit_field.image_usage.storage` and `bit_field.image_usage.sampled` enough. TiImageUsageFlags usage; } TiImageAllocateInfo; // Structure `TiImageSlice` -// -// A subsection of a memory allocation. The sum of `offset` and `extent` in each dimension cannot exceed the size of `image`. +// +// A subsection of a memory allocation. The sum of `offset` and `extent` in each +// dimension cannot exceed the size of `image`. typedef struct TiImageSlice { // The subsectioned image allocation. TiImage image; @@ -659,12 +753,13 @@ typedef struct TiSamplerCreateInfo { } TiSamplerCreateInfo; // Structure `TiTexture` -// +// // Image data bound to a sampler. typedef struct TiTexture { // Image bound to the texture. TiImage image; - // The bound sampler that controls the sampling behavior of `structure.texture.image`. + // The bound sampler that controls the sampling behavior of + // `structure.texture.image`. TiSampler sampler; // Image Dimension. TiImageDimension dimension; @@ -675,7 +770,7 @@ typedef struct TiTexture { } TiTexture; // Union `TiArgumentValue` -// +// // A scalar or structured argument value. typedef union TiArgumentValue { // Value of a 32-bit one's complement signed integer. @@ -689,7 +784,7 @@ typedef union TiArgumentValue { } TiArgumentValue; // Structure `TiArgument` -// +// // An argument value to feed kernels. typedef struct TiArgument { // Type of the argument. @@ -699,61 +794,63 @@ typedef struct TiArgument { } TiArgument; // Structure `TiNamedArgument` -// +// // A named argument value to feed compute graphs. typedef struct TiNamedArgument { // Name of the argument. - const char* name; + const char *name; // Argument body. TiArgument argument; } TiNamedArgument; // Function `ti_get_available_archs` -// -// Gets a list of available archs on the current platform. An arch is only available if: -// +// +// Gets a list of available archs on the current platform. An arch is only +// available if: +// // 1. The Runtime library is compiled with its support; -// 2. The current platform is installed with a capable hardware or an emulation software. -// -// An available arch has at least one device available, i.e., device index 0 is always available. If an arch is not available on the current platform, a call to [`ti_create_runtime`](#function-ti_create_runtime) with that arch is guaranteed failing. -TI_DLL_EXPORT void TI_API_CALL ti_get_available_archs( - uint32_t* arch_count, - TiArch* archs -); +// 2. The current platform is installed with a capable hardware or an emulation +// software. +// +// An available arch has at least one device available, i.e., device index 0 is +// always available. If an arch is not available on the current platform, a call +// to [`ti_create_runtime`](#function-ti_create_runtime) with that arch is +// guaranteed failing. +TI_DLL_EXPORT void TI_API_CALL ti_get_available_archs(uint32_t *arch_count, + TiArch *archs); // Function `ti_get_last_error` -// -// Gets the last error raised by Taichi C-API invocations. Returns the semantical error code. +// +// Gets the last error raised by Taichi C-API invocations. Returns the +// semantical error code. TI_DLL_EXPORT TiError TI_API_CALL ti_get_last_error( - // Size of textual error message in `function.get_last_error.message` - uint64_t message_size, - // Text buffer for the textual error message. Ignored when `message_size` is 0. - char* message -); + // Size of textual error message in `function.get_last_error.message` + uint64_t message_size, + // Text buffer for the textual error message. Ignored when `message_size` is + // 0. + char *message); // Function `ti_set_last_error` -// -// Sets the provided error as the last error raised by Taichi C-API invocations. It can be useful in extended validation procedures in Taichi C-API wrappers and helper libraries. +// +// Sets the provided error as the last error raised by Taichi C-API invocations. +// It can be useful in extended validation procedures in Taichi C-API wrappers +// and helper libraries. TI_DLL_EXPORT void TI_API_CALL ti_set_last_error( - // Semantical error code. - TiError error, - // A null-terminated string of the textual error message or `nullptr` for empty error message. - const char* message -); + // Semantical error code. + TiError error, + // A null-terminated string of the textual error message or `nullptr` for + // empty error message. + const char *message); // Function `ti_create_runtime` -// +// // Creates a Taichi Runtime with the specified [`TiArch`](#enumeration-tiarch). -TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime( - TiArch arch -); +TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime(TiArch arch); // Function `ti_destroy_runtime` -// +// // Destroys a Taichi Runtime. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_runtime( - TiRuntime runtime -); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_runtime(TiRuntime runtime); // Function `ti_set_runtime_capabilities_ext` TI_DLL_EXPORT void TI_API_CALL @@ -772,214 +869,185 @@ ti_get_runtime_capabilities(TiRuntime runtime, TiCapabilityLevelInfo *capabilities); // Function `ti_allocate_memory` -// +// // Allocates a contiguous device memory with provided parameters. -TI_DLL_EXPORT TiMemory TI_API_CALL ti_allocate_memory( - TiRuntime runtime, - const TiMemoryAllocateInfo* allocate_info -); +TI_DLL_EXPORT TiMemory TI_API_CALL +ti_allocate_memory(TiRuntime runtime, + const TiMemoryAllocateInfo *allocate_info); // Function `ti_free_memory` -// +// // Frees a memory allocation. -TI_DLL_EXPORT void TI_API_CALL ti_free_memory( - TiRuntime runtime, - TiMemory memory -); +TI_DLL_EXPORT void TI_API_CALL ti_free_memory(TiRuntime runtime, + TiMemory memory); // Function `ti_map_memory` -// -// Maps a device memory to a host-addressable space. You *must* ensure that the device is not being used by any device command before the mapping. -TI_DLL_EXPORT void* TI_API_CALL ti_map_memory( - TiRuntime runtime, - TiMemory memory -); +// +// Maps a device memory to a host-addressable space. You *must* ensure that the +// device is not being used by any device command before the mapping. +TI_DLL_EXPORT void *TI_API_CALL ti_map_memory(TiRuntime runtime, + TiMemory memory); // Function `ti_unmap_memory` -// -// Unmaps a device memory and makes any host-side changes about the memory visible to the device. You *must* ensure that there is no further access to the previously mapped host-addressable space. -TI_DLL_EXPORT void TI_API_CALL ti_unmap_memory( - TiRuntime runtime, - TiMemory memory -); +// +// Unmaps a device memory and makes any host-side changes about the memory +// visible to the device. You *must* ensure that there is no further access to +// the previously mapped host-addressable space. +TI_DLL_EXPORT void TI_API_CALL ti_unmap_memory(TiRuntime runtime, + TiMemory memory); // Function `ti_allocate_image` -// +// // Allocates a device image with provided parameters. -TI_DLL_EXPORT TiImage TI_API_CALL ti_allocate_image( - TiRuntime runtime, - const TiImageAllocateInfo* allocate_info -); +TI_DLL_EXPORT TiImage TI_API_CALL +ti_allocate_image(TiRuntime runtime, const TiImageAllocateInfo *allocate_info); // Function `ti_free_image` -// +// // Frees an image allocation. -TI_DLL_EXPORT void TI_API_CALL ti_free_image( - TiRuntime runtime, - TiImage image -); +TI_DLL_EXPORT void TI_API_CALL ti_free_image(TiRuntime runtime, TiImage image); // Function `ti_create_sampler` -TI_DLL_EXPORT TiSampler TI_API_CALL ti_create_sampler( - TiRuntime runtime, - const TiSamplerCreateInfo* create_info -); +TI_DLL_EXPORT TiSampler TI_API_CALL +ti_create_sampler(TiRuntime runtime, const TiSamplerCreateInfo *create_info); // Function `ti_destroy_sampler` -TI_DLL_EXPORT void TI_API_CALL ti_destroy_sampler( - TiRuntime runtime, - TiSampler sampler -); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_sampler(TiRuntime runtime, + TiSampler sampler); // Function `ti_create_event` -// +// // Creates an event primitive. -TI_DLL_EXPORT TiEvent TI_API_CALL ti_create_event( - TiRuntime runtime -); +TI_DLL_EXPORT TiEvent TI_API_CALL ti_create_event(TiRuntime runtime); // Function `ti_destroy_event` -// +// // Destroys an event primitive. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_event( - TiEvent event -); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_event(TiEvent event); // Function `ti_copy_memory_device_to_device` (Device Command) -// -// Copies the data in a contiguous subsection of the device memory to another subsection. The two subsections *must not* overlap. -TI_DLL_EXPORT void TI_API_CALL ti_copy_memory_device_to_device( - TiRuntime runtime, - const TiMemorySlice* dst_memory, - const TiMemorySlice* src_memory -); +// +// Copies the data in a contiguous subsection of the device memory to another +// subsection. The two subsections *must not* overlap. +TI_DLL_EXPORT void TI_API_CALL +ti_copy_memory_device_to_device(TiRuntime runtime, + const TiMemorySlice *dst_memory, + const TiMemorySlice *src_memory); // Function `ti_copy_image_device_to_device` (Device Command) -// -// Copies the image data in a contiguous subsection of the device image to another subsection. The two subsections *must not* overlap. -TI_DLL_EXPORT void TI_API_CALL ti_copy_image_device_to_device( - TiRuntime runtime, - const TiImageSlice* dst_image, - const TiImageSlice* src_image -); +// +// Copies the image data in a contiguous subsection of the device image to +// another subsection. The two subsections *must not* overlap. +TI_DLL_EXPORT void TI_API_CALL +ti_copy_image_device_to_device(TiRuntime runtime, + const TiImageSlice *dst_image, + const TiImageSlice *src_image); // Function `ti_track_image_ext` -// -// Tracks the device image with the provided image layout. Because Taichi tracks image layouts internally, it is *only* useful to inform Taichi that the image is transitioned to a new layout by external procedures. -TI_DLL_EXPORT void TI_API_CALL ti_track_image_ext( - TiRuntime runtime, - TiImage image, - TiImageLayout layout -); +// +// Tracks the device image with the provided image layout. Because Taichi tracks +// image layouts internally, it is *only* useful to inform Taichi that the image +// is transitioned to a new layout by external procedures. +TI_DLL_EXPORT void TI_API_CALL ti_track_image_ext(TiRuntime runtime, + TiImage image, + TiImageLayout layout); // Function `ti_transition_image` (Device Command) -// -// Transitions the image to the provided image layout. Because Taichi tracks image layouts internally, it is *only* useful to enforce an image layout for external procedures to use. -TI_DLL_EXPORT void TI_API_CALL ti_transition_image( - TiRuntime runtime, - TiImage image, - TiImageLayout layout -); +// +// Transitions the image to the provided image layout. Because Taichi tracks +// image layouts internally, it is *only* useful to enforce an image layout for +// external procedures to use. +TI_DLL_EXPORT void TI_API_CALL ti_transition_image(TiRuntime runtime, + TiImage image, + TiImageLayout layout); // Function `ti_launch_kernel` (Device Command) -// -// Launches a Taichi kernel with the provided arguments. The arguments *must* have the same count and types in the same order as in the source code. -TI_DLL_EXPORT void TI_API_CALL ti_launch_kernel( - TiRuntime runtime, - TiKernel kernel, - uint32_t arg_count, - const TiArgument* args -); +// +// Launches a Taichi kernel with the provided arguments. The arguments *must* +// have the same count and types in the same order as in the source code. +TI_DLL_EXPORT void TI_API_CALL ti_launch_kernel(TiRuntime runtime, + TiKernel kernel, + uint32_t arg_count, + const TiArgument *args); // Function `ti_launch_compute_graph` (Device Command) -// -// Launches a Taichi compute graph with provided named arguments. The named arguments *must* have the same count, names, and types as in the source code. -TI_DLL_EXPORT void TI_API_CALL ti_launch_compute_graph( - TiRuntime runtime, - TiComputeGraph compute_graph, - uint32_t arg_count, - const TiNamedArgument* args -); +// +// Launches a Taichi compute graph with provided named arguments. The named +// arguments *must* have the same count, names, and types as in the source code. +TI_DLL_EXPORT void TI_API_CALL +ti_launch_compute_graph(TiRuntime runtime, + TiComputeGraph compute_graph, + uint32_t arg_count, + const TiNamedArgument *args); // Function `ti_signal_event` (Device Command) -// -// Sets an event primitive to a signaled state so that the queues waiting for it can go on execution. If the event has been signaled, you *must* call [`ti_reset_event`](#function-ti_reset_event-device-command) to reset it; otherwise, an undefined behavior would occur. -TI_DLL_EXPORT void TI_API_CALL ti_signal_event( - TiRuntime runtime, - TiEvent event -); +// +// Sets an event primitive to a signaled state so that the queues waiting for it +// can go on execution. If the event has been signaled, you *must* call +// [`ti_reset_event`](#function-ti_reset_event-device-command) to reset it; +// otherwise, an undefined behavior would occur. +TI_DLL_EXPORT void TI_API_CALL ti_signal_event(TiRuntime runtime, + TiEvent event); // Function `ti_reset_event` (Device Command) -// +// // Sets a signaled event primitive back to an unsignaled state. -TI_DLL_EXPORT void TI_API_CALL ti_reset_event( - TiRuntime runtime, - TiEvent event -); +TI_DLL_EXPORT void TI_API_CALL ti_reset_event(TiRuntime runtime, TiEvent event); // Function `ti_wait_event` (Device Command) -// -// Waits until an event primitive transitions to a signaled state. The awaited event *must* be signaled by an external procedure or a previous invocation to [`ti_reset_event`](#function-ti_reset_event-device-command); otherwise, an undefined behavior would occur. -TI_DLL_EXPORT void TI_API_CALL ti_wait_event( - TiRuntime runtime, - TiEvent event -); +// +// Waits until an event primitive transitions to a signaled state. The awaited +// event *must* be signaled by an external procedure or a previous invocation to +// [`ti_reset_event`](#function-ti_reset_event-device-command); otherwise, an +// undefined behavior would occur. +TI_DLL_EXPORT void TI_API_CALL ti_wait_event(TiRuntime runtime, TiEvent event); // Function `ti_submit` -// -// Submits all previously invoked device commands to the offload device for execution. -TI_DLL_EXPORT void TI_API_CALL ti_submit( - TiRuntime runtime -); +// +// Submits all previously invoked device commands to the offload device for +// execution. +TI_DLL_EXPORT void TI_API_CALL ti_submit(TiRuntime runtime); // Function `ti_wait` -// -// Waits until all previously invoked device commands are executed. Any invoked command that has not been submitted is submitted first. -TI_DLL_EXPORT void TI_API_CALL ti_wait( - TiRuntime runtime -); +// +// Waits until all previously invoked device commands are executed. Any invoked +// command that has not been submitted is submitted first. +TI_DLL_EXPORT void TI_API_CALL ti_wait(TiRuntime runtime); // Function `ti_load_aot_module` -// +// // Loads a pre-compiled AOT module from the file system. -// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the runtime fails to load the AOT module from the specified path. -TI_DLL_EXPORT TiAotModule TI_API_CALL ti_load_aot_module( - TiRuntime runtime, - const char* module_path -); +// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the runtime fails +// to load the AOT module from the specified path. +TI_DLL_EXPORT TiAotModule TI_API_CALL +ti_load_aot_module(TiRuntime runtime, const char *module_path); // Function `ti_create_aot_module` -TI_DLL_EXPORT TiAotModule TI_API_CALL ti_create_aot_module( - TiRuntime runtime, - const void* tcm, - uint64_t size -); +TI_DLL_EXPORT TiAotModule TI_API_CALL ti_create_aot_module(TiRuntime runtime, + const void *tcm, + uint64_t size); // Function `ti_destroy_aot_module` -// +// // Destroys a loaded AOT module and releases all related resources. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_aot_module( - TiAotModule aot_module -); +TI_DLL_EXPORT void TI_API_CALL ti_destroy_aot_module(TiAotModule aot_module); // Function `ti_get_aot_module_kernel` -// +// // Retrieves a pre-compiled Taichi kernel from the AOT module. -// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not have a kernel of the specified name. -TI_DLL_EXPORT TiKernel TI_API_CALL ti_get_aot_module_kernel( - TiAotModule aot_module, - const char* name -); +// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not +// have a kernel of the specified name. +TI_DLL_EXPORT TiKernel TI_API_CALL +ti_get_aot_module_kernel(TiAotModule aot_module, const char *name); // Function `ti_get_aot_module_compute_graph` -// +// // Retrieves a pre-compiled compute graph from the AOT module. -// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not have a compute graph of the specified name. -TI_DLL_EXPORT TiComputeGraph TI_API_CALL ti_get_aot_module_compute_graph( - TiAotModule aot_module, - const char* name -); +// Returns [`TI_NULL_HANDLE`](#definition-ti_null_handle) if the module does not +// have a compute graph of the specified name. +TI_DLL_EXPORT TiComputeGraph TI_API_CALL +ti_get_aot_module_compute_graph(TiAotModule aot_module, const char *name); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_cpu.h b/c_api/include/taichi/taichi_cpu.h index 58656f3a8374d..ca0f7e7031462 100644 --- a/c_api/include/taichi/taichi_cpu.h +++ b/c_api/include/taichi/taichi_cpu.h @@ -4,22 +4,20 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus - +#endif // __cplusplus // Structure `TiCpuMemoryInteropInfo` typedef struct TiCpuMemoryInteropInfo { - void* ptr; + void *ptr; uint64_t size; } TiCpuMemoryInteropInfo; // Function `ti_export_cpu_memory` -TI_DLL_EXPORT void TI_API_CALL ti_export_cpu_memory( - TiRuntime runtime, - TiMemory memory, - TiCpuMemoryInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_cpu_memory(TiRuntime runtime, + TiMemory memory, + TiCpuMemoryInteropInfo *interop_info); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_cuda.h b/c_api/include/taichi/taichi_cuda.h index 350269f859af9..485953966a159 100644 --- a/c_api/include/taichi/taichi_cuda.h +++ b/c_api/include/taichi/taichi_cuda.h @@ -4,22 +4,20 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus - +#endif // __cplusplus // Structure `TiCudaMemoryInteropInfo` typedef struct TiCudaMemoryInteropInfo { - void* ptr; + void *ptr; uint64_t size; } TiCudaMemoryInteropInfo; // Function `ti_export_cuda_memory` -TI_DLL_EXPORT void TI_API_CALL ti_export_cuda_memory( - TiRuntime runtime, - TiMemory memory, - TiCudaMemoryInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_cuda_memory(TiRuntime runtime, + TiMemory memory, + TiCudaMemoryInteropInfo *interop_info); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_opengl.h b/c_api/include/taichi/taichi_opengl.h index 34ef146c645f8..0522de61ce047 100644 --- a/c_api/include/taichi/taichi_opengl.h +++ b/c_api/include/taichi/taichi_opengl.h @@ -4,8 +4,7 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus - +#endif // __cplusplus // Structure `TiOpenglMemoryInteropInfo` typedef struct TiOpenglMemoryInteropInfo { @@ -14,19 +13,17 @@ typedef struct TiOpenglMemoryInteropInfo { } TiOpenglMemoryInteropInfo; // Function `ti_import_opengl_memory` -TI_DLL_EXPORT void TI_API_CALL ti_import_opengl_memory( - TiRuntime runtime, - TiMemory memory, - TiOpenglMemoryInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_import_opengl_memory(TiRuntime runtime, + TiMemory memory, + TiOpenglMemoryInteropInfo *interop_info); // Function `ti_export_opengl_memory` -TI_DLL_EXPORT void TI_API_CALL ti_export_opengl_memory( - TiRuntime runtime, - TiMemory memory, - TiOpenglMemoryInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_opengl_memory(TiRuntime runtime, + TiMemory memory, + TiOpenglMemoryInteropInfo *interop_info); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_unity.h b/c_api/include/taichi/taichi_unity.h index 6f4c6f5f4e734..43e8b5da2ebfa 100644 --- a/c_api/include/taichi/taichi_unity.h +++ b/c_api/include/taichi/taichi_unity.h @@ -4,61 +4,52 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus - +#endif // __cplusplus // Handle `TixNativeBufferUnity` -typedef struct TixNativeBufferUnity_t* TixNativeBufferUnity; +typedef struct TixNativeBufferUnity_t *TixNativeBufferUnity; // Function `tix_import_native_runtime_unity` -TI_DLL_EXPORT TiRuntime TI_API_CALL tix_import_native_runtime_unity( -); +TI_DLL_EXPORT TiRuntime TI_API_CALL tix_import_native_runtime_unity(); // Function `tix_launch_kernel_async_unity` -TI_DLL_EXPORT void TI_API_CALL tix_launch_kernel_async_unity( - TiRuntime runtime, - TiKernel kernel, - uint32_t arg_count, - const TiArgument* args -); +TI_DLL_EXPORT void TI_API_CALL +tix_launch_kernel_async_unity(TiRuntime runtime, + TiKernel kernel, + uint32_t arg_count, + const TiArgument *args); // Function `tix_launch_compute_graph_async_unity` -TI_DLL_EXPORT void TI_API_CALL tix_launch_compute_graph_async_unity( - TiRuntime runtime, - TiComputeGraph compute_graph, - uint32_t arg_count, - const TiNamedArgument* args -); +TI_DLL_EXPORT void TI_API_CALL +tix_launch_compute_graph_async_unity(TiRuntime runtime, + TiComputeGraph compute_graph, + uint32_t arg_count, + const TiNamedArgument *args); // Function `tix_copy_memory_to_native_buffer_async_unity` -TI_DLL_EXPORT void TI_API_CALL tix_copy_memory_to_native_buffer_async_unity( - TiRuntime runtime, - TixNativeBufferUnity dst, - uint64_t dst_offset, - const TiMemorySlice* src -); +TI_DLL_EXPORT void TI_API_CALL +tix_copy_memory_to_native_buffer_async_unity(TiRuntime runtime, + TixNativeBufferUnity dst, + uint64_t dst_offset, + const TiMemorySlice *src); // Function `tix_copy_memory_device_to_host_unity` -TI_DLL_EXPORT void TI_API_CALL tix_copy_memory_device_to_host_unity( - TiRuntime runtime, - void* dst, - uint64_t dst_offset, - const TiMemorySlice* src -); +TI_DLL_EXPORT void TI_API_CALL +tix_copy_memory_device_to_host_unity(TiRuntime runtime, + void *dst, + uint64_t dst_offset, + const TiMemorySlice *src); // Function `tix_copy_memory_host_to_device_unity` -TI_DLL_EXPORT void TI_API_CALL tix_copy_memory_host_to_device_unity( - TiRuntime runtime, - const TiMemorySlice* dst, - const void* src, - uint64_t src_offset -); +TI_DLL_EXPORT void TI_API_CALL +tix_copy_memory_host_to_device_unity(TiRuntime runtime, + const TiMemorySlice *dst, + const void *src, + uint64_t src_offset); // Function `tix_submit_async_unity` -TI_DLL_EXPORT void* TI_API_CALL tix_submit_async_unity( - TiRuntime runtime -); +TI_DLL_EXPORT void *TI_API_CALL tix_submit_async_unity(TiRuntime runtime); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/include/taichi/taichi_vulkan.h b/c_api/include/taichi/taichi_vulkan.h index a7c68708248bd..2a440092013fb 100644 --- a/c_api/include/taichi/taichi_vulkan.h +++ b/c_api/include/taichi/taichi_vulkan.h @@ -1,22 +1,26 @@ // # Vulkan Backend Features -// -// Taichi's Vulkan API gives you further control over the Vulkan version and extension requirements and allows you to interop with external Vulkan applications with shared resources. -// +// +// Taichi's Vulkan API gives you further control over the Vulkan version and +// extension requirements and allows you to interop with external Vulkan +// applications with shared resources. +// #pragma once #include #ifdef __cplusplus extern "C" { -#endif // __cplusplus - +#endif // __cplusplus // Structure `TiVulkanRuntimeInteropInfo` -// -// Necessary detail to share the same Vulkan runtime between Taichi and external procedures. -// -// -// **NOTE** `compute_queue` and `graphics_queue` can be the same if the queue family have `VK_QUEUE_COMPUTE_BIT` and `VK_QUEUE_GRAPHICS_BIT` set at the same tiem. +// +// Necessary detail to share the same Vulkan runtime between Taichi and external +// procedures. +// +// +// **NOTE** `compute_queue` and `graphics_queue` can be the same if the queue +// family have `VK_QUEUE_COMPUTE_BIT` and `VK_QUEUE_GRAPHICS_BIT` set at the +// same tiem. typedef struct TiVulkanRuntimeInteropInfo { // Pointer to Vulkan loader function `vkGetInstanceProcAddr`. PFN_vkGetInstanceProcAddr get_instance_proc_addr; @@ -28,35 +32,41 @@ typedef struct TiVulkanRuntimeInteropInfo { VkPhysicalDevice physical_device; // Vulkan logical device handle. VkDevice device; - // Vulkan queue handle created in the queue family at `structure.vulkan_runtime_interop_info.compute_queue_family_index`. + // Vulkan queue handle created in the queue family at + // `structure.vulkan_runtime_interop_info.compute_queue_family_index`. VkQueue compute_queue; // Index of a Vulkan queue family with the `VK_QUEUE_COMPUTE_BIT` set. uint32_t compute_queue_family_index; - // Vulkan queue handle created in the queue family at `structure.vulkan_runtime_interop_info.graphics_queue_family_index`. + // Vulkan queue handle created in the queue family at + // `structure.vulkan_runtime_interop_info.graphics_queue_family_index`. VkQueue graphics_queue; // Index of a Vulkan queue family with the `VK_QUEUE_GRAPHICS_BIT` set. uint32_t graphics_queue_family_index; } TiVulkanRuntimeInteropInfo; // Structure `TiVulkanMemoryInteropInfo` -// -// Necessary detail to share the same piece of Vulkan buffer between Taichi and external procedures. +// +// Necessary detail to share the same piece of Vulkan buffer between Taichi and +// external procedures. typedef struct TiVulkanMemoryInteropInfo { // Vulkan buffer. VkBuffer buffer; // Size of the piece of memory in bytes. uint64_t size; - // Vulkan buffer usage. In most of the cases, Taichi requires the `VK_BUFFER_USAGE_STORAGE_BUFFER_BIT`. + // Vulkan buffer usage. In most of the cases, Taichi requires the + // `VK_BUFFER_USAGE_STORAGE_BUFFER_BIT`. VkBufferUsageFlags usage; // Device memory binded to the Vulkan buffer. VkDeviceMemory memory; - // Offset in `VkDeviceMemory` object to the beginning of this allocation, in bytes. + // Offset in `VkDeviceMemory` object to the beginning of this allocation, in + // bytes. uint64_t offset; } TiVulkanMemoryInteropInfo; // Structure `TiVulkanImageInteropInfo` -// -// Necessary detail to share the same piece of Vulkan image between Taichi and external procedures. +// +// Necessary detail to share the same piece of Vulkan image between Taichi and +// external procedures. typedef struct TiVulkanImageInteropInfo { // Vulkan image. VkImage image; @@ -74,97 +84,90 @@ typedef struct TiVulkanImageInteropInfo { VkSampleCountFlagBits sample_count; // Image tiling. VkImageTiling tiling; - // Vulkan image usage. In most cases, Taichi requires the `VK_IMAGE_USAGE_STORAGE_BIT` and the `VK_IMAGE_USAGE_SAMPLED_BIT`. + // Vulkan image usage. In most cases, Taichi requires the + // `VK_IMAGE_USAGE_STORAGE_BIT` and the `VK_IMAGE_USAGE_SAMPLED_BIT`. VkImageUsageFlags usage; } TiVulkanImageInteropInfo; // Structure `TiVulkanEventInteropInfo` -// -// Necessary detail to share the same Vulkan event synchronization primitive between Taichi and the user application. +// +// Necessary detail to share the same Vulkan event synchronization primitive +// between Taichi and the user application. typedef struct TiVulkanEventInteropInfo { // Vulkan event handle. VkEvent event; } TiVulkanEventInteropInfo; // Function `ti_create_vulkan_runtime_ext` -// +// // Creates a Vulkan Taichi runtime with user-controlled capability settings. -TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_vulkan_runtime_ext( - uint32_t api_version, - uint32_t instance_extension_count, - const char** instance_extensions, - uint32_t device_extension_count, - const char** device_extensions -); +TI_DLL_EXPORT TiRuntime TI_API_CALL +ti_create_vulkan_runtime_ext(uint32_t api_version, + uint32_t instance_extension_count, + const char **instance_extensions, + uint32_t device_extension_count, + const char **device_extensions); // Function `ti_import_vulkan_runtime` -// +// // Imports the Vulkan runtime owned by Taichi to external procedures. -TI_DLL_EXPORT TiRuntime TI_API_CALL ti_import_vulkan_runtime( - const TiVulkanRuntimeInteropInfo* interop_info -); +TI_DLL_EXPORT TiRuntime TI_API_CALL +ti_import_vulkan_runtime(const TiVulkanRuntimeInteropInfo *interop_info); // Function `ti_export_vulkan_runtime` -// +// // Exports a Vulkan runtime from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_runtime( - TiRuntime runtime, - TiVulkanRuntimeInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_vulkan_runtime(TiRuntime runtime, + TiVulkanRuntimeInteropInfo *interop_info); // Function `ti_import_vulkan_memory` -// +// // Imports the Vulkan buffer owned by Taichi to external procedures. -TI_DLL_EXPORT TiMemory TI_API_CALL ti_import_vulkan_memory( - TiRuntime runtime, - const TiVulkanMemoryInteropInfo* interop_info -); +TI_DLL_EXPORT TiMemory TI_API_CALL +ti_import_vulkan_memory(TiRuntime runtime, + const TiVulkanMemoryInteropInfo *interop_info); // Function `ti_export_vulkan_memory` -// +// // Exports a Vulkan buffer from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_memory( - TiRuntime runtime, - TiMemory memory, - TiVulkanMemoryInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_vulkan_memory(TiRuntime runtime, + TiMemory memory, + TiVulkanMemoryInteropInfo *interop_info); // Function `ti_import_vulkan_image` -// +// // Imports the Vulkan image owned by Taichi to external procedures. -TI_DLL_EXPORT TiImage TI_API_CALL ti_import_vulkan_image( - TiRuntime runtime, - const TiVulkanImageInteropInfo* interop_info, - VkImageViewType view_type, - VkImageLayout layout -); +TI_DLL_EXPORT TiImage TI_API_CALL +ti_import_vulkan_image(TiRuntime runtime, + const TiVulkanImageInteropInfo *interop_info, + VkImageViewType view_type, + VkImageLayout layout); // Function `ti_export_vulkan_image` -// +// // Exports a Vulkan image from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_image( - TiRuntime runtime, - TiImage image, - TiVulkanImageInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_vulkan_image(TiRuntime runtime, + TiImage image, + TiVulkanImageInteropInfo *interop_info); // Function `ti_import_vulkan_event` -// +// // Imports the Vulkan event owned by Taichi to external procedures. -TI_DLL_EXPORT TiEvent TI_API_CALL ti_import_vulkan_event( - TiRuntime runtime, - const TiVulkanEventInteropInfo* interop_info -); +TI_DLL_EXPORT TiEvent TI_API_CALL +ti_import_vulkan_event(TiRuntime runtime, + const TiVulkanEventInteropInfo *interop_info); // Function `ti_export_vulkan_event` -// +// // Exports a Vulkan event from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_event( - TiRuntime runtime, - TiEvent event, - TiVulkanEventInteropInfo* interop_info -); +TI_DLL_EXPORT void TI_API_CALL +ti_export_vulkan_event(TiRuntime runtime, + TiEvent event, + TiVulkanEventInteropInfo *interop_info); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index 4551ee4f3ceaf..88d9a9cb2d6b0 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -346,7 +346,7 @@ TiMemory ti_allocate_memory(TiRuntime runtime, try { out = ((Runtime *)runtime)->allocate_memory(params); - } catch (const std::bad_alloc& e) { + } catch (const std::bad_alloc &e) { ti_set_last_error(TI_ERROR_OUT_OF_MEMORY, "allocate_memory"); return TI_NULL_HANDLE; } @@ -496,6 +496,11 @@ void ti_copy_memory_device_to_device(TiRuntime runtime, TI_CAPI_ARGUMENT_NULL(dst_memory->memory); TI_CAPI_ARGUMENT_NULL(src_memory); TI_CAPI_ARGUMENT_NULL(src_memory->memory); + if(dst_memory->size!=src_memory->size) { + ti_set_last_error(TI_ERROR_INVALID_ARGUMENT, + "The size of memory slices are not match"); + return; + } Runtime *runtime2 = (Runtime *)runtime; auto dst = devmem2devalloc(*runtime2, dst_memory->memory) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 102dc6751c8a3..fdf3ed36f3039 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -114,226 +114,477 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocateMemory) -{ +TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; - - - TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - if(ti::is_arch_available(TI_ARCH_VULKAN)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - for(int i = 0;i<4;++i) + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + auto inner = [&](TiArch arch){ + if(ti::is_arch_available(arch)) { - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; - ti_allocate_memory(runtime,allocate_info); - error = ti_get_last_error(0,nullptr); - //std::cout<size = 1024; - } - allocate_info->size = 1024; - - if(ti::is_arch_available(TI_ARCH_OPENGL)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_OPENGL); - for(int i = 0;i<4;++i) - { - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1000000000000000000; - ti_allocate_memory(runtime,allocate_info); - error = ti_get_last_error(0,nullptr); - //std::cout<size = 1024; - } + }; - ti_allocate_memory(TI_NULL_HANDLE,nullptr); - error = ti_get_last_error(0,nullptr); - TI_ASSERT(error==TI_ERROR_ARGUMENT_NULL); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); + inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorFreeMemory) -{ - if(ti::is_arch_available(TI_ARCH_VULKAN)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime,allocate_info); - ti_free_memory(runtime,memory); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error == TI_ERROR_SUCCESS); - } +TEST_F(CapiTest, TestBehaviorFreeMemory) { + + auto inner = [](TiArch arch){ + if(ti::is_arch_available(arch)) { + TiRuntime runtime = ti_create_runtime(arch); + TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, allocate_info); + ti_free_memory(runtime, memory); + CHECK_TAICHI_SUCCESS(); + + //runtime & allocate_info are both null + { + ti_free_memory(TI_NULL_HANDLE,nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + //runtime is null and allocate_info is valid + { + TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, allocate_info); + ti_free_memory(TI_NULL_HANDLE,memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + //runtime is not null and allocate_info is null + { + TiRuntime runtime = ti_create_runtime(arch); + ti_free_memory(runtime,nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + } + }; + inner(TI_ARCH_VULKAN); } -TEST_F (CapiTest, TestBehaviorMapMemory) -{ - TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - if(ti::is_arch_available(TI_ARCH_VULKAN)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemory memory = ti_allocate_memory(runtime,allocate_info); - ti_map_memory(runtime,memory); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error == TI_ERROR_SUCCESS); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); - } - if(ti::is_arch_available(TI_ARCH_CUDA)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_CUDA); - TiMemory memory = ti_allocate_memory(runtime,allocate_info); - ti_map_memory(runtime,memory); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error == TI_ERROR_SUCCESS); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); - } - if(ti::is_arch_available(TI_ARCH_X64)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_X64); - TiMemory memory = ti_allocate_memory(runtime,allocate_info); - ti_map_memory(runtime,memory); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error == TI_ERROR_SUCCESS); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); - } - if(ti::is_arch_available(TI_ARCH_OPENGL)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_OPENGL); - TiMemory memory = ti_allocate_memory(runtime,allocate_info); - ti_map_memory(runtime,memory); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error == TI_ERROR_SUCCESS); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); - } - ti_map_memory(TI_NULL_HANDLE,TI_NULL_HANDLE); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error,TI_ERROR_ARGUMENT_NULL); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); +TEST_F(CapiTest, TestBehaviorMapMemory) { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; + + auto inner = [&](TiArch arch){ + if(ti::is_arch_available(arch)) { + TiRuntime runtime = ti_create_runtime(arch); + TiMemory memory = ti_allocate_memory(runtime,&allocate_info); + ti_map_memory(runtime,memory); + CHECK_TAICHI_SUCCESS(); + + // runtime & memory are both null + { + ti_map_memory(TI_NULL_HANDLE,TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + // runtime is null, memory is valid + { + TiRuntime runtime = ti_create_runtime(arch); + TiMemory memory = ti_allocate_memory(runtime,&allocate_info); + ti_map_memory(TI_NULL_HANDLE,memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + // runtime is valid, memory is null + { + TiRuntime runtime = ti_create_runtime(arch); + ti_map_memory(runtime,TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + } + }; + inner(TI_ARCH_VULKAN); } -TEST_F (CapiTest, TestBehaviorUnmapMemory) -{ - TiMemoryAllocateInfo* allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - if(ti::is_arch_available(TI_ARCH_VULKAN)) - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemory memory = ti_allocate_memory(runtime,allocate_info); - ti_map_memory(runtime,memory); - ti_unmap_memory(runtime,memory); - TiError error = ti_get_last_error(0,nullptr); - TI_ASSERT(error == TI_ERROR_SUCCESS); - ti_set_last_error(TI_ERROR_SUCCESS,nullptr); - } +TEST_F(CapiTest, TestBehaviorUnmapMemory) { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + auto inner = [&](TiArch arch) { + if(ti::is_arch_available(arch)) { + TiRuntime runtime = ti_create_runtime(arch); + for(int i = 0;i<4;++i) + { + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT< archs = ti::get_available_archs(); } -TEST_F(CapiTest, DryRunRuntime) {{ +TEST_F(CapiTest, DryRunRuntime) { + { // CPU Runtime TiArch arch = TiArch::TI_ARCH_X64; ti::Runtime runtime(arch); @@ -37,7 +38,7 @@ TEST_F(CapiTest, DryRunRuntime) {{ } TEST_F(CapiTest, DryRunCapabilities) { - if (ti::is_arch_available(TI_ARCH_VULKAN)) { + if (ti::is_arch_available(TI_ARCH_VULKAN)) { // Vulkan Runtime { ti::Runtime runtime(TI_ARCH_VULKAN); @@ -94,7 +95,7 @@ TEST_F(CapiTest, SetCapabilities) { } } -TEST_F(CapiTest, DryRunMemoryAllocation) { +TEST_F(CapiTest, DryRunMemoryAllocation) { { // CPU Runtime TiArch arch = TiArch::TI_ARCH_X64; @@ -105,7 +106,7 @@ TEST_F(CapiTest, DryRunMemoryAllocation) { if (ti::is_arch_available(TI_ARCH_VULKAN)) { // Vulkan Runtime - TiArch arch = TiArch::TI_ARCH_VULKAN; + TiArch arch = TiArch::TI_ARCH_VULKAN; ti::Runtime runtime(arch); ti::Memory memory = runtime.allocate_memory(100); ti::NdArray ndarray = runtime.allocate_ndarray({100}, {}); @@ -113,7 +114,7 @@ TEST_F(CapiTest, DryRunMemoryAllocation) { if (ti::is_arch_available(TI_ARCH_OPENGL)) { // Opengl Runtime - TiArch arch = TiArch::TI_ARCH_OPENGL; + TiArch arch = TiArch::TI_ARCH_OPENGL; ti::Runtime runtime(arch); ti::Memory memory = runtime.allocate_memory(100); ti::NdArray ndarray = runtime.allocate_ndarray({100}, {}); diff --git a/taichi/rhi/opengl/opengl_device.cpp b/taichi/rhi/opengl/opengl_device.cpp index e2df31075bd34..0c5c377d4295d 100644 --- a/taichi/rhi/opengl/opengl_device.cpp +++ b/taichi/rhi/opengl/opengl_device.cpp @@ -555,13 +555,6 @@ DeviceAllocation GLDevice::allocate_memory(const AllocParams ¶ms) { } check_opengl_error("glBufferData"); - if(alloc_res==GL_OUT_OF_MEMORY) - { - throw std::bad_alloc(); - } - check_opengl_error("glBufferData"); - - DeviceAllocation alloc; alloc.device = this; alloc.alloc_id = buffer; diff --git a/tests/cpp/aot/python_scripts/aot_module_test.py b/tests/cpp/aot/python_scripts/aot_module_test.py new file mode 100644 index 0000000000000..da6184bf474fe --- /dev/null +++ b/tests/cpp/aot/python_scripts/aot_module_test.py @@ -0,0 +1,34 @@ +import argparse +import os + +import taichi as ti + + +def main(arch): + ti.init(arch=arch) + + if ti.lang.impl.current_cfg().arch != arch: + return + + arr = ti.ndarray(int, shape=16) + + assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() + dir_name = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) + + m = ti.aot.Module() + + tcm_path = dir_name + "/module.tcm" + m.save(dir_name) + m.archive(tcm_path) + print(tcm_path) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--arch", type=str) + args = parser.parse_args() + + if args.arch == "vulkan": + main(arch=ti.vulkan) + else: + assert False diff --git a/tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py b/tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py new file mode 100644 index 0000000000000..dfc75d871dc59 --- /dev/null +++ b/tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py @@ -0,0 +1,53 @@ +import argparse +import os + +import taichi as ti + + +def compile_graph_aot(arch): + ti.init(arch=arch) + + if ti.lang.impl.current_cfg().arch != arch: + return + + arr = ti.graph.Arg(ti.graph.ArgKind.NDARRAY, + 'arr', + ti.i32, + field_dim=1, + element_shape=(1, )) + + base0 = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 'base0', ti.i32) + + base1 = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 'base2', ti.i32) + + base2 = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 'base1', ti.i32) + + g_builder = ti.graph.GraphBuilder() + + + run_graph = g_builder.compile() + + assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() + tmpdir = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) + + mod = ti.aot.Module() + mod.add_graph('run_graph', run_graph) + mod.save(tmpdir) + mod.archive(tmpdir+'/module.tcm') + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--arch", type=str) + args = parser.parse_args() + + if args.arch == "cpu": + compile_graph_aot(arch=ti.cpu) + elif args.arch == "cuda": + compile_graph_aot(arch=ti.cuda) + elif args.arch == "vulkan": + compile_graph_aot(arch=ti.vulkan) + elif args.arch == "opengl": + compile_graph_aot(arch=ti.opengl) + else: + assert False diff --git a/tests/test_config.json b/tests/test_config.json index 0064be40d6d1a..d507220d008e9 100644 --- a/tests/test_config.json +++ b/tests/test_config.json @@ -202,6 +202,18 @@ "CapiTest.TestCreateTcmAotModule": [ ["cpp", "aot", "python_scripts", "tcm_test.py"], "--arch=vulkan" + ], + "CapiTest.TestBehaviorLoadAOTModuleVulkan": [ + ["cpp", "aot", "python_scripts", "aot_module_test.py"], + "--arch=vulkan" + ], + "CapiTest.TestBehaviorDestroyAotModuleVulkan": [ + ["cpp", "aot", "python_scripts", "aot_module_test.py"], + "--arch=vulkan" + ], + "CapiTest.TestBehaviorGetCgraphVulkan": [ + ["cpp", "aot", "python_scripts", "graph_aot_test_vulkan.py"], + "--arch=vulkan" ] } } From baa92b83d5ee10c10f2556b74d0d73780b86db55 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 13:03:21 +0800 Subject: [PATCH 05/42] Remove debug code --- c_api/tests/c_api_behavior_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index fdf3ed36f3039..2f2b6b21789fd 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -549,11 +549,10 @@ void test_behavior_destroy_aot_module_impl(TiArch arch){ } TEST_F(CapiTest, TestBehaviorDestroyAotModuleVulkan) { - std::cout << 11111111111111 << std::endl; test_behavior_destroy_aot_module_impl(TI_ARCH_VULKAN); } -void test_behavir_get_Cgraph_impl(TiArch arch) +void test_behavir_get_cgraph_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); const std::string module_path = folder_dir + std::string("/module.tcm"); @@ -585,6 +584,6 @@ void test_behavir_get_Cgraph_impl(TiArch arch) TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { - test_behavir_get_Cgraph_impl(TI_ARCH_VULKAN); + test_behavir_get_cgraph_impl(TI_ARCH_VULKAN); } From 0c058f83862265a9835d64e4579f19af7bf1e784 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 05:04:38 +0000 Subject: [PATCH 06/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/src/taichi_core_impl.cpp | 4 +- c_api/tests/c_api_behavior_test.cpp | 170 ++++++++---------- .../python_scripts/graph_aot_test_vulkan.py | 3 +- 3 files changed, 77 insertions(+), 100 deletions(-) diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index 88d9a9cb2d6b0..b5928f3e90ac1 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -496,10 +496,10 @@ void ti_copy_memory_device_to_device(TiRuntime runtime, TI_CAPI_ARGUMENT_NULL(dst_memory->memory); TI_CAPI_ARGUMENT_NULL(src_memory); TI_CAPI_ARGUMENT_NULL(src_memory->memory); - if(dst_memory->size!=src_memory->size) { + if (dst_memory->size != src_memory->size) { ti_set_last_error(TI_ERROR_INVALID_ARGUMENT, "The size of memory slices are not match"); - return; + return; } Runtime *runtime2 = (Runtime *)runtime; diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 2f2b6b21789fd..af7beb0bb361f 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -118,24 +118,22 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; - auto inner = [&](TiArch arch){ - if(ti::is_arch_available(arch)) - { + auto inner = [&](TiArch arch) { + if (ti::is_arch_available(arch)) { // Attempt to allocate memory with size of 1024 TiRuntime runtime = ti_create_runtime(arch); - for(int i = 0;i<4;++i) - { - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT<size = 1024; @@ -174,26 +171,26 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) { ti_free_memory(runtime, memory); CHECK_TAICHI_SUCCESS(); - //runtime & allocate_info are both null + // runtime & allocate_info are both null { - ti_free_memory(TI_NULL_HANDLE,nullptr); + ti_free_memory(TI_NULL_HANDLE, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - //runtime is null and allocate_info is valid + // runtime is null and allocate_info is valid { TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; allocate_info->size = 1024; allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(runtime, allocate_info); - ti_free_memory(TI_NULL_HANDLE,memory); + ti_free_memory(TI_NULL_HANDLE, memory); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - //runtime is not null and allocate_info is null + // runtime is not null and allocate_info is null { TiRuntime runtime = ti_create_runtime(arch); - ti_free_memory(runtime,nullptr); + ti_free_memory(runtime, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } } @@ -206,31 +203,31 @@ TEST_F(CapiTest, TestBehaviorMapMemory) { allocate_info.size = 1024; allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; - auto inner = [&](TiArch arch){ - if(ti::is_arch_available(arch)) { + auto inner = [&](TiArch arch) { + if (ti::is_arch_available(arch)) { TiRuntime runtime = ti_create_runtime(arch); - TiMemory memory = ti_allocate_memory(runtime,&allocate_info); - ti_map_memory(runtime,memory); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_map_memory(runtime, memory); CHECK_TAICHI_SUCCESS(); // runtime & memory are both null { - ti_map_memory(TI_NULL_HANDLE,TI_NULL_HANDLE); + ti_map_memory(TI_NULL_HANDLE, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } // runtime is null, memory is valid { TiRuntime runtime = ti_create_runtime(arch); - TiMemory memory = ti_allocate_memory(runtime,&allocate_info); - ti_map_memory(TI_NULL_HANDLE,memory); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_map_memory(TI_NULL_HANDLE, memory); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } // runtime is valid, memory is null { TiRuntime runtime = ti_create_runtime(arch); - ti_map_memory(runtime,TI_NULL_HANDLE); + ti_map_memory(runtime, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } } @@ -242,35 +239,34 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; auto inner = [&](TiArch arch) { - if(ti::is_arch_available(arch)) { + if (ti::is_arch_available(arch)) { TiRuntime runtime = ti_create_runtime(arch); - for(int i = 0;i<4;++i) - { - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT< Date: Mon, 12 Dec 2022 14:00:44 +0800 Subject: [PATCH 07/42] step --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index af7beb0bb361f..995cf618f2d07 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -504,7 +504,7 @@ void test_behavior_load_aot_module_impl(TiArch arch) { } // Attempt to load aot module with a invalid path. { - TiAotModule module = ti_load_aot_module(runtime, "ssssss/????//"); + TiAotModule module = ti_load_aot_module(runtime, "ssssss///"); CHECK_TAICHI_ERROR_IS(TI_ERROR_CORRUPTED_DATA); TI_ASSERT(module == TI_NULL_HANDLE); } From 933a5ba11f708eead13b0cc827ae4986be3e981d Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 14:18:01 +0800 Subject: [PATCH 08/42] step --- c_api/tests/c_api_behavior_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 995cf618f2d07..6474d8cbdd0bf 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -275,7 +275,6 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { } TEST_F(CapiTest, TestBehaviorAllocateImage) { - TiError error = TI_ERROR_SUCCESS; TiImageExtent extent; extent.height = 512; extent.width = 512; @@ -335,7 +334,6 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { } TEST_F(CapiTest, TestBehaviorFreeImage) { - TiError error = TI_ERROR_SUCCESS; TiImageExtent extent; extent.height = 512; extent.width = 512; From 7a08028f4d3a295b3d5cd4ac001428c97ae449eb Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 14:53:15 +0800 Subject: [PATCH 09/42] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 97f47abf34610..5530bffe4e1ac 100644 --- a/setup.py +++ b/setup.py @@ -128,7 +128,7 @@ def get_cmake_args(): if use_msbuild: build_options.extend(['-G', 'Visual Studio 17 2022']) else: - build_options.extend(['-G', 'Ninja']) + build_options.extend(['-G', 'Ninja', '--skip-generator-test']) sys.argv[2:2] = build_options cmake_args += [ From 09571647805736ebe23e3ba6612cf935f123854c Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 18:43:13 +0800 Subject: [PATCH 10/42] up --- c_api/tests/c_api_behavior_test.cpp | 96 ++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 6474d8cbdd0bf..f0ce15c0f95bc 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -116,25 +116,27 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; + auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attempt to allocate memory with size of 1024 TiRuntime runtime = ti_create_runtime(arch); for (int i = 0; i < 4; ++i) { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; TiMemory memory = ti_allocate_memory(runtime, &allocate_info); TI_ASSERT(memory != TI_NULL_HANDLE); + ti_free_memory(runtime, memory); } // Attempt to run out of the memory { + TiMemoryAllocateInfo allocate_info; allocate_info.size = 1000000000000000000; ti_allocate_memory(runtime, &allocate_info); error = ti_get_last_error(0, nullptr); - TI_ASSERT(error == TI_ERROR_OUT_OF_MEMORY); - allocate_info.size = 1024; + CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); } // runtime and allocate_info are both null @@ -151,9 +153,13 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { // runtime is null, allocate is not null; { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + + ti_destroy_runtime(runtime); } }; @@ -163,14 +169,15 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { TEST_F(CapiTest, TestBehaviorFreeMemory) { auto inner = [](TiArch arch) { if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, allocate_info); - ti_free_memory(runtime, memory); - CHECK_TAICHI_SUCCESS(); - + { + TiRuntime runtime = ti_create_runtime(arch); + TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, allocate_info); + ti_free_memory(runtime, memory); + CHECK_TAICHI_SUCCESS(); + } // runtime & allocate_info are both null { ti_free_memory(TI_NULL_HANDLE, nullptr); @@ -179,10 +186,11 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) { // runtime is null and allocate_info is valid { - TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, allocate_info); + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); ti_free_memory(TI_NULL_HANDLE, memory); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } @@ -205,10 +213,15 @@ TEST_F(CapiTest, TestBehaviorMapMemory) { auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - ti_map_memory(runtime, memory); - CHECK_TAICHI_SUCCESS(); + { + TiRuntime runtime = ti_create_runtime(arch); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + TI_ASSERT(memory != TI_NULL_HANDLE); + CHECK_TAICHI_SUCCESS(); + ti_map_memory(runtime, memory); + CHECK_TAICHI_SUCCESS(); + ti_unmap_memory(runtime, memory); + } // runtime & memory are both null { @@ -274,7 +287,8 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocateImage) { +TiImageAllocateInfo getImageAllocateInfo() +{ TiImageExtent extent; extent.height = 512; extent.width = 512; @@ -286,25 +300,41 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { imageAllocateInfo.extent = extent; imageAllocateInfo.usage = TI_IMAGE_USAGE_STORAGE_BIT; imageAllocateInfo.mip_level_count = 1; + return imageAllocateInfo; +} + +TEST_F(CapiTest, TestBehaviorAllocateImage) { auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attemp to allocate a normal 2D image - TiRuntime runtime = ti_create_runtime(arch); - TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); - CHECK_TAICHI_SUCCESS(); - TI_ASSERT(image != TI_NULL_HANDLE); + { + auto imageAllocateInfo = getImageAllocateInfo(); + TiRuntime runtime = ti_create_runtime(arch); + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); + CHECK_TAICHI_SUCCESS(); + TI_ASSERT(image != TI_NULL_HANDLE); + ti_free_image(runtime, image); + } // Attemp to allocate a 2D image with invalid demension { + TiRuntime runtime = ti_create_runtime(arch); + auto imageAllocateInfo = getImageAllocateInfo(); + imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_MAX_ENUM; + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_MAX_ENUM; image = ti_allocate_image(runtime, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); - imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_2D; + TI_ASSERT(image == TI_NULL_HANDLE); } // Attemp to allocate a 2D image with a invalid format { + TiRuntime runtime = ti_create_runtime(arch); + auto imageAllocateInfo = getImageAllocateInfo(); + imageAllocateInfo.format = TI_FORMAT_MAX_ENUM; + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); imageAllocateInfo.format = TI_FORMAT_MAX_ENUM; image = ti_allocate_image(runtime, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); @@ -313,19 +343,21 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { // runtime & imageAllocateInfo are both null { - image = ti_allocate_image(TI_NULL_HANDLE, TI_NULL_HANDLE); + + auto image = ti_allocate_image(TI_NULL_HANDLE, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - // runtime is null, imageAllocateInfo is valid { - image = ti_allocate_image(TI_NULL_HANDLE, &imageAllocateInfo); + TiImageAllocateInfo imageAllocateInfo = getImageAllocateInfo(); + TiImage image = ti_allocate_image(TI_NULL_HANDLE, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } // runtime is valid, imageAllocateInfo is null; { - image = ti_allocate_image(runtime, TI_NULL_HANDLE); + TiRuntime runtime = ti_create_runtime(arch); + TiImage image = ti_allocate_image(runtime, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } } @@ -452,6 +484,10 @@ TEST_F(CapiTest, TestBehaviorCopyMemoryDTD) { src_memory.memory = TI_NULL_HANDLE; ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + + ti_free_memory(runtime, memory); + ti_destroy_runtime(runtime); + } }; inner(TI_ARCH_VULKAN); From cbd5c909b2bbb187727ddcf68456d4f1ca03f7ae Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 10:44:52 +0000 Subject: [PATCH 11/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index f0ce15c0f95bc..c9ebe7884923d 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -116,7 +116,7 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; - + auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attempt to allocate memory with size of 1024 @@ -287,8 +287,7 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { inner(TI_ARCH_VULKAN); } -TiImageAllocateInfo getImageAllocateInfo() -{ +TiImageAllocateInfo getImageAllocateInfo() { TiImageExtent extent; extent.height = 512; extent.width = 512; @@ -304,7 +303,6 @@ TiImageAllocateInfo getImageAllocateInfo() } TEST_F(CapiTest, TestBehaviorAllocateImage) { - auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attemp to allocate a normal 2D image @@ -343,7 +341,6 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { // runtime & imageAllocateInfo are both null { - auto image = ti_allocate_image(TI_NULL_HANDLE, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } @@ -487,7 +484,6 @@ TEST_F(CapiTest, TestBehaviorCopyMemoryDTD) { ti_free_memory(runtime, memory); ti_destroy_runtime(runtime); - } }; inner(TI_ARCH_VULKAN); From fa30516f793328f65ec46bd2136bfc1cf97a9bda Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 18:58:41 +0800 Subject: [PATCH 12/42] up --- c_api/tests/c_api_behavior_test.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index c9ebe7884923d..59df9a20d55c6 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -116,7 +116,7 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; - + auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attempt to allocate memory with size of 1024 @@ -287,7 +287,8 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { inner(TI_ARCH_VULKAN); } -TiImageAllocateInfo getImageAllocateInfo() { +TiImageAllocateInfo getImageAllocateInfo() +{ TiImageExtent extent; extent.height = 512; extent.width = 512; @@ -303,6 +304,7 @@ TiImageAllocateInfo getImageAllocateInfo() { } TEST_F(CapiTest, TestBehaviorAllocateImage) { + auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attemp to allocate a normal 2D image @@ -341,14 +343,20 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { // runtime & imageAllocateInfo are both null { + TiRuntime runtime = ti_create_runtime(arch); auto image = ti_allocate_image(TI_NULL_HANDLE, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); } // runtime is null, imageAllocateInfo is valid { + TiRuntime runtime = ti_create_runtime(arch); TiImageAllocateInfo imageAllocateInfo = getImageAllocateInfo(); TiImage image = ti_allocate_image(TI_NULL_HANDLE, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); } // runtime is valid, imageAllocateInfo is null; @@ -356,6 +364,8 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { TiRuntime runtime = ti_create_runtime(arch); TiImage image = ti_allocate_image(runtime, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); } } }; @@ -484,6 +494,7 @@ TEST_F(CapiTest, TestBehaviorCopyMemoryDTD) { ti_free_memory(runtime, memory); ti_destroy_runtime(runtime); + } }; inner(TI_ARCH_VULKAN); From 4658a1f737aeca691d35edaed040bea1cfb1e567 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 11:01:20 +0000 Subject: [PATCH 13/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 59df9a20d55c6..0fab8a22851bf 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -116,7 +116,7 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; - + auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attempt to allocate memory with size of 1024 @@ -287,8 +287,7 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { inner(TI_ARCH_VULKAN); } -TiImageAllocateInfo getImageAllocateInfo() -{ +TiImageAllocateInfo getImageAllocateInfo() { TiImageExtent extent; extent.height = 512; extent.width = 512; @@ -304,7 +303,6 @@ TiImageAllocateInfo getImageAllocateInfo() } TEST_F(CapiTest, TestBehaviorAllocateImage) { - auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attemp to allocate a normal 2D image @@ -494,7 +492,6 @@ TEST_F(CapiTest, TestBehaviorCopyMemoryDTD) { ti_free_memory(runtime, memory); ti_destroy_runtime(runtime); - } }; inner(TI_ARCH_VULKAN); From ecfb2ae560c6a328dbb7326f5dad8f46d2efb032 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 19:27:39 +0800 Subject: [PATCH 14/42] up --- c_api/tests/c_api_behavior_test.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 0fab8a22851bf..1fe324a056799 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -307,7 +307,17 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { if (ti::is_arch_available(arch)) { // Attemp to allocate a normal 2D image { - auto imageAllocateInfo = getImageAllocateInfo(); + TiImageExtent extent; + extent.height = 512; + extent.width = 512; + extent.depth = 1; + extent.array_layer_count = 1; + TiImageAllocateInfo imageAllocateInfo; + imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_2D; + imageAllocateInfo.format = TI_FORMAT_RGBA8; + imageAllocateInfo.extent = extent; + imageAllocateInfo.usage = TI_IMAGE_USAGE_STORAGE_BIT; + imageAllocateInfo.mip_level_count = 1; TiRuntime runtime = ti_create_runtime(arch); TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); CHECK_TAICHI_SUCCESS(); @@ -363,6 +373,7 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { TiImage image = ti_allocate_image(runtime, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); ti_free_image(runtime, image); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); ti_destroy_runtime(runtime); } } From 3bdddf4dc00901018ccd7d94c530170dd4bbed23 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Mon, 12 Dec 2022 19:30:51 +0800 Subject: [PATCH 15/42] u --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 1fe324a056799..cb7a5f0088bd8 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -407,7 +407,7 @@ TEST_F(CapiTest, TestBehaviorFreeImage) { ti_free_image(TI_NULL_HANDLE, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - + // Runtime is null, Image is valid { ti_free_image(TI_NULL_HANDLE, image); From bf0945453805fdaf87ec598f71455c4b75985583 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 11:34:57 +0000 Subject: [PATCH 16/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index cb7a5f0088bd8..1fe324a056799 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -407,7 +407,7 @@ TEST_F(CapiTest, TestBehaviorFreeImage) { ti_free_image(TI_NULL_HANDLE, TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - + // Runtime is null, Image is valid { ti_free_image(TI_NULL_HANDLE, image); From 8e75f54dcd65ce82f825e59fc34fcd1f407119ad Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 11:55:27 +0800 Subject: [PATCH 17/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 728 +++++++++++++++------------- 1 file changed, 393 insertions(+), 335 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 1fe324a056799..b3ca23682b695 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -23,6 +23,8 @@ TEST_F(CapiTest, TestBehaviorCreateRuntime) { TiRuntime runtime = ti_create_runtime(arch); TI_ASSERT(runtime == TI_NULL_HANDLE); CHECK_TAICHI_ERROR_IS(TI_ERROR_NOT_SUPPORTED); + ti_destroy_runtime(runtime); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); }; // Attempt to create runtime for unknown arch. @@ -53,7 +55,6 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { } TiRuntime runtime = ti_create_runtime(arch); - { // Two nulls, considerred nop. ti_get_runtime_capabilities(runtime, nullptr, nullptr); @@ -109,6 +110,7 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TI_ASSERT(capabilities.at(i).level != 0); } } + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); @@ -118,49 +120,52 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - // Attempt to allocate memory with size of 1024 - TiRuntime runtime = ti_create_runtime(arch); - for (int i = 0; i < 4; ++i) { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - TI_ASSERT(memory != TI_NULL_HANDLE); - ti_free_memory(runtime, memory); - } + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } - // Attempt to run out of the memory - { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1000000000000000000; - ti_allocate_memory(runtime, &allocate_info); - error = ti_get_last_error(0, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); - } + // Attempt to allocate memory with size of 1024 + TiRuntime runtime = ti_create_runtime(arch); + for (int i = 0; i < 4; ++i) { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + TI_ASSERT(memory != TI_NULL_HANDLE); + ti_free_memory(runtime, memory); + } - // runtime and allocate_info are both null - { - ti_allocate_memory(TI_NULL_HANDLE, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // Attempt to run out of the memory + { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1000000000000000000; + ti_allocate_memory(runtime, &allocate_info); + error = ti_get_last_error(0, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); + } - // runtime is not null, allocate_info is null - { - ti_allocate_memory(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime and allocate_info are both null + { + ti_allocate_memory(TI_NULL_HANDLE, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } - // runtime is null, allocate is not null; - { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime is not null, allocate_info is null + { + ti_allocate_memory(runtime, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } - ti_destroy_runtime(runtime); + // runtime is null, allocate is not null; + { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); @@ -168,39 +173,45 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { TEST_F(CapiTest, TestBehaviorFreeMemory) { auto inner = [](TiArch arch) { - if (ti::is_arch_available(arch)) { - { - TiRuntime runtime = ti_create_runtime(arch); - TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, allocate_info); - ti_free_memory(runtime, memory); - CHECK_TAICHI_SUCCESS(); - } - // runtime & allocate_info are both null - { - ti_free_memory(TI_NULL_HANDLE, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } - // runtime is null and allocate_info is valid - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - ti_free_memory(TI_NULL_HANDLE, memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + { + TiRuntime runtime = ti_create_runtime(arch); + TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, allocate_info); + ti_free_memory(runtime, memory); + CHECK_TAICHI_SUCCESS(); + ti_destroy_runtime(runtime); + } - // runtime is not null and allocate_info is null - { - TiRuntime runtime = ti_create_runtime(arch); - ti_free_memory(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime & allocate_info are both null + { + ti_free_memory(TI_NULL_HANDLE, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + // runtime is null and allocate_info is valid + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_free_memory(TI_NULL_HANDLE, memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_destroy_runtime(runtime); + } + + // runtime is not null and allocate_info is null + { + TiRuntime runtime = ti_create_runtime(arch); + ti_free_memory(runtime, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } }; inner(TI_ARCH_VULKAN); @@ -212,37 +223,46 @@ TEST_F(CapiTest, TestBehaviorMapMemory) { allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - { - TiRuntime runtime = ti_create_runtime(arch); - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - TI_ASSERT(memory != TI_NULL_HANDLE); - CHECK_TAICHI_SUCCESS(); - ti_map_memory(runtime, memory); - CHECK_TAICHI_SUCCESS(); - ti_unmap_memory(runtime, memory); - } + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } + + { + TiRuntime runtime = ti_create_runtime(arch); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + TI_ASSERT(memory != TI_NULL_HANDLE); + CHECK_TAICHI_SUCCESS(); + ti_map_memory(runtime, memory); + CHECK_TAICHI_SUCCESS(); + ti_unmap_memory(runtime, memory); + ti_destroy_runtime(runtime); + } - // runtime & memory are both null - { - ti_map_memory(TI_NULL_HANDLE, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime & memory are both null + { + TiRuntime runtime = ti_create_runtime(arch); + ti_map_memory(TI_NULL_HANDLE, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_destroy_runtime(runtime); + } - // runtime is null, memory is valid - { - TiRuntime runtime = ti_create_runtime(arch); - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - ti_map_memory(TI_NULL_HANDLE, memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime is null, memory is valid + { + TiRuntime runtime = ti_create_runtime(arch); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_map_memory(TI_NULL_HANDLE, memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_unmap_memory(runtime, memory); + ti_destroy_runtime(runtime); + } - // runtime is valid, memory is null - { - TiRuntime runtime = ti_create_runtime(arch); - ti_map_memory(runtime, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime is valid, memory is null + { + TiRuntime runtime = ti_create_runtime(arch); + ti_map_memory(runtime, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_destroy_runtime(runtime); } }; inner(TI_ARCH_VULKAN); @@ -252,36 +272,43 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - for (int i = 0; i < 4; ++i) { - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - ti_map_memory(runtime, memory); - ti_unmap_memory(runtime, memory); - CHECK_TAICHI_SUCCESS(); - } + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is nor supported, so the test is skipped", arch); + return; + } - // runtime & memory are both null - { - ti_unmap_memory(TI_NULL_HANDLE, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + TiRuntime runtime = ti_create_runtime(arch); + for (int i = 0; i < 4; ++i) { + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_map_memory(runtime, memory); + ti_unmap_memory(runtime, memory); + CHECK_TAICHI_SUCCESS(); + } + ti_destroy_runtime(runtime); - // runtime is null, memory is valid - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - ti_unmap_memory(TI_NULL_HANDLE, memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime & memory are both null + { + ti_unmap_memory(TI_NULL_HANDLE, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } - // runtime is valid, memory is valid - { - TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - ti_unmap_memory(runtime, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime is null, memory is valid + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_unmap_memory(TI_NULL_HANDLE, memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_memory(runtime, memory); + ti_destroy_runtime(runtime); + } + + // runtime is valid, memory is valid + { + TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); + ti_unmap_memory(runtime, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_destroy_runtime(runtime); } }; inner(TI_ARCH_VULKAN); @@ -304,78 +331,83 @@ TiImageAllocateInfo getImageAllocateInfo() { TEST_F(CapiTest, TestBehaviorAllocateImage) { auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - // Attemp to allocate a normal 2D image - { - TiImageExtent extent; - extent.height = 512; - extent.width = 512; - extent.depth = 1; - extent.array_layer_count = 1; - TiImageAllocateInfo imageAllocateInfo; - imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_2D; - imageAllocateInfo.format = TI_FORMAT_RGBA8; - imageAllocateInfo.extent = extent; - imageAllocateInfo.usage = TI_IMAGE_USAGE_STORAGE_BIT; - imageAllocateInfo.mip_level_count = 1; - TiRuntime runtime = ti_create_runtime(arch); - TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); - CHECK_TAICHI_SUCCESS(); - TI_ASSERT(image != TI_NULL_HANDLE); - ti_free_image(runtime, image); - } + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } - // Attemp to allocate a 2D image with invalid demension - { - TiRuntime runtime = ti_create_runtime(arch); - auto imageAllocateInfo = getImageAllocateInfo(); - imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_MAX_ENUM; - TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); - imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_MAX_ENUM; - image = ti_allocate_image(runtime, &imageAllocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); - TI_ASSERT(image == TI_NULL_HANDLE); - } + // Attemp to allocate a normal 2D image + { + TiImageExtent extent; + extent.height = 512; + extent.width = 512; + extent.depth = 1; + extent.array_layer_count = 1; + TiImageAllocateInfo imageAllocateInfo; + imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_2D; + imageAllocateInfo.format = TI_FORMAT_RGBA8; + imageAllocateInfo.extent = extent; + imageAllocateInfo.usage = TI_IMAGE_USAGE_STORAGE_BIT; + imageAllocateInfo.mip_level_count = 1; + TiRuntime runtime = ti_create_runtime(arch); + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); + CHECK_TAICHI_SUCCESS(); + TI_ASSERT(image != TI_NULL_HANDLE); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); + } - // Attemp to allocate a 2D image with a invalid format - { - TiRuntime runtime = ti_create_runtime(arch); - auto imageAllocateInfo = getImageAllocateInfo(); - imageAllocateInfo.format = TI_FORMAT_MAX_ENUM; - TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); - imageAllocateInfo.format = TI_FORMAT_MAX_ENUM; - image = ti_allocate_image(runtime, &imageAllocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); - imageAllocateInfo.format = TI_FORMAT_BGRA8; - } + // Attemp to allocate a 2D image with invalid demension + { + TiRuntime runtime = ti_create_runtime(arch); + auto imageAllocateInfo = getImageAllocateInfo(); + imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_MAX_ENUM; + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); + TI_ASSERT(image == TI_NULL_HANDLE); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); + } - // runtime & imageAllocateInfo are both null - { - TiRuntime runtime = ti_create_runtime(arch); - auto image = ti_allocate_image(TI_NULL_HANDLE, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - ti_free_image(runtime, image); - ti_destroy_runtime(runtime); - } - // runtime is null, imageAllocateInfo is valid - { - TiRuntime runtime = ti_create_runtime(arch); - TiImageAllocateInfo imageAllocateInfo = getImageAllocateInfo(); - TiImage image = ti_allocate_image(TI_NULL_HANDLE, &imageAllocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - ti_free_image(runtime, image); - ti_destroy_runtime(runtime); - } + // Attemp to allocate a 2D image with a invalid format + { + TiRuntime runtime = ti_create_runtime(arch); + auto imageAllocateInfo = getImageAllocateInfo(); + imageAllocateInfo.format = TI_FORMAT_MAX_ENUM; + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); + imageAllocateInfo.format = TI_FORMAT_BGRA8; + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); + } - // runtime is valid, imageAllocateInfo is null; - { - TiRuntime runtime = ti_create_runtime(arch); - TiImage image = ti_allocate_image(runtime, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - ti_free_image(runtime, image); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - ti_destroy_runtime(runtime); - } + // runtime & imageAllocateInfo are both null + { + TiRuntime runtime = ti_create_runtime(arch); + auto image = ti_allocate_image(TI_NULL_HANDLE, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); + } + + // runtime is null, imageAllocateInfo is valid + { + TiRuntime runtime = ti_create_runtime(arch); + TiImageAllocateInfo imageAllocateInfo = getImageAllocateInfo(); + TiImage image = ti_allocate_image(TI_NULL_HANDLE, &imageAllocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_image(runtime, image); + ti_destroy_runtime(runtime); + } + + // runtime is valid, imageAllocateInfo is null; + { + TiRuntime runtime = ti_create_runtime(arch); + TiImage image = ti_allocate_image(runtime, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_free_image(runtime, image); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_destroy_runtime(runtime); } }; inner(TI_ARCH_VULKAN); @@ -396,65 +428,77 @@ TEST_F(CapiTest, TestBehaviorFreeImage) { auto inner = [&](TiArch arch) { // Attemp to free a normal 2D image - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); - ti_free_image(runtime, image); - CHECK_TAICHI_SUCCESS(); + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } - // Runtime & image are both invalid - { - ti_free_image(TI_NULL_HANDLE, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + TiRuntime runtime = ti_create_runtime(arch); + TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); + ti_free_image(runtime, image); + CHECK_TAICHI_SUCCESS(); - // Runtime is null, Image is valid - { - ti_free_image(TI_NULL_HANDLE, image); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // Runtime & image are both invalid + { + ti_free_image(TI_NULL_HANDLE, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } - // Runtime is valid, image is null - { - ti_free_image(runtime, TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // Runtime is null, Image is valid + { + ti_free_image(TI_NULL_HANDLE, image); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + // Runtime is valid, image is null + { + ti_free_image(runtime, TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } TEST_F(CapiTest, TestBehaviorCreateEvent) { auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiEvent event = ti_create_event(runtime); - CHECK_TAICHI_SUCCESS(); + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } + TiRuntime runtime = ti_create_runtime(arch); + TiEvent event = ti_create_event(runtime); + CHECK_TAICHI_SUCCESS(); - // Runtime is null - { - event = ti_create_event(TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // Runtime is null + { + event = ti_create_event(TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } TEST_F(CapiTest, TestBehaviorDestroyEvent) { auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiEvent event = ti_create_event(runtime); - ti_destroy_event(event); - CHECK_TAICHI_SUCCESS(); + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } - // Attemp to destroy a null event - { - ti_destroy_event(TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + TiRuntime runtime = ti_create_runtime(arch); + TiEvent event = ti_create_event(runtime); + ti_destroy_event(event); + CHECK_TAICHI_SUCCESS(); + + // Attemp to destroy a null event + { + ti_destroy_event(TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } @@ -465,45 +509,47 @@ TEST_F(CapiTest, TestBehaviorCopyMemoryDTD) { MallocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; MallocateInfo.export_sharing = TI_TRUE; auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiMemory memory = ti_allocate_memory(runtime, &MallocateInfo); - TiMemorySlice src_memory; - src_memory.memory = memory; - src_memory.offset = 128; - src_memory.size = 64; - TiMemorySlice dst_memory; - dst_memory.memory = memory; - dst_memory.offset = 1024; - dst_memory.size = 64; - ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); - CHECK_TAICHI_SUCCESS(); + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } + TiRuntime runtime = ti_create_runtime(arch); + TiMemory memory = ti_allocate_memory(runtime, &MallocateInfo); + TiMemorySlice src_memory; + src_memory.memory = memory; + src_memory.offset = 128; + src_memory.size = 64; + TiMemorySlice dst_memory; + dst_memory.memory = memory; + dst_memory.offset = 1024; + dst_memory.size = 64; + ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); + CHECK_TAICHI_SUCCESS(); - // Attempt copy memory from the big one to the small one - src_memory.size = 256; - src_memory.offset = 512; - dst_memory.offset = 1152; - ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_INVALID_ARGUMENT); - dst_memory.size = 64; + // Attempt copy memory from the big one to the small one + src_memory.size = 256; + src_memory.offset = 512; + dst_memory.offset = 1152; + ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_INVALID_ARGUMENT); + dst_memory.size = 64; - // runtime is null; - ti_copy_memory_device_to_device(TI_NULL_HANDLE, &dst_memory, &src_memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + // runtime is null; + ti_copy_memory_device_to_device(TI_NULL_HANDLE, &dst_memory, &src_memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - // dst memory is null; - dst_memory.memory = TI_NULL_HANDLE; - ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + // dst memory is null; + dst_memory.memory = TI_NULL_HANDLE; + ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - // src memory is null; - src_memory.memory = TI_NULL_HANDLE; - ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + // src memory is null; + src_memory.memory = TI_NULL_HANDLE; + ti_copy_memory_device_to_device(runtime, &dst_memory, &src_memory); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - ti_free_memory(runtime, memory); - ti_destroy_runtime(runtime); - } + ti_free_memory(runtime, memory); + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } @@ -512,52 +558,54 @@ void test_behavior_load_aot_module_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); const std::string module_path = folder_dir + std::string("/module.tcm"); - if (ti::is_arch_available(arch)) { - std::cout << arch << std::endl; - TiRuntime runtime = ti_create_runtime(arch); + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; + } + TiRuntime runtime = ti_create_runtime(arch); - // AOT module from tcm file, normal usage. - { - TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); - CHECK_TAICHI_SUCCESS(); - TI_ASSERT(module != TI_NULL_HANDLE); - } + // AOT module from tcm file, normal usage. + { + TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); + CHECK_TAICHI_SUCCESS(); + TI_ASSERT(module != TI_NULL_HANDLE); + } - // AOT module from filesystem directory, normal usage. - { - TiAotModule module = ti_load_aot_module(runtime, folder_dir); - CHECK_TAICHI_SUCCESS(); - TI_ASSERT(module != TI_NULL_HANDLE); - } + // AOT module from filesystem directory, normal usage. + { + TiAotModule module = ti_load_aot_module(runtime, folder_dir); + CHECK_TAICHI_SUCCESS(); + TI_ASSERT(module != TI_NULL_HANDLE); + } - // Attempt to load aot module from tcm file, while runtime is null. - { - TiAotModule module = - ti_load_aot_module(TI_NULL_HANDLE, module_path.c_str()); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(module == TI_NULL_HANDLE); - } + // Attempt to load aot module from tcm file, while runtime is null. + { + TiAotModule module = + ti_load_aot_module(TI_NULL_HANDLE, module_path.c_str()); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + TI_ASSERT(module == TI_NULL_HANDLE); + } - // Attempt to load aot module from tcm file, while runtime is null. - { - TiAotModule module = ti_load_aot_module(TI_NULL_HANDLE, folder_dir); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(module == TI_NULL_HANDLE); - } + // Attempt to load aot module from tcm file, while runtime is null. + { + TiAotModule module = ti_load_aot_module(TI_NULL_HANDLE, folder_dir); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + TI_ASSERT(module == TI_NULL_HANDLE); + } - // Attempt to load aot module without path. - { - TiAotModule module = ti_load_aot_module(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(module == TI_NULL_HANDLE); - } - // Attempt to load aot module with a invalid path. - { - TiAotModule module = ti_load_aot_module(runtime, "ssssss///"); - CHECK_TAICHI_ERROR_IS(TI_ERROR_CORRUPTED_DATA); - TI_ASSERT(module == TI_NULL_HANDLE); - } + // Attempt to load aot module without path. + { + TiAotModule module = ti_load_aot_module(runtime, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + TI_ASSERT(module == TI_NULL_HANDLE); } + // Attempt to load aot module with a invalid path. + { + TiAotModule module = ti_load_aot_module(runtime, "ssssss///"); + CHECK_TAICHI_ERROR_IS(TI_ERROR_CORRUPTED_DATA); + TI_ASSERT(module == TI_NULL_HANDLE); + } + ti_destroy_runtime(runtime); } TEST_F(CapiTest, TestBehaviorLoadAOTModuleVulkan) { @@ -567,18 +615,23 @@ TEST_F(CapiTest, TestBehaviorLoadAOTModuleVulkan) { void test_behavior_destroy_aot_module_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); const std::string module_path = folder_dir + std::string("/module.tcm"); - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); - TI_ASSERT(module != TI_NULL_HANDLE); - ti_destroy_aot_module(module); - CHECK_TAICHI_SUCCESS(); - - // Attempt to destroy a null handle. - ti_destroy_aot_module(TI_NULL_HANDLE); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so the test is skipped", arch); + return; } + + TiRuntime runtime = ti_create_runtime(arch); + TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); + TI_ASSERT(module != TI_NULL_HANDLE); + ti_destroy_aot_module(module); + CHECK_TAICHI_SUCCESS(); + ti_destroy_runtime(runtime); + + // Attempt to destroy a null handle. + ti_destroy_aot_module(TI_NULL_HANDLE); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + TEST_F(CapiTest, TestBehaviorDestroyAotModuleVulkan) { test_behavior_destroy_aot_module_impl(TI_ARCH_VULKAN); } @@ -586,29 +639,34 @@ TEST_F(CapiTest, TestBehaviorDestroyAotModuleVulkan) { void test_behavir_get_cgraph_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); const std::string module_path = folder_dir + std::string("/module.tcm"); - if (ti::is_arch_available(arch)) { - TiRuntime runtime = ti_create_runtime(arch); - TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); - TiComputeGraph Cgraph = - ti_get_aot_module_compute_graph(module, "run_graph"); - CHECK_TAICHI_SUCCESS(); - TI_ASSERT(Cgraph != TI_NULL_HANDLE); + if (!ti::is_arch_available(arch)) { + TI_ASSERT("arch {} is not supported, so the test is skipped", arch); + return; + } + + TiRuntime runtime = ti_create_runtime(arch); + TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); + TiComputeGraph Cgraph = + ti_get_aot_module_compute_graph(module, "run_graph"); + CHECK_TAICHI_SUCCESS(); + TI_ASSERT(Cgraph != TI_NULL_HANDLE); + + // Attemp to get compute graph with null module. + Cgraph = ti_get_aot_module_compute_graph(TI_NULL_HANDLE, "run_graph"); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + TI_ASSERT(Cgraph == TI_NULL_HANDLE); - // Attemp to get compute graph with null module. - Cgraph = ti_get_aot_module_compute_graph(TI_NULL_HANDLE, "run_graph"); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(Cgraph == TI_NULL_HANDLE); + // Attemp to get compute graph without graph name. + Cgraph = ti_get_aot_module_compute_graph(module, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + TI_ASSERT(Cgraph == TI_NULL_HANDLE); - // Attemp to get compute graph without graph name. - Cgraph = ti_get_aot_module_compute_graph(module, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(Cgraph == TI_NULL_HANDLE); + // Attemp to get compute graph with invalid name. + Cgraph = ti_get_aot_module_compute_graph(module, "#$#%*("); + CHECK_TAICHI_ERROR_IS(TI_ERROR_NAME_NOT_FOUND); + TI_ASSERT(Cgraph == TI_NULL_HANDLE); - // Attemp to get compute graph with invalid name. - Cgraph = ti_get_aot_module_compute_graph(module, "#$#%*("); - CHECK_TAICHI_ERROR_IS(TI_ERROR_NAME_NOT_FOUND); - TI_ASSERT(Cgraph == TI_NULL_HANDLE); - } + ti_destroy_runtime(runtime); } TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { From ab0ffda3a4bf7643033c9aaeb61eef44d9e1e7e7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 03:56:43 +0000 Subject: [PATCH 18/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index b3ca23682b695..2185abaa85391 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -227,7 +227,7 @@ TEST_F(CapiTest, TestBehaviorMapMemory) { TI_WARN("arch {} is not supported, so the test is skipped", arch); return; } - + { TiRuntime runtime = ti_create_runtime(arch); TiMemory memory = ti_allocate_memory(runtime, &allocate_info); @@ -334,7 +334,7 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { if (!ti::is_arch_available(arch)) { TI_WARN("arch {} is not supported, so the test is skipped", arch); return; - } + } // Attemp to allocate a normal 2D image { @@ -643,11 +643,10 @@ void test_behavir_get_cgraph_impl(TiArch arch) { TI_ASSERT("arch {} is not supported, so the test is skipped", arch); return; } - + TiRuntime runtime = ti_create_runtime(arch); TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); - TiComputeGraph Cgraph = - ti_get_aot_module_compute_graph(module, "run_graph"); + TiComputeGraph Cgraph = ti_get_aot_module_compute_graph(module, "run_graph"); CHECK_TAICHI_SUCCESS(); TI_ASSERT(Cgraph != TI_NULL_HANDLE); From 0b9f6aa0d99df443e1c2f9d4877ccd98240c1897 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 12:12:57 +0800 Subject: [PATCH 19/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 34 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 2185abaa85391..481657fd4673d 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -126,23 +126,27 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { } // Attempt to allocate memory with size of 1024 - TiRuntime runtime = ti_create_runtime(arch); - for (int i = 0; i < 4; ++i) { + { + TiRuntime runtime = ti_create_runtime(arch); TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(runtime, &allocate_info); TI_ASSERT(memory != TI_NULL_HANDLE); ti_free_memory(runtime, memory); + ti_destroy_runtime(runtime); } // Attempt to run out of the memory { + TiRuntime runtime = ti_create_runtime(arch); TiMemoryAllocateInfo allocate_info; allocate_info.size = 1000000000000000000; - ti_allocate_memory(runtime, &allocate_info); + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); error = ti_get_last_error(0, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); + ti_free_memory(runtime, memory); + ti_destroy_runtime(runtime); } // runtime and allocate_info are both null @@ -153,19 +157,20 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { // runtime is not null, allocate_info is null { + TiRuntime runtime = ti_create_runtime(arch); ti_allocate_memory(runtime, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + ti_destroy_runtime(runtime); } // runtime is null, allocate is not null; { TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; - ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); + TiMemory memory = ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + TI_ASSERT(memory == TI_NULL_HANDLE); } - - ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); @@ -277,15 +282,15 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { return; } - TiRuntime runtime = ti_create_runtime(arch); - for (int i = 0; i < 4; ++i) { - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; + { + TiRuntime runtime = ti_create_runtime(arch); + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(runtime, &allocate_info); ti_map_memory(runtime, memory); ti_unmap_memory(runtime, memory); CHECK_TAICHI_SUCCESS(); + ti_destroy_runtime(runtime); } - ti_destroy_runtime(runtime); // runtime & memory are both null { @@ -353,6 +358,13 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); CHECK_TAICHI_SUCCESS(); TI_ASSERT(image != TI_NULL_HANDLE); + + imageAllocateInfo.usage = TI_IMAGE_USAGE_SAMPLED_BIT; + image = ti_allocate_image(runtime, &imageAllocateInfo); + CHECK_TAICHI_SUCCESS(); + TI_ASSERT(image != TI_NULL_HANDLE); + imageAllocateInfo.usage = TI_IMAGE_USAGE_STORAGE_BIT; + ti_free_image(runtime, image); ti_destroy_runtime(runtime); } From 26fd593f9b740956958d3640a1e7b206fe43cbb4 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 12:22:54 +0800 Subject: [PATCH 20/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 481657fd4673d..9199a951d2430 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -652,7 +652,7 @@ void test_behavir_get_cgraph_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); const std::string module_path = folder_dir + std::string("/module.tcm"); if (!ti::is_arch_available(arch)) { - TI_ASSERT("arch {} is not supported, so the test is skipped", arch); + TI_WARN("arch {} is not supported, so the test is skipped", arch); return; } From 2f45d886c0556091c7e254f09669dd0c28e4240a Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 12:38:10 +0800 Subject: [PATCH 21/42] reModity --- c_api/tests/c_api_behavior_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 9199a951d2430..5507e374400b5 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -142,8 +142,8 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiRuntime runtime = ti_create_runtime(arch); TiMemoryAllocateInfo allocate_info; allocate_info.size = 1000000000000000000; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - error = ti_get_last_error(0, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); ti_free_memory(runtime, memory); ti_destroy_runtime(runtime); @@ -167,6 +167,7 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { { TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); TI_ASSERT(memory == TI_NULL_HANDLE); From 3d3a8b07c55ae035579fbe21a32df470bec4757c Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 12:42:11 +0800 Subject: [PATCH 22/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 5507e374400b5..b76c280fa6a94 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -117,8 +117,6 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { } TEST_F(CapiTest, TestBehaviorAllocateMemory) { - TiError error = TI_ERROR_SUCCESS; - auto inner = [&](TiArch arch) { if (!ti::is_arch_available(arch)) { TI_WARN("arch {} is not supported, so the test is skipped", arch); From 33fa41c6aef9ffd37669ec14dc220451d1dd603c Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 13:13:08 +0800 Subject: [PATCH 23/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index b76c280fa6a94..bde3d8a8a1bd7 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -117,6 +117,7 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { } TEST_F(CapiTest, TestBehaviorAllocateMemory) { + TiError error = TI_ERROR_SUCCESS; auto inner = [&](TiArch arch) { if (!ti::is_arch_available(arch)) { TI_WARN("arch {} is not supported, so the test is skipped", arch); @@ -124,27 +125,23 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { } // Attempt to allocate memory with size of 1024 - { - TiRuntime runtime = ti_create_runtime(arch); + TiRuntime runtime = ti_create_runtime(arch); + for (int i = 0; i < 4; ++i) { TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; TiMemory memory = ti_allocate_memory(runtime, &allocate_info); TI_ASSERT(memory != TI_NULL_HANDLE); ti_free_memory(runtime, memory); - ti_destroy_runtime(runtime); } // Attempt to run out of the memory { - TiRuntime runtime = ti_create_runtime(arch); TiMemoryAllocateInfo allocate_info; allocate_info.size = 1000000000000000000; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + ti_allocate_memory(runtime, &allocate_info); + error = ti_get_last_error(0, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); - ti_free_memory(runtime, memory); - ti_destroy_runtime(runtime); } // runtime and allocate_info are both null @@ -155,23 +152,19 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { // runtime is not null, allocate_info is null { - TiRuntime runtime = ti_create_runtime(arch); ti_allocate_memory(runtime, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - ti_destroy_runtime(runtime); } - + // runtime is null, allocate is not null; { TiMemoryAllocateInfo allocate_info; allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); + ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(memory == TI_NULL_HANDLE); } + ti_destroy_runtime(runtime); }; - inner(TI_ARCH_VULKAN); } From 2e8d3696511f5f02a222d0f02295c8b682bbf0f6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 05:14:22 +0000 Subject: [PATCH 24/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index bde3d8a8a1bd7..733762fddc0b0 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -155,7 +155,7 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { ti_allocate_memory(runtime, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - + // runtime is null, allocate is not null; { TiMemoryAllocateInfo allocate_info; From 1a864716770352f50b9da62e1db4662c6b7cfd6e Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 14:31:52 +0800 Subject: [PATCH 25/42] remodify --- c_api/tests/c_api_behavior_test.cpp | 79 ++++++++++++++--------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 733762fddc0b0..f1f5f399191fa 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -119,51 +119,48 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TEST_F(CapiTest, TestBehaviorAllocateMemory) { TiError error = TI_ERROR_SUCCESS; auto inner = [&](TiArch arch) { - if (!ti::is_arch_available(arch)) { - TI_WARN("arch {} is not supported, so the test is skipped", arch); - return; - } - - // Attempt to allocate memory with size of 1024 - TiRuntime runtime = ti_create_runtime(arch); - for (int i = 0; i < 4; ++i) { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - TI_ASSERT(memory != TI_NULL_HANDLE); - ti_free_memory(runtime, memory); - } - - // Attempt to run out of the memory - { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1000000000000000000; - ti_allocate_memory(runtime, &allocate_info); - error = ti_get_last_error(0, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); - } + if (ti::is_arch_available(arch)) { + // Attempt to allocate memory with size of 1024 + TiRuntime runtime = ti_create_runtime(arch); + for (int i = 0; i < 4; ++i) { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + TI_ASSERT(memory != TI_NULL_HANDLE); + ti_free_memory(runtime, memory); + } - // runtime and allocate_info are both null - { - ti_allocate_memory(TI_NULL_HANDLE, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // Attempt to run out of the memory + { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1000000000000000000; + ti_allocate_memory(runtime, &allocate_info); + error = ti_get_last_error(0, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); + } - // runtime is not null, allocate_info is null - { - ti_allocate_memory(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime and allocate_info are both null + { + ti_allocate_memory(TI_NULL_HANDLE, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } - // runtime is null, allocate is not null; - { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + // runtime is not null, allocate_info is null + { + ti_allocate_memory(runtime, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + + // runtime is null, allocate is not null; + { + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + ti_destroy_runtime(runtime); } - ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } From b4fd596636a6daeff856afc6c341bb124390d9ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 06:33:06 +0000 Subject: [PATCH 26/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index f1f5f399191fa..432b7bef9ac12 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -151,7 +151,7 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { ti_allocate_memory(runtime, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } - + // runtime is null, allocate is not null; { TiMemoryAllocateInfo allocate_info; From a151b98e6b532c4e71c5a7b3b8b61adc10ee91c5 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 15:10:12 +0800 Subject: [PATCH 27/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 432b7bef9ac12..fbea0934751a2 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -112,7 +112,6 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { } ti_destroy_runtime(runtime); }; - inner(TI_ARCH_VULKAN); } @@ -131,15 +130,6 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { ti_free_memory(runtime, memory); } - // Attempt to run out of the memory - { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1000000000000000000; - ti_allocate_memory(runtime, &allocate_info); - error = ti_get_last_error(0, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); - } - // runtime and allocate_info are both null { ti_allocate_memory(TI_NULL_HANDLE, nullptr); From 2d3fe148f63f7fe5a49a913573764b022396ef4d Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 13 Dec 2022 16:25:40 +0800 Subject: [PATCH 28/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 1 - .../cpp/aot/python_scripts/graph_aot_test.py | 1 + .../python_scripts/graph_aot_test_vulkan.py | 52 ------------------- tests/test_config.json | 2 +- 4 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index fbea0934751a2..0f1c9a3be0f92 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -116,7 +116,6 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { } TEST_F(CapiTest, TestBehaviorAllocateMemory) { - TiError error = TI_ERROR_SUCCESS; auto inner = [&](TiArch arch) { if (ti::is_arch_available(arch)) { // Attempt to allocate memory with size of 1024 diff --git a/tests/cpp/aot/python_scripts/graph_aot_test.py b/tests/cpp/aot/python_scripts/graph_aot_test.py index 0394ddb2ac744..e085b8102eb5c 100644 --- a/tests/cpp/aot/python_scripts/graph_aot_test.py +++ b/tests/cpp/aot/python_scripts/graph_aot_test.py @@ -51,6 +51,7 @@ def run2(base: int, arr: ti.types.ndarray(ndim=1, dtype=ti.i32)): mod = ti.aot.Module() mod.add_graph('run_graph', run_graph) mod.save(tmpdir, '') + mod.archive(tmpdir + '/module.tcm') if __name__ == "__main__": diff --git a/tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py b/tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py deleted file mode 100644 index 19b79b0a28d6a..0000000000000 --- a/tests/cpp/aot/python_scripts/graph_aot_test_vulkan.py +++ /dev/null @@ -1,52 +0,0 @@ -import argparse -import os - -import taichi as ti - - -def compile_graph_aot(arch): - ti.init(arch=arch) - - if ti.lang.impl.current_cfg().arch != arch: - return - - arr = ti.graph.Arg(ti.graph.ArgKind.NDARRAY, - 'arr', - ti.i32, - field_dim=1, - element_shape=(1, )) - - base0 = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 'base0', ti.i32) - - base1 = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 'base2', ti.i32) - - base2 = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 'base1', ti.i32) - - g_builder = ti.graph.GraphBuilder() - - run_graph = g_builder.compile() - - assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() - tmpdir = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) - - mod = ti.aot.Module() - mod.add_graph('run_graph', run_graph) - mod.save(tmpdir) - mod.archive(tmpdir + '/module.tcm') - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("--arch", type=str) - args = parser.parse_args() - - if args.arch == "cpu": - compile_graph_aot(arch=ti.cpu) - elif args.arch == "cuda": - compile_graph_aot(arch=ti.cuda) - elif args.arch == "vulkan": - compile_graph_aot(arch=ti.vulkan) - elif args.arch == "opengl": - compile_graph_aot(arch=ti.opengl) - else: - assert False diff --git a/tests/test_config.json b/tests/test_config.json index d507220d008e9..e00872d4914ed 100644 --- a/tests/test_config.json +++ b/tests/test_config.json @@ -212,7 +212,7 @@ "--arch=vulkan" ], "CapiTest.TestBehaviorGetCgraphVulkan": [ - ["cpp", "aot", "python_scripts", "graph_aot_test_vulkan.py"], + ["cpp", "aot", "python_scripts", "graph_aot_test.py"], "--arch=vulkan" ] } From d7636da6c80735db644dc2a3c74542210acd2908 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Wed, 14 Dec 2022 14:23:50 +0800 Subject: [PATCH 29/42] remodify --- c_api/tests/c_api_behavior_test.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 0f1c9a3be0f92..b3c516eb98316 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -297,7 +297,7 @@ TEST_F(CapiTest, TestBehaviorUnmapMemory) { inner(TI_ARCH_VULKAN); } -TiImageAllocateInfo getImageAllocateInfo() { +TiImageAllocateInfo get_image_allocate_info() { TiImageExtent extent; extent.height = 512; extent.width = 512; @@ -350,7 +350,7 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { // Attemp to allocate a 2D image with invalid demension { TiRuntime runtime = ti_create_runtime(arch); - auto imageAllocateInfo = getImageAllocateInfo(); + auto imageAllocateInfo = get_image_allocate_info(); imageAllocateInfo.dimension = TI_IMAGE_DIMENSION_MAX_ENUM; TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); @@ -362,7 +362,7 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { // Attemp to allocate a 2D image with a invalid format { TiRuntime runtime = ti_create_runtime(arch); - auto imageAllocateInfo = getImageAllocateInfo(); + auto imageAllocateInfo = get_image_allocate_info(); imageAllocateInfo.format = TI_FORMAT_MAX_ENUM; TiImage image = ti_allocate_image(runtime, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_OUT_OF_RANGE); @@ -383,7 +383,7 @@ TEST_F(CapiTest, TestBehaviorAllocateImage) { // runtime is null, imageAllocateInfo is valid { TiRuntime runtime = ti_create_runtime(arch); - TiImageAllocateInfo imageAllocateInfo = getImageAllocateInfo(); + TiImageAllocateInfo imageAllocateInfo = get_image_allocate_info(); TiImage image = ti_allocate_image(TI_NULL_HANDLE, &imageAllocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); ti_free_image(runtime, image); @@ -626,7 +626,7 @@ TEST_F(CapiTest, TestBehaviorDestroyAotModuleVulkan) { test_behavior_destroy_aot_module_impl(TI_ARCH_VULKAN); } -void test_behavir_get_cgraph_impl(TiArch arch) { +void test_behavior_get_cgraph_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); const std::string module_path = folder_dir + std::string("/module.tcm"); if (!ti::is_arch_available(arch)) { @@ -636,28 +636,28 @@ void test_behavir_get_cgraph_impl(TiArch arch) { TiRuntime runtime = ti_create_runtime(arch); TiAotModule module = ti_load_aot_module(runtime, module_path.c_str()); - TiComputeGraph Cgraph = ti_get_aot_module_compute_graph(module, "run_graph"); + TiComputeGraph cgraph = ti_get_aot_module_compute_graph(module, "run_graph"); CHECK_TAICHI_SUCCESS(); - TI_ASSERT(Cgraph != TI_NULL_HANDLE); + TI_ASSERT(cgraph != TI_NULL_HANDLE); // Attemp to get compute graph with null module. - Cgraph = ti_get_aot_module_compute_graph(TI_NULL_HANDLE, "run_graph"); + cgraph = ti_get_aot_module_compute_graph(TI_NULL_HANDLE, "run_graph"); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(Cgraph == TI_NULL_HANDLE); + TI_ASSERT(cgraph == TI_NULL_HANDLE); // Attemp to get compute graph without graph name. - Cgraph = ti_get_aot_module_compute_graph(module, nullptr); + cgraph = ti_get_aot_module_compute_graph(module, nullptr); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - TI_ASSERT(Cgraph == TI_NULL_HANDLE); + TI_ASSERT(cgraph == TI_NULL_HANDLE); // Attemp to get compute graph with invalid name. - Cgraph = ti_get_aot_module_compute_graph(module, "#$#%*("); + cgraph = ti_get_aot_module_compute_graph(module, "#$#%*("); CHECK_TAICHI_ERROR_IS(TI_ERROR_NAME_NOT_FOUND); - TI_ASSERT(Cgraph == TI_NULL_HANDLE); + TI_ASSERT(cgraph == TI_NULL_HANDLE); ti_destroy_runtime(runtime); } TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { - test_behavir_get_cgraph_impl(TI_ARCH_VULKAN); + test_behavior_get_cgraph_impl(TI_ARCH_VULKAN); } From 651d62cb2ca8bef35745a94250214b3437df8e1f Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Wed, 14 Dec 2022 15:19:25 +0800 Subject: [PATCH 30/42] reModify --- c_api/tests/c_api_behavior_test.cpp | 2 +- taichi/rhi/opengl/opengl_device.cpp | 1 + tests/cpp/aot/python_scripts/graph_aot_test.py | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index b3c516eb98316..b77b60a470ccc 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -628,7 +628,7 @@ TEST_F(CapiTest, TestBehaviorDestroyAotModuleVulkan) { void test_behavior_get_cgraph_impl(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); - const std::string module_path = folder_dir + std::string("/module.tcm"); + const std::string module_path = folder_dir; if (!ti::is_arch_available(arch)) { TI_WARN("arch {} is not supported, so the test is skipped", arch); return; diff --git a/taichi/rhi/opengl/opengl_device.cpp b/taichi/rhi/opengl/opengl_device.cpp index 0a02bd04351de..78b06d835d18f 100644 --- a/taichi/rhi/opengl/opengl_device.cpp +++ b/taichi/rhi/opengl/opengl_device.cpp @@ -536,6 +536,7 @@ DeviceAllocation GLDevice::allocate_memory(const AllocParams ¶ms) { check_opengl_error("glGenBuffers"); glBindBuffer(target_hint, buffer); check_opengl_error("glBindBuffer"); + glBufferData(target_hint, params.size, nullptr, params.host_read ? GL_STATIC_COPY : GL_DYNAMIC_READ); GLuint alloc_res = glGetError(); diff --git a/tests/cpp/aot/python_scripts/graph_aot_test.py b/tests/cpp/aot/python_scripts/graph_aot_test.py index e085b8102eb5c..0394ddb2ac744 100644 --- a/tests/cpp/aot/python_scripts/graph_aot_test.py +++ b/tests/cpp/aot/python_scripts/graph_aot_test.py @@ -51,7 +51,6 @@ def run2(base: int, arr: ti.types.ndarray(ndim=1, dtype=ti.i32)): mod = ti.aot.Module() mod.add_graph('run_graph', run_graph) mod.save(tmpdir, '') - mod.archive(tmpdir + '/module.tcm') if __name__ == "__main__": From 769269da25ec348221f41545bc37b2d86ae2840f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 07:20:48 +0000 Subject: [PATCH 31/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/rhi/opengl/opengl_device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/rhi/opengl/opengl_device.cpp b/taichi/rhi/opengl/opengl_device.cpp index 78b06d835d18f..683184858f0c2 100644 --- a/taichi/rhi/opengl/opengl_device.cpp +++ b/taichi/rhi/opengl/opengl_device.cpp @@ -536,7 +536,7 @@ DeviceAllocation GLDevice::allocate_memory(const AllocParams ¶ms) { check_opengl_error("glGenBuffers"); glBindBuffer(target_hint, buffer); check_opengl_error("glBindBuffer"); - + glBufferData(target_hint, params.size, nullptr, params.host_read ? GL_STATIC_COPY : GL_DYNAMIC_READ); GLuint alloc_res = glGetError(); From bf54e92e3273aca645837228964877d2a7146d96 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Thu, 15 Dec 2022 10:49:28 +0800 Subject: [PATCH 32/42] final_test --- c_api/src/taichi_core_impl.cpp | 2 + c_api/tests/c_api_behavior_test.cpp | 86 ++++++++++++++++------------- taichi/rhi/vulkan/vulkan_api.cpp | 4 +- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index cebd882ff4c38..6589ebef706e3 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -81,6 +81,8 @@ const char *describe_error(TiError error) { return "invalid state"; case TI_ERROR_INCOMPATIBLE_MODULE: return "incompatible module"; + case TI_ERROR_OUT_OF_MEMORY: + return "out of memory"; default: return "unknown error"; } diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index b77b60a470ccc..69ea55d2c0bfb 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -117,39 +117,51 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) { TEST_F(CapiTest, TestBehaviorAllocateMemory) { auto inner = [&](TiArch arch) { - if (ti::is_arch_available(arch)) { - // Attempt to allocate memory with size of 1024 - TiRuntime runtime = ti_create_runtime(arch); - for (int i = 0; i < 4; ++i) { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); - TI_ASSERT(memory != TI_NULL_HANDLE); - ti_free_memory(runtime, memory); - } + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so this test is skipped", arch); + } + + // Attempt to allocate memory with size of 1024 + TiRuntime runtime = ti_create_runtime(arch); + { + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1024; + allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); + TI_ASSERT(memory != TI_NULL_HANDLE); + ti_free_memory(runtime, memory); + } - // runtime and allocate_info are both null - { - ti_allocate_memory(TI_NULL_HANDLE, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // Attemp to run out of memory + { + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1000000000000000000; + allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); + TI_ASSERT(memory == TI_NULL_HANDLE); + } - // runtime is not null, allocate_info is null - { - ti_allocate_memory(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } + // runtime and allocate_info are both null + { + ti_allocate_memory(TI_NULL_HANDLE, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } - // runtime is null, allocate is not null; - { - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - ti_allocate_memory(TI_NULL_HANDLE, &allocate_info); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); - } - ti_destroy_runtime(runtime); + // runtime is not null, allocate_info is null + { + ti_allocate_memory(runtime, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); } + + // runtime is null, allocate is not null; + { + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1024; + ti_allocate_memory(TI_NULL_HANDLE, &allocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + } + ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } @@ -163,10 +175,10 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) { { TiRuntime runtime = ti_create_runtime(arch); - TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; - allocate_info->size = 1024; - allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, allocate_info); + TiMemoryAllocateInfo *allocateInfo = new TiMemoryAllocateInfo; + allocateInfo->size = 1024; + allocateInfo->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, allocateInfo); ti_free_memory(runtime, memory); CHECK_TAICHI_SUCCESS(); ti_destroy_runtime(runtime); @@ -181,10 +193,10 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) { // runtime is null and allocate_info is valid { TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemoryAllocateInfo allocate_info; - allocate_info.size = 1024; - allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, &allocate_info); + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1024; + allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); ti_free_memory(TI_NULL_HANDLE, memory); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); ti_destroy_runtime(runtime); diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index 95652ea24c953..83c841a7ea834 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -515,7 +515,9 @@ IVkBuffer create_buffer(VkDevice device, VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info, &buffer->buffer, &buffer->allocation, nullptr); - assert(res != VK_ERROR_OUT_OF_DEVICE_MEMORY); + if(res == VK_ERROR_OUT_OF_DEVICE_MEMORY){ + throw std::bad_alloc(); + } BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer"); return buffer; From 55c8c8c6199b9d7625ffc693ff4ce941c9b28da0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Dec 2022 03:04:51 +0000 Subject: [PATCH 33/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 4 ++-- taichi/rhi/vulkan/vulkan_api.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 3878d69ab3d89..1f7acbb71f008 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -120,7 +120,7 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { if (!ti::is_arch_available(arch)) { TI_WARN("arch {} is not supported, so this test is skipped", arch); } - + // Attempt to allocate memory with size of 1024 TiRuntime runtime = ti_create_runtime(arch); { @@ -672,4 +672,4 @@ void test_behavior_get_cgraph_impl(TiArch arch) { TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { test_behavior_get_cgraph_impl(TI_ARCH_VULKAN); -} \ No newline at end of file +} diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index 83c841a7ea834..e4717ff812f60 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -515,7 +515,7 @@ IVkBuffer create_buffer(VkDevice device, VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info, &buffer->buffer, &buffer->allocation, nullptr); - if(res == VK_ERROR_OUT_OF_DEVICE_MEMORY){ + if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY) { throw std::bad_alloc(); } BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer"); From 9044d7a1c49cedbaf35cf1d3e2af7b8835b264d7 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Thu, 15 Dec 2022 12:11:40 +0800 Subject: [PATCH 34/42] final_test --- c_api/tests/c_api_behavior_test.cpp | 2 +- taichi/rhi/vulkan/vulkan_api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 1f7acbb71f008..de7d7cae1e88c 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -672,4 +672,4 @@ void test_behavior_get_cgraph_impl(TiArch arch) { TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { test_behavior_get_cgraph_impl(TI_ARCH_VULKAN); -} +} \ No newline at end of file diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index e4717ff812f60..abfcdfb40ad5e 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -516,7 +516,7 @@ IVkBuffer create_buffer(VkDevice device, VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info, &buffer->buffer, &buffer->allocation, nullptr); if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY) { - throw std::bad_alloc(); + throw std::bad_alloc(); //FIXME } BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer"); From 89b401e0ed88d1e8fd595491d2f32613228ba78f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Dec 2022 04:15:55 +0000 Subject: [PATCH 35/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 2 +- taichi/rhi/vulkan/vulkan_api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index de7d7cae1e88c..1f7acbb71f008 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -672,4 +672,4 @@ void test_behavior_get_cgraph_impl(TiArch arch) { TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { test_behavior_get_cgraph_impl(TI_ARCH_VULKAN); -} \ No newline at end of file +} diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index abfcdfb40ad5e..f77d83ebd2bef 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -516,7 +516,7 @@ IVkBuffer create_buffer(VkDevice device, VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info, &buffer->buffer, &buffer->allocation, nullptr); if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY) { - throw std::bad_alloc(); //FIXME + throw std::bad_alloc(); // FIXME } BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer"); From 6d6c2a1f6afaf37d193b84a4e79fdf6a55231677 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Thu, 15 Dec 2022 12:24:10 +0800 Subject: [PATCH 36/42] final_test --- taichi/rhi/vulkan/vulkan_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index f77d83ebd2bef..f78bb50473e70 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -516,8 +516,8 @@ IVkBuffer create_buffer(VkDevice device, VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info, &buffer->buffer, &buffer->allocation, nullptr); if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY) { - throw std::bad_alloc(); // FIXME - } + throw std::bad_alloc(); + }//FIXME: (damnkk) Should be removed when RHI error codes are ready BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer"); return buffer; From e4afea9bdb25534bc01f5a63fefa37060e3aab4b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Dec 2022 04:25:32 +0000 Subject: [PATCH 37/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/rhi/vulkan/vulkan_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index f78bb50473e70..17f14301c1efb 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -516,8 +516,8 @@ IVkBuffer create_buffer(VkDevice device, VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info, &buffer->buffer, &buffer->allocation, nullptr); if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY) { - throw std::bad_alloc(); - }//FIXME: (damnkk) Should be removed when RHI error codes are ready + throw std::bad_alloc(); + } // FIXME: (damnkk) Should be removed when RHI error codes are ready BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer"); return buffer; From f6e397c9031998bdc035b93e6c36d8fc9fd6ed21 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Sat, 17 Dec 2022 22:18:29 +0800 Subject: [PATCH 38/42] step --- c_api/tests/c_api_behavior_test.cpp | 96 +++++++++++++++++++---------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 1f7acbb71f008..ad639bda8a043 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -119,53 +119,83 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { auto inner = [&](TiArch arch) { if (!ti::is_arch_available(arch)) { TI_WARN("arch {} is not supported, so this test is skipped", arch); + return; } - // Attempt to allocate memory with size of 1024 TiRuntime runtime = ti_create_runtime(arch); - { - TiMemoryAllocateInfo allocateInfo; - allocateInfo.size = 1024; - allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); - TI_ASSERT(memory != TI_NULL_HANDLE); - ti_free_memory(runtime, memory); - } - - // Attemp to run out of memory - { - TiMemoryAllocateInfo allocateInfo; - allocateInfo.size = 1000000000000000000; - allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); - TI_ASSERT(memory == TI_NULL_HANDLE); - } + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1024; + allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); + TI_ASSERT(memory != TI_NULL_HANDLE); + ti_free_memory(runtime, memory); + ti_destroy_runtime(runtime); + }; + inner(TI_ARCH_VULKAN); +} - // runtime and allocate_info are both null - { - ti_allocate_memory(TI_NULL_HANDLE, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); +TEST_F(CapiTest, TestBehaviorAllocInvalidMemory){ + auto inner = [&](TiArch arch){ + if(!ti::is_arch_available(arch)){ + TI_WARN("arch {} is not supported, so this test is skipped",arch); + return; } + // Attemp to run out of memory + TiRuntime runtime = ti_create_runtime(arch); + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1000000000000000000; + allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); + TI_ASSERT(memory == TI_NULL_HANDLE); + ti_destroy_runtime(runtime); + }; + inner(TI_ARCH_VULKAN); +} - // runtime is not null, allocate_info is null - { - ti_allocate_memory(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); +TEST_F(CapiTest, TestBehaviorAllocMemoryNoArg){ + auto inner = [&](TiArch arch){ + if(!ti::is_arch_available(arch)){ + TI_WARN("arch {} is not supported, so this test is skipped",arch); + return; } + // runtime and allocate_info are both null + ti_allocate_memory(TI_NULL_HANDLE, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + }; + inner(TI_ARCH_VULKAN); +} - // runtime is null, allocate is not null; - { - TiMemoryAllocateInfo allocateInfo; - allocateInfo.size = 1024; - ti_allocate_memory(TI_NULL_HANDLE, &allocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); +TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo){ + auto inner = [&](TiArch arch){ + if(!ti::is_arch_available(arch)){ + TI_WARN("arch {} is not supported, so this test is skipped",arch); + return; } + // runtime is not null, allocate_info is null + TiRuntime runtime = ti_create_runtime(arch); + ti_allocate_memory(runtime, nullptr); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); } +TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime){ + auto inner = [&](TiArch arch){ + if(!ti::is_arch_available(arch)){ + TI_WARN("arch {} is not supported, so this test is skipped",arch); + return; + } + // runtime is null, allocate is not null; + TiMemoryAllocateInfo allocateInfo; + allocateInfo.size = 1024; + ti_allocate_memory(TI_NULL_HANDLE, &allocateInfo); + CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); +}; + inner(TI_ARCH_VULKAN); +} + TEST_F(CapiTest, TestBehaviorFreeMemory) { auto inner = [](TiArch arch) { if (!ti::is_arch_available(arch)) { From 6a12eac66fe6792add293e24d0b373d6b7b2a948 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 17 Dec 2022 14:19:49 +0000 Subject: [PATCH 39/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index ad639bda8a043..720353e880e09 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -134,10 +134,10 @@ TEST_F(CapiTest, TestBehaviorAllocateMemory) { inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocInvalidMemory){ - auto inner = [&](TiArch arch){ - if(!ti::is_arch_available(arch)){ - TI_WARN("arch {} is not supported, so this test is skipped",arch); +TEST_F(CapiTest, TestBehaviorAllocInvalidMemory) { + auto inner = [&](TiArch arch) { + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so this test is skipped", arch); return; } // Attemp to run out of memory @@ -153,10 +153,10 @@ TEST_F(CapiTest, TestBehaviorAllocInvalidMemory){ inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocMemoryNoArg){ - auto inner = [&](TiArch arch){ - if(!ti::is_arch_available(arch)){ - TI_WARN("arch {} is not supported, so this test is skipped",arch); +TEST_F(CapiTest, TestBehaviorAllocMemoryNoArg) { + auto inner = [&](TiArch arch) { + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so this test is skipped", arch); return; } // runtime and allocate_info are both null @@ -166,10 +166,10 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoArg){ inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo){ - auto inner = [&](TiArch arch){ - if(!ti::is_arch_available(arch)){ - TI_WARN("arch {} is not supported, so this test is skipped",arch); +TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo) { + auto inner = [&](TiArch arch) { + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so this test is skipped", arch); return; } // runtime is not null, allocate_info is null @@ -181,10 +181,10 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo){ inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime){ - auto inner = [&](TiArch arch){ - if(!ti::is_arch_available(arch)){ - TI_WARN("arch {} is not supported, so this test is skipped",arch); +TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime) { + auto inner = [&](TiArch arch) { + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so this test is skipped", arch); return; } // runtime is null, allocate is not null; @@ -192,7 +192,7 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime){ allocateInfo.size = 1024; ti_allocate_memory(TI_NULL_HANDLE, &allocateInfo); CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); -}; + }; inner(TI_ARCH_VULKAN); } From f90c1172ccc4c02041edd39bcbe3e32048846d76 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Dec 2022 06:27:26 +0000 Subject: [PATCH 40/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 38ca2800dfc88..8a6a8cc83678f 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -166,10 +166,10 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo) { inner(TI_ARCH_VULKAN); } -TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime){ - auto inner = [&](TiArch arch){ - if(!ti::is_arch_available(arch)){ - TI_WARN("arch {} is not supported, so this test is skipped",arch); +TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime) { + auto inner = [&](TiArch arch) { + if (!ti::is_arch_available(arch)) { + TI_WARN("arch {} is not supported, so this test is skipped", arch); return; } // runtime is null, allocate is not null; From e1916e872776d8920c3851198c973e02ed9a6780 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Tue, 20 Dec 2022 14:57:58 +0800 Subject: [PATCH 41/42] step --- c_api/tests/c_api_behavior_test.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 8a6a8cc83678f..9acd8b885e240 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -131,7 +131,7 @@ TEST_F(CapiTest, TestBehaviorAllocInvalidMemory) { allocateInfo.size = 1000000000000000000; allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_OUT_OF_MEMORY); + EXPECT_TAICHI_ERROR(TI_ERROR_OUT_OF_MEMORY); TI_ASSERT(memory == TI_NULL_HANDLE); ti_destroy_runtime(runtime); }; @@ -146,7 +146,7 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoArg) { } // runtime and allocate_info are both null ti_allocate_memory(TI_NULL_HANDLE, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL); }; inner(TI_ARCH_VULKAN); } @@ -160,7 +160,7 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo) { // runtime is not null, allocate_info is null TiRuntime runtime = ti_create_runtime(arch); ti_allocate_memory(runtime, nullptr); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL); ti_destroy_runtime(runtime); }; inner(TI_ARCH_VULKAN); @@ -176,7 +176,7 @@ TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime) { TiMemoryAllocateInfo allocateInfo; allocateInfo.size = 1024; ti_allocate_memory(TI_NULL_HANDLE, &allocateInfo); - CHECK_TAICHI_ERROR_IS(TI_ERROR_ARGUMENT_NULL); + EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL); }; inner(TI_ARCH_VULKAN); } @@ -190,10 +190,10 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) { { TiRuntime runtime = ti_create_runtime(arch); - TiMemoryAllocateInfo *allocateInfo = new TiMemoryAllocateInfo; - allocateInfo->size = 1024; - allocateInfo->usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, allocateInfo); + TiMemoryAllocateInfo *allocate_info = new TiMemoryAllocateInfo; + allocate_info->size = 1024; + allocate_info->usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, allocate_info); ti_free_memory(runtime, memory); ASSERT_TAICHI_SUCCESS(); ti_destroy_runtime(runtime); @@ -208,10 +208,10 @@ TEST_F(CapiTest, TestBehaviorFreeMemory) { // runtime is null and allocate_info is valid { TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); - TiMemoryAllocateInfo allocateInfo; - allocateInfo.size = 1024; - allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT; - TiMemory memory = ti_allocate_memory(runtime, &allocateInfo); + TiMemoryAllocateInfo allocate_info; + allocate_info.size = 1024; + allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT; + TiMemory memory = ti_allocate_memory(runtime, &allocate_info); ti_free_memory(TI_NULL_HANDLE, memory); EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL); ti_destroy_runtime(runtime); @@ -688,4 +688,4 @@ TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { }; test_behavior_get_cgraph_impl(TI_ARCH_VULKAN); -} +} \ No newline at end of file From f4758f0f9c151993708755d53b802a6ef97807d9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Dec 2022 06:59:14 +0000 Subject: [PATCH 42/42] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 9acd8b885e240..204c5b17629b1 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -688,4 +688,4 @@ TEST_F(CapiTest, TestBehaviorGetCgraphVulkan) { }; test_behavior_get_cgraph_impl(TI_ARCH_VULKAN); -} \ No newline at end of file +}