OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /qaz_libs/trunk/BFM/sim/tests
    from Rev 34 to Rev 43
    Reverse comparison

Rev 34 → Rev 43

/tb_video_frame_dpi/dpi_video_array.py
0,0 → 1,48
#
# ////////////////////////////////////////////////////////////////////
# // Copyright (C) 2018 Authors and OPENCORES.ORG ////
# // ////
# // This source file may be used and distributed without ////
# // restriction provided that this copyright statement is not ////
# // removed from the file and that any derivative work contains ////
# // the original copyright notice and the associated disclaimer. ////
# // ////
# // This source file is free software; you can redistribute it ////
# // and/or modify it under the terms of the GNU Lesser General ////
# // Public License as published by the Free Software Foundation; ////
# // either version 2.1 of the License, or (at your option) any ////
# // later version. ////
# // ////
# // This source is distributed in the hope that it will be ////
# // useful, but WITHOUT ANY WARRANTY; without even the implied ////
# // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
# // PURPOSE. See the GNU Lesser General Public License for more ////
# // details. ////
# // ////
# // You should have received a copy of the GNU Lesser General ////
# // Public License along with this source; if not, download it ////
# // from http://www.opencores.org/lgpl.shtml ////
# ////////////////////////////////////////////////////////////////////
import numpy as np
import py_to_video_frame as vf
 
# -----------------------------------------------------
class dpi_video_array:
 
def __init__(self, width, height):
self.width = width
self.height = height
print('~~~ | dpi_video_array __init__ | ' + str(width) + 'x' + str(height))
 
def py_get_array(self):
print('~~~ | dpi_video_array | py_get_array() | ')
size = self.width * self.height
x = np.arange(0, size, dtype=np.uint32)
vf.np_to_frame(x)
 
def make_counting_raw_video_file(self):
print('~~~ | dpi_video_array | make_counting_raw_video_file() | ')
 
def do_it(self):
print('~~~ | dpi_video_array | do_it() | ')
 
/tb_video_frame_dpi/init_test.do
0,0 → 1,28
# ------------------------------------
#
# ------------------------------------
 
global env
 
# setup environment
do ../../../../scripts/sim_env.do
set env(SIM_TARGET) fpga
 
radix -hexadecimal
quietly set env(PATH) "D:/Anaconda2;$::env(PATH)"
 
make_lib work 1
 
sim_compile_lib $env(LIB_BASE_DIR) tb_packages
sim_compile_lib $env(LIB_BASE_DIR) bfm_packages
# sim_compile_lib $env(LIB_BASE_DIR) axi4_lib
# sim_compile_lib $env(LIB_BASE_DIR) qaz_lib
# sim_compile_lib $env(LIB_BASE_DIR) sim
 
# compile simulation files
vlog -f ./tb_files.f
 
# run the sim
sim_run_test
 
 
/tb_video_frame_dpi/py_dpi.c
0,0 → 1,142
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
#include <Python.h>
#include "vpi_user.h"
#include "py_dpi.h"
 
// --------------------------------------------------------------------
PyObject *g_dva_i;
 
// --------------------------------------------------------------------
void c_do_it()
{
printf("^^^ | c_do_it()\n");
/* result = instance.method(x,y) */
PyObject *pmeth = PyObject_GetAttrString(g_dva_i, "do_it");
// Py_DECREF(pinst);
// pargs = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
// PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
PyObject *pres = PyEval_CallObject(pmeth, NULL);
Py_DECREF(pmeth);
// Py_DECREF(pargs);
Py_DECREF(pres);
}
 
// --------------------------------------------------------------------
unsigned int *g_va = NULL;
 
void c_get_array(const svOpenArrayHandle va)
{
int va_y = svSize(va, 1);
int va_x = svSize(va, 2);
printf("^^^ | c_get_array() | %dx%d\n", va_x, va_y);
g_va = (unsigned int *)svGetArrElemPtr2(va, 0, 0);
PyObject *pmeth = PyObject_GetAttrString(g_dva_i, "py_get_array");
// pargs = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
// PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
PyObject *pres = PyEval_CallObject(pmeth, NULL);
Py_DECREF(pmeth);
// Py_DECREF(pargs);
Py_DECREF(pres);
}
 
// --------------------------------------------------------------------
int py_run_file
( const char *filename
, int argc
, const svOpenArrayHandle args
)
{
printf("^^^ | py_run_file | %s |\n", filename);
 
char *argv[4]; // limit of 4 args
int i;
for(i = 0; i < argc && i < 4; i++)
{
argv[i] = *(char **)svGetArrElemPtr1(args, i);
printf( "^^^ | py_run_file | args[%d] = %s\n"
, i
, argv[i]
);
}
 
PySys_SetArgv(argc, argv);
PyObject *PyFileObject = PyFile_FromString((char *)filename, "r");
return PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), filename, 1);
}
 
// --------------------------------------------------------------------
void init_py_dpi(int width, int height)
{
printf("^^^ | init_py_dpi() | %dx%d\n", width, height);
Py_Initialize();
init_py_to_video_frame();
PyObject *dva_m = PyImport_ImportModule("dpi_video_array");
if(!dva_m)
{
PyErr_Print();
printf("^^^ | init_py_dpi() | dva_m Error\n");
}
PyObject *dva_c = PyObject_GetAttrString(dva_m, "dpi_video_array");
Py_DECREF(dva_m);
if(!dva_c)
{
PyErr_Print();
printf("^^^ | init_py_dpi() | dva_c Error\n");
}
PyObject *args = Py_BuildValue("(ii)", width, height);
g_dva_i = PyObject_CallObject(dva_c, args);
Py_DECREF(args);
Py_DECREF(dva_c);
if(!g_dva_i)
{
PyErr_Print();
printf("^^^ | init_py_dpi() | g_dva_i Error\n");
Py_DECREF(g_dva_i);
g_dva_i = NULL;
}
}
 
// --------------------------------------------------------------------
void exit_py_dpi()
{
printf("^^^ | exit_py_dpi()\n");
if(g_dva_i)
Py_DECREF(g_dva_i);
Py_Finalize();
}
/tb_video_frame_dpi/py_dpi.h
0,0 → 1,71
/* MTI_DPI */
 
/*
* Copyright 2002-2018 Mentor Graphics Corporation.
*
* Note:
* This file is automatically generated.
* Please do not edit this file - you will lose your edits.
*
* Settings when this file was generated:
* PLATFORM = 'win64'
*/
#ifndef INCLUDED_PY_DPI
#define INCLUDED_PY_DPI
 
#ifdef __cplusplus
#define DPI_LINK_DECL extern "C"
#else
#define DPI_LINK_DECL
#endif
 
#include "svdpi.h"
 
 
#ifndef MTI_INCLUDED_TYPEDEF_frame_coordinate_t
#define MTI_INCLUDED_TYPEDEF_frame_coordinate_t
 
typedef struct {
int x;
int y;
} frame_coordinate_t;
 
#endif
 
 
DPI_LINK_DECL DPI_DLLESPEC
void
c_do_it();
 
DPI_LINK_DECL DPI_DLLESPEC
void
c_get_array(
const svOpenArrayHandle va);
 
DPI_LINK_DECL DPI_DLLESPEC
void
exit_py_dpi();
 
DPI_LINK_DECL DPI_DLLESPEC
void
init_py_dpi(
int width,
int height);
 
DPI_LINK_DECL DPI_DLLESPEC
void
init_py_to_video_frame();
 
DPI_LINK_DECL DPI_DLLESPEC
int
py_run_file(
const char* filename,
int argc,
const svOpenArrayHandle args);
 
DPI_LINK_DECL int
sv_write(
int data,
int address);
 
#endif
/tb_video_frame_dpi/py_to_video_frame_module.c
0,0 → 1,130
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
 
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>
 
extern unsigned int *g_va;
 
// --------------------------------------------------------------------
static PyObject* np_to_frame(PyObject* self, PyObject* args)
{
printf("^^^ | np_to_frame()\n");
 
if(g_va == NULL)
return NULL;
 
PyArrayObject *in_array;
NpyIter *in_iter;
NpyIter_IterNextFunc *in_iternext;
 
/* parse single numpy array argument */
if(!PyArg_ParseTuple(args, "O!", &PyArray_Type, &in_array))
return NULL;
 
/* create the iterators */
in_iter = NpyIter_New
( in_array
, NPY_ITER_READONLY
, NPY_KEEPORDER
, NPY_NO_CASTING
, NULL
);
 
if(in_iter == NULL)
return NULL;
 
in_iternext = NpyIter_GetIterNext(in_iter, NULL);
 
if(in_iternext == NULL)
{
NpyIter_Deallocate(in_iter);
return NULL;
}
unsigned int **in_dataptr = (unsigned int **)NpyIter_GetDataPtrArray(in_iter);
unsigned int *p = g_va;
 
/* iterate over the arrays */
do
{
*p++ = **in_dataptr;
} while(in_iternext(in_iter));
 
/* clean up and return the result */
NpyIter_Deallocate(in_iter);
g_va = NULL;
return Py_BuildValue("");
}
 
// --------------------------------------------------------------------
/* define functions in module */
static PyMethodDef py_to_video_frame_methods[] =
{ {"np_to_frame"
, np_to_frame
, METH_VARARGS
, "numpy to video frame"
},
{NULL, NULL, 0, NULL}
};
 
// --------------------------------------------------------------------
#if PY_MAJOR_VERSION >= 3
/* module initialization */
/* Python version 3*/
static struct PyModuleDef cmod_py_to_video_frame =
{ PyModuleDef_HEAD_INIT
, "py_to_video_frame"
, "Some documentation"
, -1
, py_to_video_frame_methods
};
 
PyMODINIT_FUNC
PyInit_py_to_video_frame(void)
{
PyObject *module = PyModule_Create(&cmod_py_to_video_frame);
 
if(module != NULL)
import_array();
 
return module;
}
 
#else
 
/* module initialization */
/* Python version 2 */
PyMODINIT_FUNC
init_py_to_video_frame(void)
{
printf("^^^ | init_py_to_video_frame()\n");
(void) Py_InitModule("py_to_video_frame", py_to_video_frame_methods);
import_array();
}
 
#endif
/tb_video_frame_dpi/py_video.py
0,0 → 1,31
#
 
import numpy as np
import matplotlib.pyplot as plt
 
fname = 'count.raw'
v_frames = 1
v_width = 8
v_height = 16
 
data = np.arange(v_frames*v_width*v_height, dtype='uint16')
 
with open(fname, 'w+') as infile:
data.tofile(infile, format='uint16')
 
infile.close()
 
# ---------------------------------------------------------
with open(fname, 'r') as infile:
data = np.fromfile(infile, dtype='uint16').reshape(v_frames, v_height, v_width)
 
np.set_printoptions(formatter={'int':hex})
 
for i in range(v_frames):
fig, ax = plt.subplots()
im = ax.imshow(data[i], cmap='gray')
ax.set(xticks=[], yticks=[])
fig.colorbar(im)
plt.show()
 
print(data[0])
/tb_video_frame_dpi/sim.do
0,0 → 1,11
#
#
 
quit -sim
 
# vsim -suppress 12110 -novopt work.tb_top
vsim -f ./sim.f work.tb_top
 
# # log all signals
# log /* -r
 
/tb_video_frame_dpi/sim.f
0,0 → 1,11
#
#
 
# -voptargs="-f ./acc_file.f"
 
# -suppress 12110
# -novopt
 
-ldflags "D:/Anaconda2/python27.dll"
# -ldflags "D:/Anaconda2/Lib/site-packages/numpy/core/lib/npymath.lib"
 
/tb_video_frame_dpi/sv_video_frame_dpi.svh
0,0 → 1,91
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
 
// --------------------------------------------------------------------
class video_frame_dpi;
mailbox #(video_array_t) array_buffer;
mailbox #(video_frame_class) buffer_in, buffer_out;
 
// --------------------------------------------------------------------
function void py_file(string filename, string py_args[]);
int return_status;
return_status = py_run_file(filename, py_args.size(), py_args);
endfunction : py_file
// --------------------------------------------------------------------
task do_it();
$display("^^^ %16.t | %m |", $time);
c_do_it();
endtask
 
// --------------------------------------------------------------------
task get_frame(ref video_array_t va);
$display("^^^ %16.t | %m |", $time);
array_buffer.get(va);
c_get_array(va);
$display("^^^ %16.t | %m | %p |", $time, va);
endtask
 
// --------------------------------------------------------------------
function new;
$display("^^^ | video_frame_dpi | new");
endfunction
 
// --------------------------------------------------------------------
function void init(int width, int height, buffer_in_size=2, buffer_out_size=2);
video_array_t a_h;
$display("^^^ | video_frame_dpi | init");
this.array_buffer = new(buffer_in_size);
this.buffer_in = new(buffer_in_size);
this.buffer_out = new(buffer_out_size);
for(int i = 0; i < buffer_in_size; i++)
begin
a_h = new[height];
foreach(a_h[y])
a_h[y] = new[width];
if(array_buffer.try_put(a_h) == 0)
begin
$display("^^^ | video_frame_dpi | init ERROR!");
$stop;
end
end
init_py_dpi(width, height);
endfunction
 
// --------------------------------------------------------------------
function void exit;
$display("^^^ | video_frame_dpi | exit");
exit_py_dpi();
endfunction
 
// --------------------------------------------------------------------
endclass : video_frame_dpi
/tb_video_frame_dpi/tb_files.f
0,0 → 1,16
#
 
# ${PROJECT_DIR}/sim/src//.sv
 
-ccflags "-Bsymbolic -ID:/Anaconda2/include -D MS_WIN64"
-ccflags "-ID:/Anaconda2/Lib/site-packages/numpy/core/include"
 
-ccflags "-std=c99"
-dpiheader py_dpi.h
 
#
./video_frame_dpi.sv
./tb_video_frame_dpi.sv
./py_dpi.c
./py_to_video_frame_module.c
 
/tb_video_frame_dpi/tb_video_frame_dpi.sv
0,0 → 1,39
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
 
module tb_top;
 
// --------------------------------------------------------------------
localparam WIDTH = 8;
localparam HEIGHT = 16;
 
// --------------------------------------------------------------------
video_frame_dpi #(.WIDTH(WIDTH), .HEIGHT(HEIGHT))
dut();
 
// --------------------------------------------------------------------
endmodule
/tb_video_frame_dpi/try_it.py
0,0 → 1,35
#
# ////////////////////////////////////////////////////////////////////
# // Copyright (C) 2018 Authors and OPENCORES.ORG ////
# // ////
# // This source file may be used and distributed without ////
# // restriction provided that this copyright statement is not ////
# // removed from the file and that any derivative work contains ////
# // the original copyright notice and the associated disclaimer. ////
# // ////
# // This source file is free software; you can redistribute it ////
# // and/or modify it under the terms of the GNU Lesser General ////
# // Public License as published by the Free Software Foundation; ////
# // either version 2.1 of the License, or (at your option) any ////
# // later version. ////
# // ////
# // This source is distributed in the hope that it will be ////
# // useful, but WITHOUT ANY WARRANTY; without even the implied ////
# // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
# // PURPOSE. See the GNU Lesser General Public License for more ////
# // details. ////
# // ////
# // You should have received a copy of the GNU Lesser General ////
# // Public License along with this source; if not, download it ////
# // from http://www.opencores.org/lgpl.shtml ////
# ////////////////////////////////////////////////////////////////////
import sys
# import py_to_video_frame as vf
import numpy as np
 
print("^^^ | running python!")
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
 
 
print("~~~ | try_it | DONE!")
/tb_video_frame_dpi/video_frame_dpi.sv
0,0 → 1,73
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
 
`timescale 1 ns/1 ns
module
video_frame_dpi
#( WIDTH = 8
, HEIGHT = 16
);
import bfm_pkg::*;
import video_frame_pkg::*;
 
// --------------------------------------------------------------------
import "DPI-C" context function void init_py_dpi(int width, int height);
import "DPI-C" context function void exit_py_dpi();
import "DPI-C" context function void c_do_it();
import "DPI-C" context function void c_get_array(inout video_array_t va);
import "DPI-C" context function int py_run_file(string filename, int argc, string args[]);
import "DPI-C" context function void init_py_to_video_frame();
export "DPI-C" task sv_write;
 
// --------------------------------------------------------------------
`include "./sv_video_frame_dpi.svh"
 
// --------------------------------------------------------------------
// Exported SV task. Can be called by C, SV or Python
task sv_write(input int data, address);
$display("sv_write(data = %d, address = %d)",data,address);
endtask
 
// --------------------------------------------------------------------
video_frame_dpi vf_h;
video_array_t va;
 
initial
begin
vf_h = new();
vf_h.init(WIDTH, HEIGHT);
 
vf_h.get_frame(va);
// vf_h.do_it();
 
vf_h.exit();
 
$display("DONE!!");
end
 
// --------------------------------------------------------------------
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.