Skip to content

Instantly share code, notes, and snippets.

@BeMg
BeMg / main.py
Created February 25, 2019 13:03
Sample tvm to llvm IR
import tvm
N, M, L = 1024, 512, 64
A = tvm.placeholder((N, L), name='A')
B = tvm.placeholder((M, L), name='B')
k = tvm.reduce_axis((0, L), name='k')
C = tvm.compute((N, M), lambda i, j:
tvm.sum(A[i, k] * B[j, k], axis=k), name='C')
s = tvm.create_schedule(C.op)
print(tvm.lower(s, [A, B, C], simple_mode=True))
@BeMg
BeMg / main.c
Last active February 18, 2019 05:19
compiler course
int sum(int a, int b) {
return a+b;
}
void print(int);
int main() {
int a = 50;
int b = 50*123;
@BeMg
BeMg / quad_parm.cpp
Created December 27, 2018 12:08
quad 參數
GLfloat quadVertices[] = {
-150.0f, -150.0f, -150.0f,
-150.0f, -150.0f, 150.0f,
150.0f, -150.0f, -150.0f,
150.0f, -150.0f, -150.0f,
-150.0f, -150.0f, 150.0f,
150.0f, -150.0f, 150.0f
};
glUniformMatrix4fv(model_p.mv, 1, GL_FALSE, value_ptr(view2 *
@BeMg
BeMg / OnGithub
Last active December 4, 2020 11:18
build own riscv64-unknown-elf-gcc and spike environment
FROM ubuntu:18.04
MAINTAINER BeMg
RUN apt-get update && apt-get install -y git autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk \
build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev && mkdir risc-v
ENV RISCV /risc-v
RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain && \
cd riscv-gnu-toolchain && ./configure --prefix=$RISCV && make -j4 && \
rm -rf riscv-binutils && git clone --branch test git@github.com:BeMg/riscv-bintuils.git riscv-binutils && \
cd riscv-binutils && ./configure --prefix=$RISCV --target=riscv64-unknown-elf && make -j4 && make install -j4 && cd
@BeMg
BeMg / read_from_file.c
Created November 30, 2018 01:29
spike 讀檔測試程式
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc > 0) {
printf("%s\n", argv[1]);
}
FILE *pfile = fopen(argv[1], "r");
@BeMg
BeMg / loadscene.cpp
Created November 26, 2018 05:39
GPA AS2
void loadScene(string path, string img_path, vector<Shape> &vS, vector<Material> &vM) {
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
for (unsigned int i = 0; i < scene->mNumMaterials; ++i)
{
aiMaterial *material = scene->mMaterials[i];
Material Material;
aiString texturePath;
@BeMg
BeMg / add16.c
Last active October 31, 2018 14:03
riscv_toolchain in docker
#include <stdio.h>
int test(int a[], int b[]) {
asm volatile(
"ld a2, 0(a0)\n\t"
"ld a3, 0(a1)\n\t"
"add16 a2, a2, a3 \n\t"
"sd a2, 0(a0)\n\t"
);
}
@BeMg
BeMg / main.rkt
Last active September 16, 2018 08:07
just backup
#lang racket
;; Programming Languages Homework 5 Simple Test
;; Save this file to the same directory as your homework file
;; These are basic tests. Passing these tests does not guarantee that your code will pass the actual homework grader
;; Be sure to put your homework file in the same folder as this test file.
;; Uncomment the line below and, if necessary, change the filename
;;(require "hw5")
(require rackunit)
@BeMg
BeMg / build.common
Created September 10, 2018 10:17
For riscv-tools build
# Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain.
# Tools will be installed to $RISCV.
if [ "x$RISCV" = "x" ]
then
echo "Please set the RISCV environment variable to your preferred install path."
exit 1
fi
# Use gmake instead of make if it exists.
@BeMg
BeMg / hw1.md
Created July 25, 2018 04:58
homework for new c language programer

作業一 Sorting

實作 sorting algorithm 以熟悉演算法與程式語言。

預計實作

  • bubble sort
  • insertion sort
  • merge sort
  • quick sort