神経回路網の計算
Cocoa勉強会 関東 2017.11.22
Bitz Co., Ltd. 村上幸雄
• Accelerate Framework
• BNNS
ニューラルネットワーク
• Quadrature
積分
• Basic Linear Algebra Subprograms (BLAS)
線形代数
• Sparse Solvers
const int SIZE = 150 ;
MatrixXf mat1 = Matrix<float, SIZE, SIZE>::Random() ;
MatrixXf mat2 = Matrix<float, SIZE, SIZE>::Random() ;
float* mat1_ = (float *)malloc(sizeof(float)*SIZE*SIZE) ;
float* mat2_ = (float *)malloc(sizeof(float)*SIZE*SIZE) ;
for( int i=0 ; i<SIZE ; i++ ) {
for( int j=0 ; j<SIZE ; j++ ) {
mat1_[j+i*SIZE] = mat1(i, j) ;
mat2_[j+i*SIZE] = mat2(i, j) ;
}
}
// multiplication by CBLAS
void (^testCBLAS)() = ^{
NSTimeInterval time_start = [NSDate timeIntervalSinceReferenceDate] ;
for( int i=0 ; i<10 ; i++ ) {
float* volatile mat_ans_ = (float *)malloc(sizeof(float)*SIZE*SIZE) ;
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
SIZE, SIZE, SIZE, 1, mat1_, SIZE, mat2_, SIZE, 0, mat_ans_, SIZE);
//for( int a=SIZE-3 ; a<SIZE ; a++ ) { printf("%fn", mat_ans_[a+a*SIZE]) ; }
free(mat_ans_) ;
}
NSTimeInterval time_stop = [NSDate timeIntervalSinceReferenceDate] ;
time_cblas += time_stop - time_start ;
};
let kSize: Int32 = 150
let kSizeSize: Int = Int(kSize * kSize)
typealias FloatPointer = UnsafeMutablePointer<Float>
var matAns = FloatPointer.allocate(capacity: kSizeSize)
var mat1 = FloatPointer.allocate(capacity: kSizeSize)
var mat2 = FloatPointer.allocate(capacity: kSizeSize)
let p = unsafeBitCast(matAns, to: UnsafeMutablePointer<Float>.self)
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, kSize, kSize, kSize, 1, mat1, kS
matAns.deallocate(capacity: kSizeSize)
cblas_sgemmは、行列A, B, Cとスカラーα, βでαAB + βCを計算

神経回路網の計算

  • 1.
  • 2.
    • Accelerate Framework •BNNS ニューラルネットワーク • Quadrature 積分 • Basic Linear Algebra Subprograms (BLAS) 線形代数 • Sparse Solvers
  • 3.
    const int SIZE= 150 ; MatrixXf mat1 = Matrix<float, SIZE, SIZE>::Random() ; MatrixXf mat2 = Matrix<float, SIZE, SIZE>::Random() ; float* mat1_ = (float *)malloc(sizeof(float)*SIZE*SIZE) ; float* mat2_ = (float *)malloc(sizeof(float)*SIZE*SIZE) ; for( int i=0 ; i<SIZE ; i++ ) { for( int j=0 ; j<SIZE ; j++ ) { mat1_[j+i*SIZE] = mat1(i, j) ; mat2_[j+i*SIZE] = mat2(i, j) ; } } // multiplication by CBLAS void (^testCBLAS)() = ^{ NSTimeInterval time_start = [NSDate timeIntervalSinceReferenceDate] ; for( int i=0 ; i<10 ; i++ ) { float* volatile mat_ans_ = (float *)malloc(sizeof(float)*SIZE*SIZE) ; cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, SIZE, SIZE, SIZE, 1, mat1_, SIZE, mat2_, SIZE, 0, mat_ans_, SIZE); //for( int a=SIZE-3 ; a<SIZE ; a++ ) { printf("%fn", mat_ans_[a+a*SIZE]) ; } free(mat_ans_) ; } NSTimeInterval time_stop = [NSDate timeIntervalSinceReferenceDate] ; time_cblas += time_stop - time_start ; };
  • 4.
    let kSize: Int32= 150 let kSizeSize: Int = Int(kSize * kSize) typealias FloatPointer = UnsafeMutablePointer<Float> var matAns = FloatPointer.allocate(capacity: kSizeSize) var mat1 = FloatPointer.allocate(capacity: kSizeSize) var mat2 = FloatPointer.allocate(capacity: kSizeSize) let p = unsafeBitCast(matAns, to: UnsafeMutablePointer<Float>.self) cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, kSize, kSize, kSize, 1, mat1, kS matAns.deallocate(capacity: kSizeSize) cblas_sgemmは、行列A, B, Cとスカラーα, βでαAB + βCを計算