Skip to content

Instantly share code, notes, and snippets.

object reduce_vs_fold {
println("Welcome to Eclipse Scala worksheet") //> Welcome to Eclipse Scala worksheet
def time[A](f: => A) = {
val now = System.nanoTime
val result = f
val micros = (System.nanoTime - now) / 1000.0
println("%12.4f micro seconds".format(micros))
result
} //> time: [A](f: => A)A
@chick
chick / gist:1020a7a87d70e84ba4a0
Created November 20, 2014 22:37
Python iterator over indices of hull of n-dimensional matrix
import copy
class HaloEnumerator(object):
"""
Enumerates all points of n-dimensional matrix described by shape that are on the exterior of the matrix
where the exterior thickness is described by halo, halo must be the same size as shape.
Currently halos have only one value for each dimension though it perhaps should be built to accommodate
a separate value for low indices and high indices
"""
@chick
chick / PadderSpec.scala
Last active July 18, 2016 16:16
How do I right pad an SInt
// See LICENSE for license details.
package simple.example
import chisel3._
import chisel3.iotesters.{PeekPokeTester, runPeekPokeTester, Backend}
import chisel3.util.{Cat, Fill}
import org.scalatest.{Matchers, FlatSpec}
class Padable(val numBits: Int, val radixPoint: Int) extends Bundle {
@chick
chick / control.c-kernel.cl
Created December 30, 2016 22:30
Simple OpenCL kernel for 7pt operator
// <file: control.c>
#include <stdio.h>
#include <time.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
int control(cl_command_queue queue, cl_kernel kernel_0, cl_mem out, cl_mem mesh) {
@chick
chick / control+kernel
Created December 30, 2016 22:33
Non-pencil model OpenCL kernel for 7pt operator
// <file: control.c>
#include <stdio.h>
#include <time.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
int control(cl_command_queue queue, cl_kernel kernel_0, cl_mem out, cl_mem mesh) {
// <file: kernel_0.cl>
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#define encode514_514_514(x0, x1, x2) (264196 * (long) (x0) + 514 * (long) (x1) + 1 * (long) (x2))
#define encode514_514(x0, x1) (514 * (long) (x0) + 1 * (long) (x1))
#define encode10_18(x0, x1) (18 * (long) (x0) + 1 * (long) (x1))
__kernel void kernel_0(__global double* out, __global double* mesh) {
size_t tile_id_1 = get_group_id(0);
size_t tile_id_2 = get_group_id(1);
size_t packed_global_id_1 = get_global_id(0);
@chick
chick / pencil_kernel_with_local_mem.cl
Created January 7, 2017 00:21
opencl pencil kernel using local memory in planes
// <file: kernel_0.cl>
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#define encode514_514_514(x0, x1, x2) (264196 * (long) (x0) + 514 * (long) (x1) + 1 * (long) (x2))
#define encode514_514(x0, x1) (514 * (long) (x0) + 1 * (long) (x1))
#define encode10_18(x0, x1) (18 * (long) (x0) + 1 * (long) (x1))
__kernel void kernel_0(__global double* out, __global double* mesh) {
__local double local_buf_0[180];
__local double local_buf_1[180];
__local double local_buf_2[180];
@chick
chick / bundle-init-code-frag
Created March 23, 2017 21:30
How to initialize a bundle
class MyBundle extends Bundle {
val x = Bool()
val y = UInt(8.W)
val z = Bool()
}
object MyBundle {
/**
* initialize x and y but not z,
* @return
@chick
chick / AccumulatorTester.scala
Created June 23, 2017 21:32
Illustrates an investigation between the vcd output of verilator vs interpreter when reset is called
// See LICENSE for license details.
package examples
/**
* verilator and interpreter have inconsistent behavior around reset.
*/
import java.io.File
@chick
chick / SortIndexAndTake.scala
Created October 19, 2017 05:31
Example of a way of sorting a vector of FixedPoint values, returning the array indices of first N lowest values
package hardwaresort
import chisel3._
import chisel3.experimental.FixedPoint
import chisel3.internal.firrtl.KnownBinaryPoint
import chisel3.iotesters.PeekPokeTester
import chisel3.util.log2Ceil
//scalastyle:off magic.number
/**