Skip to content

Instantly share code, notes, and snippets.

// an extract from a REPL session
val A = CuMatrix.fromDense(DenseMatrix((1.0f, 1.0f, 2.0f, 1.0f), (1.0f, 2.0f, 1.0f, -2.0f), (3.0f, -1.0f, 3.0f, -2.0f), (-2.0f, 3.0f, -1.0f, 1.0f)))
val N = 4
val Aarray = jcuda.Pointer.to(A.offsetPointer) // this is the one I'm most uncertain about
val P = CuMatrix.create[Int](N, 1) // but I'm not sure about those 2 either
val info = CuMatrix.create[Int](N,1)
JCublas2.cublasSgetrfBatched(handle, N, Aarray, N, P.offsetPointer, info.offsetPointer, 1) // this call returns success (0),
// but A is zeroed-out
@piotrMocz
piotrMocz / getrf_test.cu
Created June 8, 2014 00:12
Test of cublasSgetrfBatched
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#define cudacall(call) \
do \
{ \
cudaError_t err = (call); \
if(cudaSuccess != err) \
@piotrMocz
piotrMocz / lu_getrf.scala
Created June 8, 2014 20:04
Finally working -- only square matrices though
def LU(A: CuMatrix[Float])(implicit handle: cublasHandle): CuMatrix[Float]= {
if (A.rows != A.cols) {
println("Matrix has to be square.")
return A
}
val d_A = CuMatrix.create[Float](A.rows, A.cols)
d_A := A
val P = CuMatrix.create[Int](d_A.rows, 1)
@piotrMocz
piotrMocz / bidiagonalization.scala
Created August 4, 2014 19:22
This is more or less what despair looks like in code.
/**
* Bidiagonalization with removed calls to my own kernels, inlined functions for
* calculating the householder vectors and a few other minor changes.
*/
def bidiagDoubleInline(A: CuMatrix[Double])(implicit handle: cublasHandle): (CuMatrix[Double], CuMatrix[Double], CuMatrix[Double]) = {
if (A.rows < A.cols) {
println("Number of rows of matrix A cannot be smaller than the number of columns.")
return (null, A, null)
}
@piotrMocz
piotrMocz / DispatchTest.java
Created April 13, 2015 22:24
Single vs. Multiple dispatch
// przyklad ma na celu zobrazowanie czym rozni sie multiple dispatch od single dispatch.
public class DispatchTest {
public static void main(String[] args) {
Foo foo = new Bar(); // typ statyczny: Foo, typ runtime'owy: Bar
A a = new B(); // typ statyczny: A, typ runtime'owy: B
foo.fooMethod(a); // wolamy tak, by dac szanse kompilatorowi sie wykazac (dwa razy inny typ
// dynamiczny i statyczny)
}
}
@piotrMocz
piotrMocz / typeclasses.scala
Last active August 29, 2015 14:19
Typeclasses vs. Overloading vs. Inheritance vs. Monkeypatching
/**
* Przykład w Scali, bo to jedyny znany mi język, który udostępnia i dziedziczenie, i typeclassy.
* Jest prosty, więc nie trzeba znać ani troche Scali :)
*
* tl;dr Typeclassy są super, ale alternatywą są interfejsy, a nie przeciążanie.
*/
// sytuacja trochę jak z Accelerate'em: biblioteka do algebry liniowej, czyli udostępnia jakiś typ macierzowy (A jest parametrem typu):
class Matrix[A](values: Array[A], rows: Int, cols: Int)
@piotrMocz
piotrMocz / Slajs.java
Created May 19, 2015 07:54
Ice ice baby.
public class NewsReceiver extends _FinancialNewsReceiverDisp {
private static final long serialVersionUID = -3538248252658050588L;
public static HashMap<CurrencyPair, Float> exchangeRates = new HashMap<>();
public static HashMap<Currency, Float> interestRates = new HashMap<>();
@Override
public void interestRate(float rate, Currency curr, Current __current) {
interestRates.put(curr, rate);
@piotrMocz
piotrMocz / sources.list
Last active October 7, 2023 03:55
/etc/apt/sources.list file for arm cross-compilation under amd64
# sources.list file for arm cross-development under amd64
#deb [arch=amd64] cdrom:[Ubuntu 14.04.3 LTS _Trusty Tahr_ - Beta amd64 (20150805)]/ trusty main restricted
deb [arch=armhf] http://ports.ubuntu.com/ trusty main restricted universe multiverse
deb [arch=armhf] http://ports.ubuntu.com/ trusty-security main restricted universe multiverse
deb [arch=armhf] http://ports.ubuntu.com/ trusty-updates main restricted universe multiverse
deb [arch=armhf] http://ports.ubuntu.com/ trusty-backports main restricted universe multiverse
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
@piotrMocz
piotrMocz / buctrap_trusty.sh
Created September 6, 2015 17:37
Install ghc on ubuntu
# Disclaimer: work-in-progress-kind-of-thing, really more of a dockerfile-became-shellscript
# Installs emulated arm ghc on amd64 box
# It assumes you're running Ubuntu 14.04 (Trusty)
# Oh btw -- run with sudo
# from Alexey Raga's dockerfile (to stop apt from asking you for a "yes"):
export DEBIAN_FRONTEND=noninteractive
export OPTS_APT="-y --force-yes --no-install-recommends"
apt-get update
@piotrMocz
piotrMocz / Main.scala
Created October 31, 2015 20:51
Reactive lab 3
/**
* Created by moczur on 10/19/15.
*/
import akka.event.LoggingReceive
import akka.actor._
import scala.concurrent.duration._
import scala.util.Random
import language.postfixOps