GCC Code Coverage Report
Directory: . Exec Total Coverage
File: frame/base/device.cpp Lines: 7 45 15.6 %
Date: 2019-01-14 Branches: 4 12 33.3 %

Line Exec Source
1
/**
2
 *  HMLP (High-Performance Machine Learning Primitives)
3
 *
4
 *  Copyright (C) 2014-2017, The University of Texas at Austin
5
 *
6
 *  This program is free software: you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation, either version 3 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program. If not, see the LICENSE file.
18
 *
19
 **/
20
21
22
#include <base/device.hpp>
23
#include <base/runtime.hpp>
24
25
using namespace std;
26
27
namespace hmlp
28
{
29
30
16
CacheLine::CacheLine() {};
31
32
void CacheLine::Setup( hmlp::Device *device, size_t line_size )
33
{
34
  this->status = CACHE_CLEAN;
35
  this->line_size = line_size;
36
  this->ptr_d = (char*)device->malloc( line_size );
37
};
38
39
bool CacheLine::isClean()
40
{
41
  return ( status == CACHE_CLEAN );
42
};
43
44
void CacheLine::Bind( void *ptr_h )
45
{
46
  this->ptr_h = ptr_h;
47
};
48
49
50
bool CacheLine::isCache( void *ptr_h, size_t size )
51
{
52
  if ( size > line_size )
53
  {
54
    printf( "Cache line %lu request %lu\n", line_size, size );
55
    return false;
56
  }
57
  else
58
  {
59
    return (this->ptr_h == ptr_h);
60
  }
61
};
62
63
char *CacheLine::device_data()
64
{
65
  return ptr_d;
66
};
67
68
69
70
1
Cache::Cache() {};
71
72
void Cache::Setup( hmlp::Device *device )
73
{
74
  for ( int line_id = 0; line_id < MAX_LINE; line_id ++ )
75
  {
76
    line[ line_id ].Setup( device, 2048 * 2048 * 8 );
77
  }
78
};
79
80
CacheLine *Cache::Read( size_t size )
81
{
82
  int line_id = fifo;
83
  fifo = ( fifo + 1 ) % MAX_LINE;
84
  if ( !line[ line_id ].isClean() )
85
  {
86
    printf( "The cache line is not clean\n" );
87
    exit( 1 );
88
  }
89
  else
90
  {
91
    //printf( "line_id %d\n", line_id );
92
  }
93
  return &(line[ line_id ]);
94
};
95
96
97
98
99
100
101
/**
102
 *  @brief Device implementation
103
 */
104
2
Device::Device()
105
{
106
2
  name = std::string( "Host CPU" );
107
1
  devicetype = hmlp::DeviceType::HOST;
108
1
};
109
110
111
CacheLine *Device::getline( size_t size )
112
{
113
  return cache.Read( size );
114
};
115
116
void Device::prefetchd2h( void *ptr_h, void *ptr_d, size_t size, int stream_id ) {};
117
118
void Device::prefetchh2d( void *ptr_d, void *ptr_h, size_t size, int stream_id ) {};
119
120
void Device::waitexecute() {};
121
122
void Device::wait( int stream_id ) {};
123
124
void *Device::malloc( size_t size ) { return NULL; };
125
126
void Device::malloc( void *ptr_d, size_t size ) {};
127
128
size_t Device::get_memory_left() { return 0; };
129
130
void Device::free( void *ptr_d, size_t size ) {};
131
132
133
2
}; // end namespace hmlp