Skip to content

Commit

Permalink
recommit the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinpei Kato committed Nov 10, 2011
0 parents commit 479e9e7
Show file tree
Hide file tree
Showing 189 changed files with 74,473 additions and 0 deletions.
62 changes: 62 additions & 0 deletions common/gdev_api.h
@@ -0,0 +1,62 @@
/*
* Copyright 2011 Shinpei Kato
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __GDEV_API_H__
#define __GDEV_API_H__

#ifdef __KERNEL__
#include "gdev_drv.h"
#else
#include "gdev_lib.h"
#endif
#include "gdev_nvidia_def.h"
/* add also:
* #include "gdev_amd_def.h"
* #include "gdev_intel_def.h"
*/

/**
* Gdev APIs:
*/
extern gdev_handle_t *gopen(int);
extern int gclose(gdev_handle_t*);
extern uint64_t gmalloc(gdev_handle_t*, uint64_t);
extern void gfree(gdev_handle_t*, uint64_t);
extern int gmemcpy_from_device(gdev_handle_t*, void*, uint64_t, uint64_t);
extern int gmemcpy_user_from_device(gdev_handle_t*, void*, uint64_t, uint64_t);
extern int gmemcpy_to_device(gdev_handle_t*, uint64_t, void*, uint64_t);
extern int gmemcpy_user_to_device(gdev_handle_t*, uint64_t, void*, uint64_t);
extern int gmemcpy_in_device(gdev_handle_t*, uint64_t, uint64_t, uint64_t);
extern int glaunch(gdev_handle_t*, struct gdev_kernel*, uint32_t*);
extern void gsync(gdev_handle_t*, uint32_t);
extern int gquery(gdev_handle_t*, uint32_t, uint32_t*);
extern int gtune(gdev_handle_t*, uint32_t, uint32_t);

/**
* tuning types for Gdev resource management parameters.
*/
#define GDEV_TUNE_MEMCPY_PIPELINE_COUNT 1
#define GDEV_TUNE_MEMCPY_CHUNK_SIZE 2

#endif
45 changes: 45 additions & 0 deletions common/gdev_conf.h
@@ -0,0 +1,45 @@
/*
* Copyright 2011 Shinpei Kato
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __GDEV_CONF_H__
#define __GDEV_CONF_H__

#include "gdev_nvidia.h"
// #include "gdev_amd.h"
// #include "gdev_intel.h"

#define GDEV_PIPELINE_MAX_COUNT 8
#define GDEV_PIPELINE_MIN_COUNT 1
#define GDEV_PIPELINE_DEFAULT_COUNT 1

#define GDEV_CHUNK_MAX_SIZE 0x2000000 /* 32MB */
#define GDEV_CHUNK_DEFAULT_SIZE 0x100000 /* 1MB */

/* define this if you want to allocate a new bounce buffer every time
you copy data to/from device memory. */
//#define GDEV_NO_STATIC_BOUNCE_BUFFER

#define GDEV_DEBUG_PRINT 0

#endif
69 changes: 69 additions & 0 deletions common/gdev_ioctl_def.h
@@ -0,0 +1,69 @@
/*
* Copyright 2011 Shinpei Kato
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __GDEV_IOCTL_DEF_H__
#define __GDEV_IOCTL_DEF_H__

/**
* user-space ioctl commands:
*/
#define GDEV_IOCTL_GMALLOC 0x100
#define GDEV_IOCTL_GFREE 0x101
#define GDEV_IOCTL_GMEMCPY_FROM_DEVICE 0x102
#define GDEV_IOCTL_GMEMCPY_TO_DEVICE 0x103
#define GDEV_IOCTL_GMEMCPY_IN_DEVICE 0x104
#define GDEV_IOCTL_GLAUNCH 0x105
#define GDEV_IOCTL_GSYNC 0x106
#define GDEV_IOCTL_GQUERY 0x107
#define GDEV_IOCTL_GTUNE 0x108

typedef struct gdev_ioctl_mem {
uint64_t addr;
uint64_t size;
} gdev_ioctl_mem_t;

typedef struct gdev_ioctl_dma {
void *src_buf;
void *dst_buf;
uint64_t src_addr;
uint64_t dst_addr;
uint64_t size;
} gdev_ioctl_dma_t;

typedef struct gdev_ioctl_launch {
struct gdev_kernel *kernel;
uint32_t *id;
} gdev_ioctl_launch_t;

typedef struct gdev_ioctl_query {
uint32_t type;
uint32_t result;
} gdev_ioctl_query_t;

typedef struct gdev_ioctl_tune {
uint32_t type;
uint32_t value;
} gdev_ioctl_tune_t;

#endif
131 changes: 131 additions & 0 deletions common/gdev_nvidia.c
@@ -0,0 +1,131 @@
/*
* Copyright 2011 Shinpei Kato
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "gdev_nvidia.h"

/* add the device memory object to the memory list. */
void gdev_heap_add(gdev_mem_t *mem)
{
gdev_vas_t *vas = mem->vas;

__gdev_list_add(&mem->list_entry, &vas->memlist);
}

/* delete the device memory object from the memory list. */
void gdev_heap_del(gdev_mem_t *mem)
{
__gdev_list_del(&mem->list_entry);
}

/* look up the memory object allocated at the specified address. */
gdev_mem_t *gdev_heap_lookup(gdev_vas_t *vas, uint64_t addr)
{
gdev_mem_t *mem;
gdev_list_t *entry = vas->memlist.next;

while (entry) {
mem = (gdev_mem_t *)entry->container;
if (mem && mem->addr == addr)
return mem;
entry = entry->next;
}

return NULL;
}

/* copy data of @size from @src_addr to @dst_addr. */
uint32_t gdev_memcpy
(gdev_ctx_t *ctx, uint64_t dst_addr, uint64_t src_addr, uint32_t size)
{
gdev_vas_t *vas = ctx->vas;
gdev_device_t *gdev = vas->gdev;
struct gdev_compute *compute = gdev->compute;
uint32_t sequence = ++ctx->fence.sequence[GDEV_FENCE_DMA];

/* it's important to emit a fence *before* memcpy():
the EXEC method of the PCOPY and M2MF engines is associated with
the QUERY method, i.e., if QUERY is set, the sequence will be
written to the specified address when the data are transfered. */
compute->fence_write(ctx, GDEV_FENCE_DMA, sequence);
compute->memcpy(ctx, dst_addr, src_addr, size);

return sequence;
}

/* launch the kernel onto the GPU. */
uint32_t gdev_launch(gdev_ctx_t *ctx, struct gdev_kernel *kern)
{
gdev_vas_t *vas = ctx->vas;
gdev_device_t *gdev = vas->gdev;
struct gdev_compute *compute = gdev->compute;
uint32_t sequence = ++ctx->fence.sequence[GDEV_FENCE_COMPUTE];

/* it's important to emit a fence *after* launch():
the LAUNCH method of the PGRAPH engine is not associated with
the QUERY method, i.e., we have to submit the QUERY method
explicitly after the kernel is launched. */
compute->launch(ctx, kern);
compute->fence_write(ctx, GDEV_FENCE_COMPUTE, sequence);

return sequence;
}

/* barrier memory access. */
void gdev_mb(gdev_ctx_t *ctx)
{
gdev_vas_t *vas = ctx->vas;
gdev_device_t *gdev = vas->gdev;
struct gdev_compute *compute = gdev->compute;

compute->membar(ctx);
}

/* poll until the resource becomes available. */
void gdev_poll(gdev_ctx_t *ctx, int type, uint32_t sequence)
{
gdev_vas_t *vas = ctx->vas;
gdev_device_t *gdev = vas->gdev;
struct gdev_compute *compute = gdev->compute;
uint32_t poll_times = 0;
uint32_t val;

compute->fence_read(ctx, type, &val);

while (val < sequence || val > sequence + GDEV_FENCE_LIMIT) {
/* relax the polling after some time. */
if (poll_times > 0x80000000) {
SCHED_YIELD();
}
else if (poll_times == 0xffffffff) {
poll_times = 0;
}
poll_times++;
compute->fence_read(ctx, type, &val);
}

/* sequence rolls back to zero, if necessary. */
if (ctx->fence.sequence[type] == GDEV_FENCE_LIMIT) {
ctx->fence.sequence[type] = 0;
}
}

0 comments on commit 479e9e7

Please sign in to comment.