当前位置: 首页>>代码示例>>C++>>正文


C++ cblas_sgemm函数代码示例

本文整理汇总了C++中cblas_sgemm函数的典型用法代码示例。如果您正苦于以下问题:C++ cblas_sgemm函数的具体用法?C++ cblas_sgemm怎么用?C++ cblas_sgemm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cblas_sgemm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) {
    srand48(time(NULL));

    int m = atoi(argv[1]);
    int k = atoi(argv[2]);
    int n = atoi(argv[3]);
    // std::string interleaving = argv[4];
    char* outfile = argv[4];

    FILE *f = fopen(outfile,"a");

    float *A, *B, *C;
    A = (float*) malloc(m * k * sizeof(float));
    B = (float*) malloc(k * n * sizeof(float));
    C = (float*) malloc(m * n * sizeof(float));
    initialize(m, k, n, A, B, C);

    // Time multiplication
    struct timeval start, end;
    gettimeofday(&start, NULL);
    cblas_sgemm(CblasColMajor,CblasNoTrans,CblasNoTrans, m,n,k, 1, A,m, B,k, 1, C,m);
    gettimeofday(&end, NULL);
    double seconds = (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);
    double Gflop_s = 2e-9 * m * k * n / seconds;
    fprintf(f,"MKL-SINGLE,%d,%d,%d,%s,%f\n", m, k, n, "MKL", Gflop_s);
    printf("MKL-SINGLE,%d,%d,%d,%s,%f\n", m, k, n, "MKL", Gflop_s);

    // Housekeeping
    free(A);
    free(B);
    free(C);
    fclose(f);
    return 0;
}
开发者ID:dose78,项目名称:FRPA,代码行数:34,代码来源:mkl_harness-single.cpp

示例2: step

/******************************
compute a corr-matrix based on trial, starting row and step
input: a trial struct, starting row id, step (the row of the correlation matrix, whose column is row), the raw matrix struct array
output: the corr-matrix struct
*******************************/
CorrMatrix* CorrMatrixComputation(Trial trial, int sr, int step, RawMatrix** matrices1, RawMatrix** matrices2)
{
  int sid = trial.sid;
  int sc = trial.sc;
  int ec = trial.ec;
  int row1 = matrices1[sid]->row;
  int row2 = matrices2[sid]->row;
  int col = matrices1[sid]->col;  // the column of 1 and 2 should be the same, i.e. the number of TRs of a block
  float* mat1 = matrices1[sid]->matrix;
  float* mat2 = matrices2[sid]->matrix;
  float* buf1 = new float[row1*col]; // col is more than what really need, just in case
  float* buf2 = new float[row2*col]; // col is more than what really need, just in case
  int ml1 = getBuf(sc, ec, row1, col, mat1, buf1);  // get the normalized matrix, return the length of time points to be computed
  int ml2 = getBuf(sc, ec, row2, col, mat2, buf2);  // get the normalized matrix, return the length of time points to be computed, m1==m2
  CorrMatrix* c_matrix = new CorrMatrix();
  c_matrix->sid = sid;
  c_matrix->tlabel = trial.label;
  c_matrix->sr = sr;
  c_matrix->step = step;
  c_matrix->nVoxels = row2; //
  float* corrs = new float[step*row2];
  cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, step, row2, ml1, 1.0, buf1+sr*ml1, ml1, buf2, ml2, 0.0, corrs, row2);
  c_matrix->matrix = corrs;
  delete[] buf1;
  delete[] buf2;
  return c_matrix;
}
开发者ID:Wildcarde,项目名称:fcma-toolbox,代码行数:32,代码来源:MatComputation.cpp

示例3: distance

// Calculate distances with matrix/matrix operations (BLAS3)
void distance(int N, int D, float *data, float *result) {
	int blockSize = 512;
  int blockCount = N / blockSize;
  int remainder = N % blockSize;
  
  if (remainder) blockCount++; // Include the ragged edge
  
  dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  
	float *diag = (float *)malloc(sizeof(float) * N);
  float *C = (float *)malloc(blockCount * blockSize * blockSize * sizeof(float));
  
  dispatch_apply(blockCount, queue, ^(size_t m) {
    int i, j;
    
    int outerDim = blockSize;
    if (m == blockCount - 1 && remainder) outerDim = remainder;
    
    
    cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, outerDim, outerDim, D,
                1, &data[m * blockSize * D], D, &data[m * blockSize * D], D, 0,
                &C[m * blockSize * blockSize], outerDim);
    
    for(i = 0; i < outerDim; i++)
      diag[m * blockSize + i] = C[m * blockSize * blockSize + i * (outerDim + 1)];
    
    for(i = 0; i < outerDim; i++)
      for(j = i + 1; j < outerDim; j++)
        result[utndidx(i + m * blockSize, j + m * blockSize)] = \
        sqrt(diag[i + m * blockSize] + diag[j + m * blockSize] - \
             2 * C[m * blockSize * blockSize + j * outerDim + i]);
  });
开发者ID:abrahante,项目名称:divvy,代码行数:33,代码来源:distance.c

示例4: col_major_fmatrix_multiply

void col_major_fmatrix_multiply(__CLPK_integer row1_ct, __CLPK_integer col2_ct, __CLPK_integer common_ct, float* inmatrix1, float* inmatrix2, float* outmatrix) {
#ifdef NOLAPACK
    uintptr_t row1_ct_l = row1_ct;
    uintptr_t col2_ct_l = col2_ct;
    uintptr_t common_ct_l = common_ct;
    uintptr_t row_idx;
    uintptr_t col_idx;
    uintptr_t com_idx;
    float* fptr;
    float fxx;
    // not optimized
    for (col_idx = 0; col_idx < col2_ct_l; col_idx++) {
        for (row_idx = 0; row_idx < row1_ct_l; row_idx++) {
            fxx = 0;
            fptr = &(inmatrix2[col_idx * common_ct]);
            for (com_idx = 0; com_idx < common_ct_l; com_idx++) {
                fxx += (*fptr++) * inmatrix1[com_idx * row1_ct_l + row_idx];
            }
            *outmatrix++ = fxx;
        }
    }
#else
#ifdef _WIN32
    char blas_char = 'N';
    float fyy = 1;
    float fzz = 0;
    sgemm_(&blas_char, &blas_char, &row1_ct, &col2_ct, &common_ct, &fyy, inmatrix1, &row1_ct, inmatrix2, &common_ct, &fzz, outmatrix, &row1_ct);
#else
    cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, row1_ct, col2_ct, common_ct, 1.0, inmatrix1, row1_ct, inmatrix2, common_ct, 0.0, outmatrix, row1_ct);
#endif // _WIN32
#endif // NOLAPACK
}
开发者ID:chrchang,项目名称:plink-ng,代码行数:32,代码来源:plink_matrix.c

示例5: gemm

/* C <- alpha*A*B + beta*C */
void gemm(double alpha, Mat mA, Mat mB, double beta, Mat mC) {
  const int n = MatN(mA);
  const void* const a = MatElems(mA);
  const void* const b = MatElems(mB);
  void* const c = MatElems(mC);
  const bool dev = MatDev(mA);

  switch (MatElemSize(mA)) {
  case 4:
    if (dev) {
      float alpha32 = alpha, beta32 = beta;
      cublasSgemm(g_cublasHandle, CUBLAS_OP_N, CUBLAS_OP_N, n, n, n,
                  &alpha32, a, n, b, n, &beta32, c, n);
    } else {
      cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n,
                  n, alpha, a, n, b, n, beta, c, n);
    }
    break;

  case 8:
    if (dev) {
      cublasDgemm(g_cublasHandle, CUBLAS_OP_N, CUBLAS_OP_N, n, n, n,
                  &alpha, a, n, b, n, &beta, c, n);
    } else {
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n,
                  n, alpha, a, n, b, n, beta, c, n);
    }
    break;
  }
}
开发者ID:zauberkraut,项目名称:acmi,代码行数:31,代码来源:linalg.c

示例6: SENNA_nn_temporal_convolution

void SENNA_nn_temporal_convolution(float *output, int output_frame_size,
                                   float *weights, float *biases, float *input,
                                   int input_frame_size, int n_frames,
                                   int k_w) {
#ifdef USE_BLAS
  if (k_w == 1) {
    if (biases) {
      int t;
      for (t = 0; t < n_frames; t++)
        cblas_scopy(output_frame_size, biases, 1,
                    output + t * output_frame_size, 1);
    }
    cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, output_frame_size,
                n_frames, input_frame_size, 1.0, weights, input_frame_size,
                input, input_frame_size, (biases ? 1.0 : 0.0), output,
                output_frame_size);
  } else
#endif
  {
    int t;

    for (t = 0; t < n_frames - k_w + 1; t++)
      SENNA_nn_linear(output + t * output_frame_size, output_frame_size,
                      weights, biases, input + t * input_frame_size,
                      input_frame_size * k_w);
  }
}
开发者ID:Averroes,项目名称:djinn,代码行数:27,代码来源:SENNA_nn.cpp

示例7: ccv_gemm

void ccv_gemm(ccv_matrix_t* a, ccv_matrix_t* b, double alpha, ccv_matrix_t* c, double beta, int transpose, ccv_matrix_t** d, int type)
{
	ccv_dense_matrix_t* da = ccv_get_dense_matrix(a);
	ccv_dense_matrix_t* db = ccv_get_dense_matrix(b);
	ccv_dense_matrix_t* dc = (c == 0) ? 0 : ccv_get_dense_matrix(c);

	assert(CCV_GET_DATA_TYPE(da->type) == CCV_GET_DATA_TYPE(db->type) && CCV_GET_CHANNEL(da->type) == 1 && CCV_GET_CHANNEL(db->type) == 1 && ((transpose & CCV_A_TRANSPOSE) ? da->rows : da->cols) == ((transpose & CCV_B_TRANSPOSE) ? db->cols : db->rows));

	if (dc != 0)
		assert(CCV_GET_DATA_TYPE(dc->type) == CCV_GET_DATA_TYPE(da->type) && CCV_GET_CHANNEL(dc->type) == 1 && ((transpose & CCV_A_TRANSPOSE) ? da->cols : da->rows) == dc->rows && ((transpose & CCV_B_TRANSPOSE) ? db->rows : db->cols) == dc->cols);

	ccv_declare_derived_signature_case(sig, ccv_sign_with_format(20, "ccv_gemm(%d)", transpose), ccv_sign_if(dc == 0 && da->sig != 0 && db->sig != 0, da->sig, db->sig, CCV_EOF_SIGN), ccv_sign_if(dc != 0 && da->sig != 0 && db->sig != 0 && dc->sig != 0, da->sig, db->sig, dc->sig, CCV_EOF_SIGN));
	type = CCV_GET_DATA_TYPE(da->type) | CCV_GET_CHANNEL(da->type);
	ccv_dense_matrix_t* dd = *d = ccv_dense_matrix_renew(*d, (transpose & CCV_A_TRANSPOSE) ? da->cols : da->rows, (transpose & CCV_B_TRANSPOSE) ? db->rows : db->cols, type, type, sig);
	ccv_object_return_if_cached(, dd);

	if (dd != dc && dc != 0)
		memcpy(dd->data.u8, dc->data.u8, dc->step * dc->rows);
	else if (dc == 0) // clean up dd if dc is not provided
		memset(dd->data.u8, 0, dd->step * dd->rows);

#if (defined HAVE_CBLAS || defined HAVE_ACCELERATE_FRAMEWORK)
	switch (CCV_GET_DATA_TYPE(dd->type))
	{
		case CCV_32F:
			cblas_sgemm(CblasRowMajor, (transpose & CCV_A_TRANSPOSE) ? CblasTrans : CblasNoTrans, (transpose & CCV_B_TRANSPOSE) ? CblasTrans : CblasNoTrans, dd->rows, dd->cols, (transpose & CCV_A_TRANSPOSE) ? da->rows : da->cols, alpha, da->data.f32, da->cols, db->data.f32, db->cols, beta, dd->data.f32, dd->cols);
			break;
		case CCV_64F:
			cblas_dgemm(CblasRowMajor, (transpose & CCV_A_TRANSPOSE) ? CblasTrans : CblasNoTrans, (transpose & CCV_B_TRANSPOSE) ? CblasTrans : CblasNoTrans, dd->rows, dd->cols, (transpose & CCV_A_TRANSPOSE) ? da->rows : da->cols, alpha, da->data.f64, da->cols, db->data.f64, db->cols, beta, dd->data.f64, dd->cols);
			break;
	}
#else
	assert(0 && "You need a BLAS compatible library for this function, e.g. libatlas.");
#endif
}
开发者ID:ChenFengAndy,项目名称:klaus,代码行数:35,代码来源:ccv_algebra.c

示例8: row

/***********************************************
Get the inner product of vectors from start row(sr), last rowLength-length
input: the number of subjects, the number of blocks, the start row, the number of voxels of masked matrix one that involved in the computing, the trials information, the first masked data array, the second masked data array
output: the partial similarity matrix based on the selected rows of first matrices and the whole second matrices
************************************************/
float* GetPartialInnerSimMatrixWithMasks(int nSubs, int nTrials, int sr, int rowLength, Trial* trials, RawMatrix** masked_matrices1, RawMatrix** masked_matrices2) // compute the correlation between masked matrices
{
  int i;
  int row1 = masked_matrices1[0]->row;
  int row2 = masked_matrices2[0]->row;  //rows should be the same across subjects since we are using the same mask file to filter out voxels
  float* values= new float[nTrials*rowLength*row2];
  float* simMatrix = new float[nTrials*nTrials];
  memset((void*)simMatrix, 0, nTrials*nTrials*sizeof(float));
  for (i=0; i<nTrials; i++)
  {
    int sc = trials[i].sc;
    int ec = trials[i].ec;
    int sid = trials[i].sid;
    int col = masked_matrices1[sid]->col; // the column of 1 and 2 should be the same, i.e. the number of TRs of a block; columns may be different, since different subjects have different TRs
    float* mat1 = masked_matrices1[sid]->matrix;
    float* mat2 = masked_matrices2[sid]->matrix;
    float* buf1 = new float[row1*col]; // col is more than what really need, just in case
    float* buf2 = new float[row2*col]; // col is more than what really need, just in case
    int ml1 = getBuf(sc, ec, row1, col, mat1, buf1);  // get the normalized matrix, return the length of time points to be computed
    int ml2 = getBuf(sc, ec, row2, col, mat2, buf2);  // get the normalized matrix, return the length of time points to be computed, m1==m2
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, rowLength, row2, ml1, 1.0, buf1+sr*ml1, ml1, buf2, ml2, 0.0, values+i*rowLength*row2, row2);
    delete[] buf1;
    delete[] buf2;
  }
  NormalizeCorrValues(values, nTrials, rowLength, row2, nSubs);
  GetDotProductUsingMatMul(simMatrix, values, nTrials, rowLength, row2);
  delete[] values;
  return simMatrix;
}
开发者ID:Wildcarde,项目名称:fcma-toolbox,代码行数:34,代码来源:SVMPredictorWithMasks.cpp

示例9: GetPartialInnerSimMatrix

// row here is nTops, get the inner product of vectors from start row(sr), last rowLength-length
float* GetPartialInnerSimMatrix(int row, int col, int nSubs, int nTrials, int sr, int rowLength, Trial* trials, RawMatrix** r_matrices) // only compute the correlation among the selected voxels
{
  int i;
  float* values = new float[nTrials*rowLength*row];
  float* simMatrix = new float[nTrials*nTrials];
  for (i=0; i<nTrials*nTrials; i++) simMatrix[i] = 0.0;
  for (i=0; i<nTrials; i++)
  {
    int sc = trials[i].sc;
    int ec = trials[i].ec;
    int sid = trials[i].sid;
    float* mat = r_matrices[sid]->matrix;
    //if (i==0 && sr==0) cout<<mat[1000*col]<<" "<<mat[1000*col+1]<<" "<<mat[1000*col+2]<<" "<<mat[1000*col+3]<<endl;
    //else if (i==0 && sr!=0) cout<<mat[0]<<" "<<mat[1]<<" "<<mat[2]<<" "<<mat[3]<<endl;
    float* buf = new float[row*col]; // col is more than what really need, just in case
    int ml = getBuf(sc, ec, row, col, mat, buf);  // get the normalized matrix, return the length of time points to be computed
    //cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, step, row, ml, 1.0, buf+sr*ml, ml, buf, ml, 0.0, corrs, row);
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, rowLength, row, ml, 1.0, buf+sr*ml, ml, buf, ml, 0.0, values+i*rowLength*row, row);
    delete[] buf;
  }
  NormalizeCorrValues(values, nTrials, rowLength, row, nSubs);
  GetDotProductUsingMatMul(simMatrix, values, nTrials, rowLength, row);
  delete[] values;
  return simMatrix;
}
开发者ID:Wildcarde,项目名称:fcma-toolbox,代码行数:26,代码来源:SVMPredictor.cpp

示例10: main

int
main (int argc, char **argv) {
	// Log messeages into stderr
	FLAGS_logtostderr = 1;
	google::InitGoogleLogging (argv[0]);

	LOG(INFO) << "Begin BLAS Demo";
	std::cout << "  A = [ 0 0 1 ; 0 1 0 ; 1 0 0 ]" << std::endl
		<< "  B = [ 1;2;3 ]" << std::endl;
	int M=3, K=3, N=1;
	float A[M*K] = { 0,0,1, 0,1,0, 1,0,0 };
	float B[K*N] = { 1,2,3 };
	float C[M*N];

	// Do matrix multiplication
	LOG(INFO) << "Calculating  C := 1.0 A * B + 0.0 C ";
	cblas_sgemm (CblasRowMajor, CblasNoTrans, CblasNoTrans, M, N, K,
		1.0, A, K, B, N, 0.0, C, N);

	// Dump matrix	
	LOG(INFO) << "Dumping matrix C";
	std::cout << "C = [" << std::endl;
	for (int i = 1; i <= M; i++) {
		std::cout << "\t";
		for (int j = 1; j <= N; j++) {
			std::cout << C[i*j-1] << " ";
		}
		std::cout << std::endl;
	}
	std::cout << "];" << std::endl;

	LOG(INFO) << "Demo done.";
	return 0;
}
开发者ID:2511674586,项目名称:withLinux,代码行数:34,代码来源:blas.cpp

示例11: gemm

inline void gemm( const Order order, const TransA transa, const TransB transb,
        const int m, const int n, const int k, const float alpha,
        const float* a, const int lda, const float* b, const int ldb,
        const float beta, float* c, const int ldc ) {
    cblas_sgemm( cblas_option< Order >::value, cblas_option< TransA >::value,
            cblas_option< TransB >::value, m, n, k, alpha, a, lda, b, ldb,
            beta, c, ldc );
}
开发者ID:CQMP,项目名称:scripts,代码行数:8,代码来源:gemm.hpp

示例12: gemm

void gemm(bool transa, bool transb, int m, int n, int k, float alpha, const float* A, int lda,
    const float* B, int ldb, float beta, float* C, int ldc)
{
  const CBLAS_TRANSPOSE ctransa = transa ? CblasTrans : CblasNoTrans;
  const CBLAS_TRANSPOSE ctransb = transb ? CblasTrans : CblasNoTrans;

  cblas_sgemm(CblasColMajor, ctransa, ctransb, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
}
开发者ID:e-thereal,项目名称:capputils,代码行数:8,代码来源:prod.cpp

示例13: cblas_sgemm

void caffe_cpu_gemm<float>(const CBLAS_TRANSPOSE TransA,
                           const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,
                           const float alpha, const float* A, const float* B, const float beta,
                           float* C) {
    int lda = (TransA == CblasNoTrans) ? K : M;
    int ldb = (TransB == CblasNoTrans) ? N : K;
    cblas_sgemm(CblasRowMajor, TransA, TransB, M, N, K, alpha, A, lda, B,
                ldb, beta, C, N);
}
开发者ID:flair2005,项目名称:mmd-caffe,代码行数:9,代码来源:math_functions.cpp

示例14: STARPU_SGEMM

inline void STARPU_SGEMM(char *transa, char *transb, int M, int N, int K, 
			float alpha, const float *A, int lda, const float *B, int ldb, 
			float beta, float *C, int ldc)
{
	enum CBLAS_TRANSPOSE ta = (toupper(transa[0]) == 'N')?CblasNoTrans:CblasTrans;
	enum CBLAS_TRANSPOSE tb = (toupper(transb[0]) == 'N')?CblasNoTrans:CblasTrans;

	cblas_sgemm(CblasColMajor, ta, tb,
			M, N, K, alpha, A, lda, B, ldb, beta, C, ldc);				
}
开发者ID:excess-project,项目名称:starpu-energy-aware-extension,代码行数:10,代码来源:blas.c

示例15: LOG

void caffe_cpu_gemm<float>(const CBLAS_TRANSPOSE TransA,
    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,
    const float alpha, const float* A, const float* B, const float beta,
    float* C) {
  int lda = (TransA == CblasNoTrans) ? K : M;
  int ldb = (TransB == CblasNoTrans) ? N : K;
#if 0
  LOG(INFO)<<"\t\t----> XEON: M="<< M <<" N="<< N <<" K="<< K;
#endif
  cblas_sgemm(CblasRowMajor, TransA, TransB, M, N, K, alpha, A, lda, B,
      ldb, beta, C, N);
}
开发者ID:codeaudit,项目名称:Xeon-CafPhi,代码行数:12,代码来源:math_functions.cpp


注:本文中的cblas_sgemm函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。