Writing kernel modules in Haskell
Posted Sep 15, 2009 10:35 UTC (Tue) by
sagrailo (guest, #48054)
In reply to:
Writing kernel modules in Haskell by Ed_L.
Parent article:
Writing kernel modules in Haskell
Yeah, right... I just quickly wrote this code (to multiply two matrices):
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iostream>
extern "C" {
#include <cblas.h>
}
#include <tnt.h>
#define N 1024
int
main(void)
{
float* A = new float[N * N];
float* B = new float[N * N];
float* C = new float[N * N];
std::fill(C, C + N * N, 0);
TNT::Array2D<float< ATNT(N, N);
TNT::Array2D<float< BTNT(N, N);
TNT::Array2D<float< CTNT(N, N);
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
A[i * N + j] = ATNT[i][j] = 1;
B[i * N + j] = BTNT[i][j] = 1;
}
clock_t start, end;
start = clock();
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, N, N, N, 1, A, N, B,
N, 0, C, N);
end = clock();
std::cerr
<< "ATLAS: "
<< (float) (end - start) / CLOCKS_PER_SEC
<< "s"
<< std::endl;
start = clock();
CTNT = TNT::matmult(ATNT, BTNT);
end = clock();
std::cerr
<< "TNT: "
<< (float) (end - start) / CLOCKS_PER_SEC
<< "s"
<< std::endl;
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
assert(C[i * N + j] == N);
assert(CTNT[i][j] == N);
}
delete [] A;
delete [] B;
delete [] C;
}
Complied with (I've put TNT into /tmp, and I have ATLAS installed in /usr/local):
g++ -O3 -o foo -I/tmp/tnt foo.cpp -lcblas -latlas
The output, on my old ThinkPad T61p:
ATLAS: 0.22s
TNT: 17.64s
So - C++ almost two orders of magnitude slower (and that's typical, in my experience).
(
Log in to post comments)