Skip to content

Instantly share code, notes, and snippets.

View DavidPoliakoff's full-sized avatar

David Poliakoff DavidPoliakoff

  • Google
  • Washington
View GitHub Profile
@DavidPoliakoff
DavidPoliakoff / kokkos.cpp
Created November 2, 2021 15:54
But why Kokkos Models?
#pragma omp parallel for
for(int i=0;i<lots;++i){
// insert psychics here
}
__global__ void cuda(){
int thread = threadIdx.x +
blockdim.x * blockIdx.x;
if(thread < lots){
// insert psychics here
@DavidPoliakoff
DavidPoliakoff / ToolLayer.cpp
Last active October 5, 2021 21:11
Writing the Tool Layer
function_pointer_that_takes_a_string begin_parallel_for_ptr;
function_pointer_that_takes_a_string end_parallel_for_ptr;
void initialize(std::string toolLibrary) {
void* handle = dlopen(toolLibrary);
begin_parallel_for_ptr = dlsym(handle, "kokkosp_begin_parallel_for");
end_parallel_for_ptr = dlsym(handle, "kokkosp_end_parallel_for");
}
void parallel_for(std::string label, boring_parallelism_stuff stuff) {
if(begin_parallel_for_ptr){
fence_kokkos(); // this is a _small_ lie
@DavidPoliakoff
DavidPoliakoff / test.cpp
Created March 12, 2021 19:41
Kokkos Tool
extern "C" void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, uint64_t* kID){
if(name matches a regex){
jonathans_api_wrapper_start();
*kID = 1;
}
}
extern "C" void kokkosp_end_parallel_for(uint64_t kID){
if(kID==1){
jonathans_api_wrapper_stop();
}
Kokkos::TeamPolicy<Kokkos::Cuda> execution_policy(total_amount_of_work,
outer_parallelism_batch_size,
inner_parallelism_batch_size);
Kokkos::parallel_for("implement_psychics", execution_policy,
KOKKOS_LAMBDA (team_member outer_handle) {
// some outer level work
double sum = psychics;
parallel_reduce (ThreadVectorRange (outer_handle, loop_count),
[=] (int& i, Scalar& lsum) {
@DavidPoliakoff
DavidPoliakoff / cool_tool.cpp
Last active November 16, 2018 12:54
MPI Wrapping
int MPI_Send( /* Args */ ){
// typical MPI code
}
struct gotcha_binding_t mpi_wrappers[] = {
{ "MPI_Init", mpi_init_wrapper, &orig_mpi_init_handle },
// other wrappers as desired
};
static int mpi_init_wrapper(int* argc, char*** argv )
{
typeof(&puts) orig_init = gotcha_get_wrappee(orig_mpi_init_handle);
/** do tool_things */
return orig_init(str);
@DavidPoliakoff
DavidPoliakoff / .cpp
Last active November 8, 2018 19:01
MPI Wrapping
int MPI_Send(const void *buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm){
// MPI Things
}
bash-4.2$ ./autogen.sh
Running autoreconf -i ...
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
libtoolize: copying file `config/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
ssize_t (*orig_read)(int fildes, void *buf, size_t nbyte);
ssize_t read_wrapper(int fildes, void* buf, size_t nbyte){
TAU_REGISTER_CONTEXT_EVENT(event, "Bytes read");
TAU_CONTEXT_EVENT(event, nbyte);
return orig_read(fildes, buf, nbyte);
}
struct gotcha_binding_t wrap_actions[] = {
{ "read", read_wrapper, &orig_read }
};