This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <cuda_runtime.h> | |
#include <cublas_v2.h> | |
#define cudacall(call) \ | |
do \ | |
{ \ | |
cudaError_t err = (call); \ | |
if(cudaSuccess != err) \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
NewerOlder