memcpy

cudamemcpyasync, memcpy fails to copy inside kernel while direct copying works

痴心易碎 提交于 2019-12-02 22:33:40
问题 I am trying to copy from a source float array(containing 1.0f) to a destination float array(containing 2.0f) inside a cuda kernel. I try three different ways using: cudamemcpysync memcpy direct copy (dst[i] = src[i]) When i read the results after the kernel has been executed I found that both cudamemcpyasync and memcpy has failed to copy while the direct copy method has worked. Why has the cudamemcpyasync and memcpy method failed? I am using GTX TitanX(SM_52). compiled using: nvcc -arch

linux编程必备函数

匿名 (未验证) 提交于 2019-12-02 21:59:42
1.memcpy 原型:void *memcpy(void*dest, const void *src, size_t n); (1)memcpy用来做内存拷贝,你可以拿它拷贝任何数据类型的对象,可以指定拷贝的数据长度; (2)将s中第14个字符开始的4个连续字符复制到d中。(从0开始) char * s="Golden Global View";   char d[20]; memcpy(d,s+14,4);//从第14个字符(V)开始复制,连续复制4个字符(View) (3)如果目标数组destin本身已有数据,执行memcpy()后,将覆盖原有数据(最多覆盖n)。如果要追加数据,则每次执行memcpy后,要将目标数组地址增加到你要追加数据的地址。 2. fopen 函数原型:FILE * fopen(const char * path, const char * mode); (1)返回值:文件顺利打开后,指向该流的文件指针就会被返回。如果文件打开失败则返回 NULL,并把错误代码存在error中。 (2)一般而言,打开文件后会做一些文件读取或写入的动作,若打开文件失败,接下来的读写动作也无法顺利进行,所以一般在 fopen() 后作错误判断及处理。 (3)参数说明:参数 path字符串包含欲打开的文件路径及文件名,参数 mode 字符串则代表着流形态。 (4)举例

memcpy with startIndex?

时光毁灭记忆、已成空白 提交于 2019-12-02 20:10:15
I wish to copy content of specific length from one buffer to another from a specific starting point. I checked memcpy() but it takes only the length of content to be copied while I want to specify the starting index too. Is there any function which can do this or is there any good approach to do it with the existing memcpy function? Goz I always prefer the syntax memcpy( &dst[dstIdx], &src[srcIdx], numElementsToCopy * sizeof( Element ) ); Just add the offset you want to the address of the buffer. char abuff[100], bbuff[100]; .... memcpy( bbuff, abuff + 5, 10 ); This copies 10 bytes starting at

Poor memcpy Performance on Linux

只谈情不闲聊 提交于 2019-12-02 15:42:29
We have recently purchased some new servers and are experiencing poor memcpy performance. The memcpy performance is 3x slower on the servers compared to our laptops. Server Specs Chassis and Mobo: SUPER MICRO 1027GR-TRF CPU: 2x Intel Xeon E5-2680 @ 2.70 Ghz Memory: 8x 16GB DDR3 1600MHz Edit: I am also testing on another server with slightly higher specs and seeing the same results as the above server Server 2 Specs Chassis and Mobo: SUPER MICRO 10227GR-TRFT CPU: 2x Intel Xeon E5-2650 v2 @ 2.6 Ghz Memory: 8x 16GB DDR3 1866MHz Laptop Specs Chassis: Lenovo W530 CPU: 1x Intel Core i7 i7-3720QM @ 2

Problem when copying memory

戏子无情 提交于 2019-12-02 14:23:39
So there is a problem I am headbanging over two nights in a row: (tuple1 and tuple2 are void pointers passed to this function) char *data; data = (char*) calloc (76, 1); memcpy(data, tuple1, 32); memcpy(data+32, tuple2, 44); The idea is to allocate memory equal to the sum of the sizes of tuple1 and tuple2 ( tuple1 is 32 bytes and tuple2 is 44) and then copy the 32 bytes of tuple1 and paste them at the address of data and after that copy the 44 bytes of tuple2 and paste them 32 bytes after the address of data. The thing is if I copy only tuple1 or only tuple2 it is really copied where it is

C : Insert/get element in/from void array

烈酒焚心 提交于 2019-12-02 13:17:53
I have to create a generic array that can contain generic data structures. How can i put a generic structure into an empty slot of my void array? This is my code. struct CircularBuffer { int E; int S; int length; // total number of item allowable in the buffer int sizeOfType; // size of each element in the buffer void *buffer; }; struct CircularBuffer* circularBufferInit(int length, int sizeOfType) { struct CircularBuffer *cb = malloc(sizeof(struct CircularBuffer)); cb->E = 0; cb->S = 0; cb->length = length; cb->sizeOfType = sizeOfType; cb->buffer = malloc(sizeOfType *length); return cb; } int

Cuda object copy

一世执手 提交于 2019-12-02 11:46:28
I'm trying to use CUDA with objects, this is a little test code i put together to try out things, but i ran into a problem. When i'm doing anything to the device version of the variable, the copy back to the host fails with "cuda Error Ilegal Address", but if i just copy the code to the device and back it works. If i comment out the printf... line, it the works. class A { public: int s; }; __device__ A *d_a; __global__ void MethodA() { printf("%d\n", d_a->s); } int main() { A *a = new A(); a->s = 10; cudaError e; e = cudaMalloc((void**)&d_a, sizeof(A)); e = cudaMemcpy(d_a, a, sizeof(A),

Getting segmentation fault SIGSEGV in memcpy after mmap

扶醉桌前 提交于 2019-12-02 08:26:54
问题 I wrote a simple Android native function that get a filename and some more arguments and read the file by mmapping (mmap) it's memory. Because it's mmap, I don't really need to call "read()" so I just memcpy() from the address returned from the mmap(). But, somewhere I'm getting a SIGSEGV probably because I'm trying to access a memory which I not permitted. But I don't understand why, I already asked all file's memory to be mapped! I'm attaching my code and the error I got: EDIT I fixed the

memcpy error : Segmentation fault (core dumped)

时光毁灭记忆、已成空白 提交于 2019-12-02 06:45:59
问题 I'm trying to copy one string to another in c using memcpy with the following code: #include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct fullName { char* firstName; char* lastName; } NAME; int main() { NAME myName, hisName; myName.firstName = "aaaaaaa"; hisName.firstName = "bbbbbb"; memcpy(myName.firstName, hisName.firstName, sizeof(hisName.firstName)); printf("myName.firstName = %s\n", myName.firstName); printf("hisName.firstName = %s\n", hisName.firstName); } and it

memcpy and then printf, calling stat(), writing in buffer;

落花浮王杯 提交于 2019-12-02 06:06:18
问题 here are includes and my function: I'm trying to copy stbuf->st_mode in buffer with memcpy and when reading it back, value is not what I was trying to copy. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/stat.h> #include <string.h> void r1_getattr(char* pth, int cfd){ struct stat* stbuf = malloc(sizeof(stat)); int res = stat(pth, stbuf); printf("(%3o)\n", (stbuf->st_mode)&0777); char* wbuf = malloc(256); memcpy(wbuf, &(stbuf->st_mode), sizeof(mode_t)); printf("(%3o)