Skip to content

Commit

Permalink
Add user preference for GPU heap size limit
Browse files Browse the repository at this point in the history
Should be set automatically according to memory needs, see #82
  • Loading branch information
denisalevi committed Jan 7, 2018
1 parent fcb5b75 commit 7ac262c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion brian2cuda/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
''',
),

gpu_heap_size = BrianPreference(
docs='''
Size of the heap (in MB) used by malloc() and free() device system calls, which
are used in the `cudaVector` implementation. `cudaVectors` are used to
dynamically allocate device memory for `Spikemonitors` and the synapse
queues in the `CudaSpikeQueue` implementation for networks with
heterogeneously distributed delays.
''',
validator=lambda v: isinstance(v, int) and v >= 0,
default=128),

curand_float_type=BrianPreference(
docs='''
Floating point type of generated random numbers (float/double).
Expand Down Expand Up @@ -373,7 +384,8 @@ def generate_main_source(self, writer, main_includes):
code_objects=self.code_objects.values(),
report_func=self.report_func,
dt=float(defaultclock.dt),
additional_headers=main_includes
additional_headers=main_includes,
gpu_heap_size=prefs['devices.cuda_standalone.gpu_heap_size']
)
writer.write('main.cu', main_tmp)

Expand Down
2 changes: 1 addition & 1 deletion brian2cuda/templates/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char **argv)

cudaDeviceProp props;
cudaGetDeviceProperties(&props, 0);
size_t limit = 128 * 1024 * 1024;
size_t limit = {{gpu_heap_size}} * 1024 * 1024;
cudaDeviceSetLimit(cudaLimitMallocHeapSize, limit);
cudaDeviceSynchronize();

Expand Down

0 comments on commit 7ac262c

Please sign in to comment.