Skip to content

Instantly share code, notes, and snippets.

View kazimuth's full-sized avatar
🕷️
numbers aren't real

james gilles kazimuth

🕷️
numbers aren't real
  • Detroit, MI
View GitHub Profile
@kazimuth
kazimuth / compile.sh
Created April 4, 2017 14:41
dumb cuda + Boost::Python example
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kazimuth
kazimuth / densenet.py
Last active December 23, 2017 03:18
More Efficient Dense Layers
'''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.
@kazimuth
kazimuth / bc.h
Created January 10, 2018 01:16
Battlecode C API
/// 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?

  • Java
    • jvisualvm
    • Can't be using docker!
  • Python
@kazimuth
kazimuth / battlecode-oom.md
Last active January 23, 2018 21:35
Battlecode OOM Fix

Why is my Battlecode Java player saying "Killed"?

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

@kazimuth
kazimuth / system_macro.rs
Last active May 22, 2018 08:51
System impl macro for specs
use specs::System;
// Tired of writing out a bunch of giant tuples by hand?
// I have the macro for you!
struct BananaSystem;
system! {
BananaSystem;