Skip to content

Commit b685fa6

Browse files
committed
STYLE: Changing dim_type to dim_t
Changing dim_t to size_t - Also changed af_array to be void * - Changed a bunch of files that were assuming dim_t to be int All the kernels now use int instead of dim_t internally This is done to improve performance. In the future, the kernels will need to be templated for index type based on number of elements
1 parent a4d5a3e commit b685fa6

File tree

344 files changed

+3483
-3471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

344 files changed

+3483
-3471
lines changed

examples/common/idxio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ unsigned reverse(unsigned x)
4242
}
4343

4444
template<class ty>
45-
void read_idx(std::vector<dim_type> &dims, std::vector<ty> &data, const char *name)
45+
void read_idx(std::vector<dim_t> &dims, std::vector<ty> &data, const char *name)
4646
{
4747
std::ifstream f(name, std::ios::in | std::ios::binary);
4848
if (!f.is_open()) throw std::runtime_error("Unable to open file");
@@ -59,7 +59,7 @@ void read_idx(std::vector<dim_type> &dims, std::vector<ty> &data, const char *na
5959

6060
// Read the dimensions
6161
size_t elem = 1;
62-
dims = std::vector<dim_type>(numdims);
62+
dims = std::vector<dim_t>(numdims);
6363
for (unsigned i = 0; i < numdims; i++) {
6464
f.read(d.bytes, sizeof(d.bytes));
6565

@@ -68,7 +68,7 @@ void read_idx(std::vector<dim_type> &dims, std::vector<ty> &data, const char *na
6868
unsigned dim = reverse(d.dim);
6969

7070
elem *= dim;
71-
dims[i] = (dim_type)dim;
71+
dims[i] = (dim_t)dim;
7272
}
7373

7474
// Read the data

examples/financial/black_scholes_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
9393
Tg = tile(GC5, n, 1);
9494

9595
dim4 dims = Xg.dims();
96-
printf("Input Data Size = %d x %d\n", dims[0], dims[1]);
96+
printf("Input Data Size = %lu x %lu\n", dims[0], dims[1]);
9797

9898
// Force compute on the GPU
9999
af::sync();

examples/getting_started/vectorize.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ array A, B;
1717

1818
static array dist_naive(array a, array b)
1919
{
20-
array dist_mat = constant(0, a.dims(1), b.dims(1));
20+
array dist_mat = constant(0, a.dims(1), (int)b.dims(1));
2121

2222
// Iterate through columns a
23-
for (int ii = 0; ii < a.dims(1); ii++) {
23+
for (int ii = 0; ii < (int)a.dims(1); ii++) {
2424

2525
// Iterate through columns of b
26-
for (int jj = 0; jj < b.dims(1); jj++) {
26+
for (int jj = 0; jj < (int)b.dims(1); jj++) {
2727

2828
// Get the sum of absolute differences
29-
for (int kk = 0; kk < a.dims(0); kk++) {
29+
for (int kk = 0; kk < (int)a.dims(0); kk++) {
3030
dist_mat(ii, jj) += abs(a(kk, ii) - b(kk, jj));
3131
}
3232
}
@@ -37,14 +37,14 @@ static array dist_naive(array a, array b)
3737

3838
static array dist_vec(array a, array b)
3939
{
40-
array dist_mat = constant(0, a.dims(1), b.dims(1));
40+
array dist_mat = constant(0, (int)a.dims(1), (int)b.dims(1));
4141

4242
// Iterate through columns a
43-
for (int ii = 0; ii < a.dims(1); ii++) {
43+
for (int ii = 0; ii < (int)a.dims(1); ii++) {
4444
array avec = a(span, ii);
4545

4646
// Iterate through columns of b
47-
for (int jj = 0; jj < b.dims(1); jj++) {
47+
for (int jj = 0; jj < (int)b.dims(1); jj++) {
4848
array bvec = b(span, jj);
4949

5050
// get SAD using sum on the vector
@@ -57,14 +57,14 @@ static array dist_vec(array a, array b)
5757

5858
static array dist_gfor1(array a, array b)
5959
{
60-
array dist_mat = constant(0, a.dims(1), b.dims(1));
60+
array dist_mat = constant(0, (int)a.dims(1), (int)b.dims(1));
6161

6262
// GFOR along columns of a
63-
gfor (seq ii, a.dims(1)) {
63+
gfor (seq ii, (int)a.dims(1)) {
6464
array avec = a(span, ii);
6565

6666
// Itere through columns of b
67-
for (int jj = 0; jj < b.dims(1); jj++) {
67+
for (int jj = 0; jj < (int)b.dims(1); jj++) {
6868
array bvec = b(span, jj);
6969

7070
// get SAD using sum on the vector
@@ -77,14 +77,14 @@ static array dist_gfor1(array a, array b)
7777

7878
static array dist_gfor2(array a, array b)
7979
{
80-
array dist_mat = constant(0, a.dims(1), b.dims(1));
80+
array dist_mat = constant(0, (int)a.dims(1), (int)b.dims(1));
8181

8282
// GFOR along columns of b
83-
gfor (seq jj, b.dims(1)) {
83+
gfor (seq jj, (int)b.dims(1)) {
8484
array bvec = b(span, jj);
8585

8686
// Iterate through columns of A
87-
for (int ii = 0; ii < a.dims(1); ii++) {
87+
for (int ii = 0; ii < (int)a.dims(1); ii++) {
8888
array avec = a(span, ii);
8989

9090
// get SAD using sum on the vector
@@ -97,9 +97,9 @@ static array dist_gfor2(array a, array b)
9797

9898
static array dist_tile1(array a, array b)
9999
{
100-
// int feat_len = a.dims(0); // Same as b.dims(0);
101-
int alen = a.dims(1);
102-
int blen = b.dims(1);
100+
// int feat_len = (int)a.dims(0); // Same as (int)b.dims(0);
101+
int alen = (int)a.dims(1);
102+
int blen = (int)b.dims(1);
103103

104104
array dist_mat = constant(0, alen, blen);
105105

@@ -127,9 +127,9 @@ static array dist_tile1(array a, array b)
127127

128128
static array dist_tile2(array a, array b)
129129
{
130-
int feat_len = a.dims(0);
131-
int alen = a.dims(1);
132-
int blen = b.dims(1);
130+
int feat_len = (int)a.dims(0);
131+
int alen = (int)a.dims(1);
132+
int blen = (int)b.dims(1);
133133

134134
// Shape of a is (feat_len, alen, 1)
135135
array a_mod = a;

examples/machine_learning/mnist_common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ std::string classify(af::array arr, int k)
2929
float *h_vec = vec.host<float>();
3030
std::vector<sort_type> data;
3131

32-
for (int i = 0; i < vec.elements(); i++)
32+
for (int i = 0; i < (int)vec.elements(); i++)
3333
data.push_back(std::make_pair(h_vec[i], i));
3434

3535
std::stable_sort(data.begin(), data.end(), compare);
@@ -46,11 +46,11 @@ static void setup_mnist(int *num_classes, int *num_train, int *num_test,
4646
af::array &train_images, af::array &test_images,
4747
af::array &train_labels, af::array &test_labels, float frac)
4848
{
49-
std::vector<dim_type> idims;
49+
std::vector<dim_t> idims;
5050
std::vector<float > idata;
5151
read_idx(idims, idata, ASSETS_DIR"/examples/data/mnist/images-subset");
5252

53-
std::vector<dim_type> ldims;
53+
std::vector<dim_t> ldims;
5454
std::vector<unsigned> ldata;
5555
read_idx(ldims, ldata, ASSETS_DIR"/examples/data/mnist/labels-subset");
5656

include/af/array.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ namespace af
8181
// af::array member functions. same behavior as those below
8282
af_array get();
8383
af_array get() const;
84-
dim_type elements() const;
84+
dim_t elements() const;
8585
template<typename T> T* host() const;
8686
void host(void *ptr) const;
8787
dtype type() const;
8888
dim4 dims() const;
89-
dim_type dims(unsigned dim) const;
89+
dim_t dims(unsigned dim) const;
9090
unsigned numdims() const;
9191
size_t bytes() const;
9292
array copy() const;
@@ -162,7 +162,7 @@ namespace af
162162
163163
*/
164164
explicit
165-
array(dim_type dim0, dtype ty = f32);
165+
array(dim_t dim0, dtype ty = f32);
166166

167167
/**
168168
Allocate a two-dimensional array of a specified size with undefined contents
@@ -187,7 +187,7 @@ namespace af
187187
188188
*/
189189
explicit
190-
array(dim_type dim0, dim_type dim1, dtype ty = f32);
190+
array(dim_t dim0, dim_t dim1, dtype ty = f32);
191191

192192
/**
193193
Allocate a three-dimensional (3D) array of a specified size with undefined contents
@@ -213,7 +213,7 @@ namespace af
213213
214214
*/
215215
explicit
216-
array(dim_type dim0, dim_type dim1, dim_type dim2, dtype ty = f32);
216+
array(dim_t dim0, dim_t dim1, dim_t dim2, dtype ty = f32);
217217

218218
/**
219219
Allocate a four-dimensional (4D) array of a specified size with undefined contents
@@ -239,7 +239,7 @@ namespace af
239239
240240
*/
241241
explicit
242-
array(dim_type dim0, dim_type dim1, dim_type dim2, dim_type dim3, dtype ty = f32);
242+
array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, dtype ty = f32);
243243

244244
/**
245245
Allocate an array of a specified size with undefined contents
@@ -301,8 +301,8 @@ namespace af
301301
*/
302302
template<typename T>
303303
explicit
304-
array(dim_type dim0,
305-
const T *pointer, af_source_t src=afHost, dim_type ngfor=0);
304+
array(dim_t dim0,
305+
const T *pointer, af_source_t src=afHost, dim_t ngfor=0);
306306

307307

308308
/**
@@ -331,8 +331,8 @@ namespace af
331331
*/
332332
template<typename T>
333333
explicit
334-
array(dim_type dim0, dim_type dim1,
335-
const T *pointer, af_source_t src=afHost, dim_type ngfor=0);
334+
array(dim_t dim0, dim_t dim1,
335+
const T *pointer, af_source_t src=afHost, dim_t ngfor=0);
336336

337337

338338
/**
@@ -360,8 +360,8 @@ namespace af
360360
*/
361361
template<typename T>
362362
explicit
363-
array(dim_type dim0, dim_type dim1, dim_type dim2,
364-
const T *pointer, af_source_t src=afHost, dim_type ngfor=0);
363+
array(dim_t dim0, dim_t dim1, dim_t dim2,
364+
const T *pointer, af_source_t src=afHost, dim_t ngfor=0);
365365

366366

367367
/**
@@ -390,8 +390,8 @@ namespace af
390390
*/
391391
template<typename T>
392392
explicit
393-
array(dim_type dim0, dim_type dim1, dim_type dim2, dim_type dim3,
394-
const T *pointer, af_source_t src=afHost, dim_type ngfor=0);
393+
array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3,
394+
const T *pointer, af_source_t src=afHost, dim_t ngfor=0);
395395

396396
/**
397397
Create an array of specified size on the device using a host/device pointer
@@ -425,7 +425,7 @@ namespace af
425425
template<typename T>
426426
explicit
427427
array(const dim4& dims,
428-
const T *pointer, af_source_t src=afHost, dim_type ngfor=0);
428+
const T *pointer, af_source_t src=afHost, dim_t ngfor=0);
429429

430430
/**
431431
@}
@@ -449,7 +449,7 @@ namespace af
449449
/**
450450
get the number of elements in array
451451
*/
452-
dim_type elements() const;
452+
dim_t elements() const;
453453

454454
/**
455455
Copy array data to host and return host pointer
@@ -479,7 +479,7 @@ namespace af
479479
/**
480480
Get dimensions of the array
481481
*/
482-
dim_type dims(unsigned dim) const;
482+
dim_t dims(unsigned dim) const;
483483

484484
/**
485485
Get the number of dimensions of the array
@@ -952,7 +952,7 @@ extern "C" {
952952
953953
\returns \ref AF_SUCCESS if the operation was a success
954954
*/
955-
AFAPI af_err af_create_array(af_array *arr, const void * const data, const unsigned ndims, const dim_type * const dims, const af_dtype type);
955+
AFAPI af_err af_create_array(af_array *arr, const void * const data, const unsigned ndims, const dim_t * const dims, const af_dtype type);
956956

957957
/**
958958
Create af_array handle
@@ -964,7 +964,7 @@ extern "C" {
964964
965965
\returns \ref AF_SUCCESS if the operation was a success
966966
*/
967-
AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_type * const dims, const af_dtype type);
967+
AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t * const dims, const af_dtype type);
968968

969969
/**
970970
@}

0 commit comments

Comments
 (0)