# Global memory

Large - depends on card ie:&#x20;

* C1060 - 4GB
* C2050 - 3GB
* C2070 - 6GB

Has long latency: \~200 cycles

Can only be allocated/freed by host

Main way host can pass data to/from device/

Allocate, copy, free:

```c
//allocate
cudaError_t cudaMalloc(void **devPtr,size_t size);

//copy
cudaError_t cudaMemcpy(void *dst, const void *src,size_t count, enum cudaMemcpyKind kind);
//kind: type of copy: H->D, D->H, D->H, D->D

//setting data on device
cudaError_t cudaMemset(void *devPtr,int value, size_t count);

cudaError_t cudaFree(void *devPtr);
```

\
Global memory has long latency, there are others:

* shared memory
* constant
* registers

![Memory types](https://3718412349-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcLzF9dv8k9-Sb-ui-A%2F-MLSet3BOkCj_5OijN97%2F-MLSexVSbYjE-muTobqS%2Fmem_types.jpeg?alt=media\&token=5be0b05e-039a-4bb9-ab0c-e4e6622267fe)
