use structure

I have such structure:

typedef struct
size_t *items;
size_t count;
} Type_t;

Can I do this:

Type_t *d_set;

cudaMalloc((void**)&d_set, sizeof(sizeof(Type_t)));
cudaMalloc((void**)&d_set->items, sizeof(size_t)*1024)));

Type_t d_set;
*)&d_set, sizeof(sizeof(Type_t)));

size_t items;
*)&items, sizeof(size_t)*1024)));

d_set->items = items;

No you can’t.
cudaMalloc() allocates memory on the device, but the pointer passed as first parameter must point to host memory.

And the second method won’t work since you cannot manipulate device memory from the CPU just like that.

…but you could keep two copies of your struct, one on the host and the second on the device:

Type_t *h_set, *d_set;

h_set = malloc(sizeof(Type_t));

cudaMalloc((void**)&d_set, sizeof(Type_t));

cudaMalloc((void**)&h_set->items, sizeof(size_t)*1024)));

h_set->count = 1024;

cudaMemcpy( d_set, h_set, sizeof(Type_t), cudaMemcpyHostToDevice );

Using another call to cudaMemcpy(), you can then fill d_set->items with data. Note however that “items” in both structs points to device mem, and you will need another pointer for the data in host mem.

cudaMemcpy( h_set->items, items, sizeof(size_t)*1024, cudaMemcpyHostToDevice );

Also note that pointers in CUDA, even to device memory, take a whopping 64 bits (I’d be happy even with a 4GB card :) so if you’re in any way making an array of these I suggest using offsets instead.