Performance: Making things go faster
Measure twice, optimize once
How do we measure?
- Java
- jvisualvm
- Can't be using docker!
- Python
nvcc -arch sm_61 -O3 -L/usr/local/lib -lboost_python -I/usr/include/python2.7/ -Xcompiler -fPIC --shared test_python.cu -o test_python.so |
'''More efficient dense layers for DenseNets. | |
author: James Gilles.''' | |
import torch | |
from torch import nn, autograd | |
class RepeatedConcat(nn.Module): | |
'''Hack for faster DenseNets. | |
Allocates O(n) memory for n concatenated layers, | |
instead of O(n^2). |
import battlecode as bc | |
import random | |
import sys | |
import traceback | |
print("pystarting") | |
# A GameController is the main type that you talk to the game with. | |
# Its constructor will connect to a running game. | |
gc = bc.GameController() |
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <bc.h> | |
/// See bc.h at xxx for the API you have access too. | |
/// Note: the API is not thread safe; don't use pthreads. |
/// GENERATED C, DO NOT EDIT | |
#ifndef bc_h_ | |
#define bc_h_ | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
#include <stdint.h> | |
uint8_t bc_has_err(); | |
int8_t bc_get_last_err(char** result); |
Performance: Making things go faster
Measure twice, optimize once
How do we measure?
Assuming you're running in Docker, this means you're running out of memory.
An initial fix you should apply is to put -Xmx40m
in your player/run.sh
; see the examplefuncsplayer-java/run.sh
from the current scaffold for how this should work.
Depending on how your code works, this may fix the problem. However, in some cases you may need to tune the number to be lower (for example, -Xmx10m
).
Note that you should NOT set -Xmx256m
or -Xmx512m
; if you're curious, see the next section of this document for why setting the number so low is necessary.
In the game running interface, you can also set Player memory limit (in mb)
to 512
instead of 256
. In the next release we will set this to be the default, and raise the memory limit in the scrimmage servers. This should give you a little more breathing room. We'll also be tuning the engine to use less memory, c
use specs::System; | |
// Tired of writing out a bunch of giant tuples by hand? | |
// I have the macro for you! | |
struct BananaSystem; | |
system! { | |
BananaSystem; |