Problem with cblas_sgemm in 64 bit build
Problem with cblas_sgemm in 64 bit build
- Subject: Problem with cblas_sgemm in 64 bit build
- From: Rick Hoge <email@hidden>
- Date: Wed, 4 Jun 2008 13:54:31 -0400
I've been tesing a 64 bit build of an application that uses the BLAS
function cblas_sgemm to multiply two matrices. The code works fine in
32 bit builds (building with Xcode 3.0 on Leopard 10.5.3)
There is a strange problem that I think I have isolated to the output
of the above function - when the matrix dimensions exceed a certain
size, the output matrix (the product) contains rows that are zeroed
out. I feel like it must be some aspect of my code that is not 64 bit
clean, but I just can't track it down.
The BLAS multiplication function is wrapped in a method of a matrix
class I have implemented - the code is provided below. If anyone can
spot any potential problems lurking in this code, I would be
grateful. I have read the 64-bit transition guide and complied with
all the recommendations as far as I can tell.
I was wondering if it could be some kind of an alignment problem, but
as the data are 4-byte floats (which don't change size under 64 bits)
I don't really see how...
Thanks -
Rick
// Here is the code:
-(NLMatrix *)mTimes:(NLMatrix *)matrix2 { // Matrix multiply two
matrices, return the result
// Do some error checking
if (numColumns != [matrix2 numRows]) {
NSLog(@"Error: columns1 must equal rows2 for matrix
multiplication");
}
float *mat1Data = (float*)[self bytes];
float *mat2Data = (float*)[matrix2 bytes];
int numRows2 = [matrix2 numRows]; // This method returns int
int numColumns2 = [matrix2 numColumns]; // This also returns int
float *newData = (float*)malloc(numRows * numColumns2 *
(int)sizeof(float));
float alpha = 1.0f;
float beta = 0.0f;
// NSLog(@"Multiplying a %dx%d matrix by a %dx%d matrix (result is
%dx%d)",
// numRows,numColumns,numRows2,numColumns2,numRows,numColumns2);
// Use cblas_sgemm to compute product: C = alpha*A * B + beta*C
cblas_sgemm (CblasColMajor, // Matrix is in column major order
CblasNoTrans, // Don't transpose A
CblasNoTrans, // Don't transpose B
numRows, // Number of rows in A (and C)
numColumns2, // Number of columns in B (and C)
numColumns, // Number of columns in A (and rows in B)
alpha, // Scalar factor multiplying A
mat1Data, // Pointer to A
numRows, // Length of leading dim of A (number of
rows for col major)
mat2Data, // Pointer to B
numRows2, // Length of leading dim of B (number of
rows for col major)
beta, // Scalar factor multiplying C
newData, // Pointer to C
numRows // Length of leading dim of C (number of rows
for col major)
);
NLMatrix *newMatrix = [[NLMatrix alloc] initWithBytes:newData
rows:numRows columns:numColumns2];
free(newData);
return [newMatrix autorelease];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden