Skip to content

Instantly share code, notes, and snippets.

Avatar

pengyu FantasyVR

  • Taichi Graphics
  • Beijing
View GitHub Profile
View fem99_export.py
import taichi as ti
import numpy as np
ti.init(arch=ti.gpu)
N = 32
dt = 1e-4
dx = 1 / N
rho = 4e1
NF = 2 * N**2 # number of faces
View cusparse_spmv.cu
#include <cuda_runtime_api.h> // cudaMalloc, cudaMemcpy, etc.
#include <cusparse.h> // cusparseSpMV
#include <stdio.h> // printf
#include <stdlib.h> // EXIT_FAILURE
/*
* cuSparse Version: 11.4.0
*
* How to compile:
* nvcc -arch=sm_75 -lcusparse cusparse_spmv.cu -o cusparse_spmv
View ndarry_sparse_matrix.py
"""
jiafengreviewhttps://github.com/taichi-dev/taichi/pull/4841#discussion_r880193695
这里我发现 内存的layout确实会影响稀疏矩阵的构建。
目前的方案是:
1. 直接获取ndarrydata_ptr
2. 从该指针处的数据按照[row, col, value]的三元组的内存排布创建Sparse matrix
目前的脚本尝试着各种ndarray的内存分布。
View mpm88_parallel_p2g.py
# MPM-MLS in 88 lines of Taichi code, originally created by @yuanming-hu
# P2G is parallel in this script.
import taichi as ti
ti.init(arch=ti.gpu)
n_particles = 8192
n_grid = 128
dx = 1 / n_grid
dt = 2e-4
@FantasyVR
FantasyVR / vulkan_test.cpp
Created Apr 21, 2022
Create vulkan instance twice.
View vulkan_test.cpp
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
#include <vector>
#include <string>
View gs_pbd_ggui.py
import taichi as ti
ti.init(arch=ti.cuda)
N = 5
NV = (N + 1)**2
NT = 2 * N**2
NE = 2 * N * (N + 1) + N**2
pos = ti.Vector.field(3, ti.f32, shape=NV)
tri = ti.field(ti.i32, shape=3 * NT)
edge = ti.Vector.field(2, ti.i32, shape=NE)
View cg_implicit_mass_spring.py
# https://www.cs.cmu.edu/~baraff/papers/sig98.pdf
import argparse
import numpy as np
import taichi as ti
@ti.data_oriented
class Cloth:
View taichi_random_selection.py
"""
Loop:
Press start button to start random selection
Press end to show the selected ID
"""
import taichi as ti
ti.init(arch=ti.cpu,cpu_max_num_threads=1)
n = 100
userId = ti.field(ti.i32, shape=n) # userId is an array of 0s
View 01_packed_mode_test.py
import taichi as ti
ti.init(arch=ti.cpu, packed=True)
a = ti.field(dtype=ti.i32)
ti.root.dense(ti.ij, (2, 3)).dense(ti.ij, (2,3)).place(a)
@ti.kernel
def fill():
for i, j in a:
View implicit_mass_spring.py
# https://www.cs.cmu.edu/~baraff/papers/sig98.pdf
import taichi as ti
import numpy as np
import argparse
@ti.data_oriented
class Cloth:
def __init__(self, N):
self.N = N