cublasSscal 
//Example 1. Application Using C and CUBLAS: 1-based indexing

#include <stdlib.h>
#include <math.h>
#include <cuda_runtime.h>
#include "cublas_v2.h"
#include <stdio.h>
#define M 6
#define N 5
#define IDX2F(i,j,ld) ((((j)-1)*(ld))+((i)-1))
static __inline__ void modify (cublasHandle_t handle, float*m, int ldm, int
n, int p, int q, float alpha, float beta){
cublasSscal (handle, n-p+, &alpha, &m[IDX2F(p,q,ldm)], ldm);
cublasSscal (handle, ldm-p+, &beta, &m[IDX2F(p,q,ldm)], );
}
int main (void){
cudaError_t cudaStat;
cublasStatus_t stat;
cublasHandle_t handle;
int i, j;
float* devPtrA;
float* a = ;
a = (float*)malloc (M * N * sizeof(*a));
if(!a) {
printf("host memory allocation failed");
return EXIT_FAILURE;
}
for(j = ; j <= N; j++) {
for(i = ; i <= M; i++) {
a[IDX2F(i,j,M)] = (float)((i-) * M + j);
printf("%7.0f",a[IDX2F(i,j,M)]);
}printf("\n");
}printf("\n");
cudaStat = cudaMalloc ((void**)&devPtrA, M*N*sizeof(*a));
if(cudaStat != cudaSuccess) {
printf ("device memory allocation failed");
return EXIT_FAILURE;
}
stat = cublasCreate(&handle);
if(stat != CUBLAS_STATUS_SUCCESS) {
printf ("CUBLAS initialization failed\n");
return EXIT_FAILURE;
}
stat = cublasSetMatrix (M, N, sizeof(*a), a, M, devPtrA, M);
if(stat != CUBLAS_STATUS_SUCCESS) {
printf ("data download failed");
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
modify (handle, devPtrA, M, N, , , 16.0f, 12.0f);
stat = cublasGetMatrix (M, N, sizeof(*a), devPtrA, M, a, M);
if(stat != CUBLAS_STATUS_SUCCESS) {
printf("data upload failed");
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
cudaFree (devPtrA);
cublasDestroy(handle);
for(j = ; j <= N; j++) {
for(i = ; i <= M; i++) {
printf ("%7.0f", a[IDX2F(i,j,M)]);
}
printf ("\n");
}
free(a);
return EXIT_SUCCESS;
}

cubla sample-code的更多相关文章

  1. android studio2.2 的Find Sample Code点击没有反应

    1 . 出现的问题描述:           右键点击Find Sample Code后半天没有反应,然后提示 Samples are currently unavailable for :{**** ...

  2. 如何将经纬度利用Google Map API显示C# VS2005 Sample Code

    原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上 ...

  3. IOS开发苹果官方Sample Code及下载地址

    IOS开发苹果官方Sample Code及下载地址 在线浏览地址:https://developer.apple.com/library/ios/navigation/#section=Resourc ...

  4. OAF Sample Code(转)

    原文地址: OAF Sample Code

  5. Sample Code之Web scene-slides

    这是我的第一篇随笔,在开始正文前说几句. 这个系列会记录我学习Arcgis js API 4.10的全过程,希望能对自己也对其他有需要的人有帮助.很多时候上网看一些大神的帖子会感到一头雾水,一是自己水 ...

  6. sample code java pom.xml

    pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  7. sqoop sample code

    本文使用的数据库是mysql的sample database employees. download url:https://launchpad.net/test-db/employees-db-1/ ...

  8. Sample Code for Qp_preq_pub.Price_request Api to Simulate an Ask for Promotion Modifier

    DECLARE p_line_tbl QP_PREQ_GRP.LINE_TBL_TYPE; p_qual_tbl QP_PREQ_GRP.QUAL_TBL_TYPE; p_line_attr_tbl ...

  9. 虹软人脸识别Android Sample Code

    AFR_FSDKInterface engine = new AFR_FSDKEngine(); //用来存放提取到的人脸信息, face_1 是注册的人脸,face_2 是要识别的人脸 AFR_FS ...

  10. Apache Flink Training and sample code

    http://training.data-artisans.com/ https://github.com/dataArtisans/blog-post-code-samples https://gi ...

随机推荐

  1. zoj 3777

    状态压缩dp #include<cstdio> #include<cstring> #include<algorithm> #define maxn 4100 us ...

  2. Interface Serializable

    public interface Serializable Serializability of a class is enabled by the class implementing the ja ...

  3. Tornado,了解一下

    多了解不一样的PYTHON框架,对深入了解DJANGO,总是有帮助的. import textwrap import tornado.httpserver import tornado.ioloop ...

  4. [java]2015上海邀请赛 B Base64

    题意: 给n和一个字符串(可以有空格) 求字符串编码n次后的字符串 编码方式:字符串的每个字符转化成ASCII码, ASCII码转化成8位2进制,    将二进制数分割成6位为一组的(不够的补0), ...

  5. [itint5]支持删除的后继查询

    http://www.itint5.com/oj/#49 这一题一开始想到是用HashSet+链表来做,链表记录prev和next.这样也可以,后来看到都是连续的整数,而且交流了一下觉得可以用类似并查 ...

  6. ecos内核概览--bakayi译

    http://blog.csdn.net/wangzaiwei2006/article/details/6453423

  7. *J2EE中乱码处理

    发生中文乱码有三种情况 表单form (1)post 首先确定浏览器的编码方式,比如说utf-8,请求发给web服务器,web服务器以编码方式iso-9959-1来接收数据(服务器是外国人编写的),服 ...

  8. oracle connect by 和start with

    网上找了个例子 测试了一下 貌似明白了create table t2(root_id number,id number,name varchar(5),description varchar(10)) ...

  9. MySQL高效分页解决方案集

    一,最常见MYSQL最基本的分页方式: select * from content order by id desc limit 0, 10 在中小数据量的情况下,这样的SQL足够用了,唯一需要注意的 ...

  10. int21 h

    表:DOS系统功能调INT 21H AH 功能 调用参数 返回参数 00 程序终止(同INT 20H) CS=程序段前缀 01 键盘输入并回显 AL=输入字符 02 显示输出 DL=输出字符 03 异 ...